L
lyjgs.168
Unregistered / Unconfirmed
GUEST, unregistred user!
我的需求是这样的:
根据DATASET中的记录数据来确定在WORD中指定书签的位置上插入表格,要求一页插入一个表格,一个表格有四个格子上面两个放图片下面两个定入相应的备注;
问题:
现在插入一个表格且在表中放入图片和备注都可以,但在插入一个表格后再想插入分页符再在分页符后插入表格,现在我的问题是当插入一个表格后怎么把插入点移动到表格下面,可以插入分面符和表格;
源代码:
var
FileName1, ReadOnly: OleVariant;
WordApp: TWordApplication;
WordDoc: TWordDocument;
JRange: Range;
FileBitMap: TBitMap;
v_Image: TImage;
ImageCount,I: Integer;
begin
FileName1 := 'd:/1.doc';
WordApp := TWordApplication.Create(self);
WordDoc := TWordDocument.Create(self);
try
WordApp.ConnectKind := ckNewInstance;
WordApp.Connect;
except
Result := 'Word未安装或已损坏!';
exit;
end;
try
if WordApp.Version = '8.0' then //Word97
WordApp.Documents.OpenOld(FileName1, EmptyParam, ReadOnly, EmptyParam,
EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam)
else //Word2000(Ver=9.0)
WordApp.Documents.Open(FileName1, EmptyParam, EmptyParam, EmptyParam,
EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, emptyparam,
emptyparam);
except
Result := '错误';
try
WordApp.Quit;
WordApp.Disconnect;
except
end;
exit;
end;
Worddoc.ConnectTo(WordApp.ActiveDocument);
v_Image := TImage.Create(nil);
FileBitMap := TBitMap.Create;
try
if WordDoc.Bookmarks.Exists('书签名') then //if bookmark exist
begin
JRange := WordDoc.Bookmarks.Item(FJFJG_BookMark).Get_Range;
ImageCount := (DataSet.RecordCount div 2) + 1;
For I := 0 To ImageCount - 1 Do
Begin//在这里怎么处理????????????
WordDoc.Tables.Add(JRange, 2, 2, EmptyParam, EmptyParam);
End;
End;
if FileExists('D:/test/word/R2000-09174.JPG') then
begin
v_Image.Picture.LoadFromFile('D:/test/word/R2000-09174.JPG');
FileBitMap.Height := v_Image.Picture.Height;
FileBitMap.Width := v_Image.Picture.Width;
FileBitMap.canvas.StretchDraw( FileBitMap.canvas.Cliprect,v_Image.Picture.Graphic);//缩放适应
FileBitMap.SaveToClipBoardFormat(MyFormat, AData, APalette);
ClipBoard.SetAsHandle(MyFormat, AData);
end;
For I := 1 To WordDoc.Tables Do
Begin
WordDoc.Tables.Item(I).Cell(1, 1).Range.Paste;
WordDoc.Tables.Item(I).Cell(1, 2).Range.Paste;//贴图
End;
Finally
End;
根据DATASET中的记录数据来确定在WORD中指定书签的位置上插入表格,要求一页插入一个表格,一个表格有四个格子上面两个放图片下面两个定入相应的备注;
问题:
现在插入一个表格且在表中放入图片和备注都可以,但在插入一个表格后再想插入分页符再在分页符后插入表格,现在我的问题是当插入一个表格后怎么把插入点移动到表格下面,可以插入分面符和表格;
源代码:
var
FileName1, ReadOnly: OleVariant;
WordApp: TWordApplication;
WordDoc: TWordDocument;
JRange: Range;
FileBitMap: TBitMap;
v_Image: TImage;
ImageCount,I: Integer;
begin
FileName1 := 'd:/1.doc';
WordApp := TWordApplication.Create(self);
WordDoc := TWordDocument.Create(self);
try
WordApp.ConnectKind := ckNewInstance;
WordApp.Connect;
except
Result := 'Word未安装或已损坏!';
exit;
end;
try
if WordApp.Version = '8.0' then //Word97
WordApp.Documents.OpenOld(FileName1, EmptyParam, ReadOnly, EmptyParam,
EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam)
else //Word2000(Ver=9.0)
WordApp.Documents.Open(FileName1, EmptyParam, EmptyParam, EmptyParam,
EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, emptyparam,
emptyparam);
except
Result := '错误';
try
WordApp.Quit;
WordApp.Disconnect;
except
end;
exit;
end;
Worddoc.ConnectTo(WordApp.ActiveDocument);
v_Image := TImage.Create(nil);
FileBitMap := TBitMap.Create;
try
if WordDoc.Bookmarks.Exists('书签名') then //if bookmark exist
begin
JRange := WordDoc.Bookmarks.Item(FJFJG_BookMark).Get_Range;
ImageCount := (DataSet.RecordCount div 2) + 1;
For I := 0 To ImageCount - 1 Do
Begin//在这里怎么处理????????????
WordDoc.Tables.Add(JRange, 2, 2, EmptyParam, EmptyParam);
End;
End;
if FileExists('D:/test/word/R2000-09174.JPG') then
begin
v_Image.Picture.LoadFromFile('D:/test/word/R2000-09174.JPG');
FileBitMap.Height := v_Image.Picture.Height;
FileBitMap.Width := v_Image.Picture.Width;
FileBitMap.canvas.StretchDraw( FileBitMap.canvas.Cliprect,v_Image.Picture.Graphic);//缩放适应
FileBitMap.SaveToClipBoardFormat(MyFormat, AData, APalette);
ClipBoard.SetAsHandle(MyFormat, AData);
end;
For I := 1 To WordDoc.Tables Do
Begin
WordDoc.Tables.Item(I).Cell(1, 1).Range.Paste;
WordDoc.Tables.Item(I).Cell(1, 2).Range.Paste;//贴图
End;
Finally
End;