delphi - Inserting text into new Word 2010 file not working (Delhi XE2) -


i've written test program in deplhi xe2 create new word document (using wort 2010 , twordapplication), insert text it, , save both .doc file , .pdf file. 2 word components on form. works except text insertion. when open documents after fact both created empty.

it's frustrating work without docs regarding using vba equivalents word. if can point me twordapplication , tworddocument specs eternally grateful. but, immediate problem how insert text.

here's have:

procedure tform1.btngenerateclick(sender: tobject); var   snewtext: widestring; begin   snewtext := 'hello, world!' + #13;   { create word document, set text , close it. }   wordapplication1.visible := false;    wordapplication1.newdocument;   wordapplication1.selection.endof(wdstory, wdmove);   wordapplication1.selection.insertafter(snewtext);   wordapplication1.selection.endof(wdstory, wdmove);    if fileexists('d:\temp\mynewdocdup.doc')   deletefile('d:\temp\mynewdocdup.doc')   else ;   worddocument1.saveas('d:\temp\mynewdocdup.doc');    if fileexists('d:\temp\mynewdocdup.pdf')   deletefile('d:\temp\mynewdocdup.pdf')   else ;   worddocument1.saveas('d:\temp\mynewdocdup.pdf', 17);    worddocument1.close;   wordapplication1.disconnect; end; 

jerry

it seems me problem document object worddocument1 not document in text added. text added fine, different document. here simple example demonstrates how it:

var   app: twordapplication;   doc: worddocument; .... app := twordapplication.create(nil); try   app.visible := false;   doc := app.documents.add(emptyparam, emptyparam, emptyparam, emptyparam);   app.selection.endof(wdstory, wdmove);   app.selection.insertafter('hello, world!');   app.selection.endof(wdstory, wdmove);   doc.saveas('c:\desktop\mynewdocdup.doc', emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam);   doc.saveas('c:\desktop\mynewdocdup.pdf', 17, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam, emptyparam);   doc.close(emptyparam, emptyparam, emptyparam);   app.quit;   app.free; end; 

in real code you'd use named file format constants rather magic number 17.

note newdocument not create new document. instead need use documents.add make new document. note pain of binding – emptyparam arguments no fun @ all. if building large amount of code on top of office pays wrap such messy details.

as documentation office automation api, can found on msdn: http://msdn.microsoft.com/en-us/library/office/ee861527.aspx


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -