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

Discussion in 'ActiveX 控件' started by zbr, Dec 21, 2010.

  1. zb

    zbr Member

    Apr 1, 2015
    有一个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文本添加上了,但是位置不对,添加在竖排的那些内容里。请问如何解决,或者哪位朋友有更好的办法。感谢你!
     
  2. zb

    zbr Member

    Apr 1, 2015
    我的QQ是59351851 ,谢谢! 比较急。
     
  3. zb

    zbr Member

    Apr 1, 2015
    或者哪位朋友告诉我在Word里如何定位???
     
  4. sz

    szhcracker Member

    Apr 1, 2015
  5. zb

    zbdzjx Member

    Apr 1, 2015
    我也來接分了!!!!
     
  6. zb

    zbr Member

    Apr 1, 2015
    多人接受答案了。