Delphi调用Word模板(问题已解决,进来的前6位朋友每人50分)(300)

zbr

New Member
Member
#1
有一个A3.Doc 的Word模板,里面的内容是左侧是什么考号,装订线等,是竖排的,就是考试试卷的左侧那些内容。现在想通过此模板,调用往Word里添加文本。代码如下:procedure TForm1.Button4Click(Sender: TObject);var NewTemplate,OldTemplate: OleVariant;
ItemIndex:OleVariant;
FindText,MatchCase,MatchWholeWord,MatchWildcards,MatchSoundsLike, MatchAllWordForms,Forward,Wrap,Format,ReplaceWith,Replace:OleVariant;begin
oldTemplate:=False;
newTemplate:='d:/A3.doc';
try wordApplication.Connect;
except showmessage('error');
abort;
end;

wordApplication.Documents.AddOld(newTemplate,oldTemplate);
//最大化word窗体 wordApplication.WindowState:=1;
wordApplication.Visible:=true;
wordApplication.Activate;
ItemIndex:=1;
wordDocument.ConnectTo(wordApplication.Documents.Item(ItemIndex));
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
//更改word活动子文档标题 wordDocument.ActiveWindow.Caption:='导出试卷';
Edit1.SelectAll;
Edit1.CopyToClipboard;
GotoDocEnd(WordApplication);
WordApplication.Selection.Paste;procedure TForm1.GotoDocEnd(WrdApp: TWordApplication);var WdUnit, WdCount, wdExtend: OleVariant;begin
WdUnit := wdScreen;
wdCount := 10;
wdExtend := EmptyParam;
while truedo
if WrdApp.Selection.MoveDown(WdUnit, wdCount, wdExtend) = 0 then
break;end;
问题是: 添加Edit文本添加上了,但是位置不对,添加在竖排的那些内容里。请问如何解决,或者哪位朋友有更好的办法。感谢你!
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)