Board index » delphi » How to format an existing text file into a Word 2000 file

How to format an existing text file into a Word 2000 file

Hi,
I am new to using MS Office 2000 with Delphi and automation.
Here is a question: how to format an existing text file into a Word 2000 file with curtain font and page margins, and save it
with 'doc'
extension? Should I use WordDocument or WordApplication component?
Can somebody show me the sample of the code or point where I can
find it?
Thank you very much.

Barry

 

Re:How to format an existing text file into a Word 2000 file


<<Byelko:
Should I use WordDocument or WordApplication component?
Can somebody show me the sample of the code or point where
I can find it?

Quote

Start here:
http://www.djpate.freeserve.co.uk/Automation.htm

If you used a TWordApplication and a TWordDocument named
Word and Doc respectively, you could do this:

var
  Filename, Format: OleVariant;
..
  Filename := 'D:\Docs\Word\Some.txt';
  Doc.ConnectTo(
    Word.Documents.Open(
       Filename, EmptyParam, EmptyParam,
       EmptyParam, EmptyParam, EmptyParam,
       EmptyParam, EmptyParam, EmptyParam,
       EmptyParam, EmptyParam, EmptyParam));
  Doc.Content.Font.Name := 'Gill Sans';
  Doc.PageSetup.LeftMargin := 80;

  Filename := ChangeFileExt(Filename, '.doc');
  Format := wdFormatDocument;
  Doc.SaveAs(Filename, Format);

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:How to format an existing text file into a Word 2000 file


Deborah,

Thank you very much for the very helpful respond.

Barry

"Deborah Pate (TeamB)" <d.p...@blueyonder.co.not-this-bit.uk> wrote:

Quote
><<Byelko:
>Should I use WordDocument or WordApplication component?
>Can somebody show me the sample of the code or point where
>I can find it?

>Start here:
>http://www.djpate.freeserve.co.uk/Automation.htm

>If you used a TWordApplication and a TWordDocument named
>Word and Doc respectively, you could do this:

>var
>  Filename, Format: OleVariant;
>...
>  Filename := 'D:\Docs\Word\Some.txt';
>  Doc.ConnectTo(
>    Word.Documents.Open(
>       Filename, EmptyParam, EmptyParam,
>       EmptyParam, EmptyParam, EmptyParam,
>       EmptyParam, EmptyParam, EmptyParam,
>       EmptyParam, EmptyParam, EmptyParam));
>  Doc.Content.Font.Name := 'Gill Sans';
>  Doc.PageSetup.LeftMargin := 80;

>  Filename := ChangeFileExt(Filename, '.doc');
>  Format := wdFormatDocument;
>  Doc.SaveAs(Filename, Format);

>--
>Deborah Pate (TeamB) http://delphi-jedi.org

>  TeamB don't see posts sent via Google or ISPs
>  Use the real Borland server: newsgroups.borland.com
>  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads