marioway
asked on
How to make a new document in WORD and import the FORMATTED TEXT into a DBRichtEdit
Hi
How do I make a new document in WORD from within a Delphi application and insert the formatted text into a DBRichtEdit.
thx
Marioway
How do I make a new document in WORD from within a Delphi application and insert the formatted text into a DBRichtEdit.
thx
Marioway
ASKER
Hi,
I'm making an invoice program, and on the invoices, sometimes a lot of text has to be added. I'm using a formatted memofield for this purpose. So I would like to call Word from within that application an insert the text from the worddoc after closing down Word.
Marioway
I'm making an invoice program, and on the invoices, sometimes a lot of text has to be added. I'm using a formatted memofield for this purpose. So I would like to call Word from within that application an insert the text from the worddoc after closing down Word.
Marioway
Hi,
One way is to copy the word document in the clipboard and paste it to the RichEdit. I don't like this way.
Another way is to save the word document somewhere as an .RTF file and load it to the RichEdit using:
RichEdit1.Lines.LoadFromFi le('c:\tem p\foo.rtf' );
Regards, Geo
One way is to copy the word document in the clipboard and paste it to the RichEdit. I don't like this way.
Another way is to save the word document somewhere as an .RTF file and load it to the RichEdit using:
RichEdit1.Lines.LoadFromFi
Regards, Geo
And delete the file after loading: DeleteFile('c:\temp\foo.rt f');
ASKER
Hi,
When i use the code above, Word creates a new doc, saves and exits. Could you give me the code for this
- open Word and append a document which one can edit;
- save that doc as an RTF-file in a specified directory
- after closing word loading the file into the (DB)RichEdit;
- delete the file at the end
I would be very greatfull
marioway
When i use the code above, Word creates a new doc, saves and exits. Could you give me the code for this
- open Word and append a document which one can edit;
- save that doc as an RTF-file in a specified directory
- after closing word loading the file into the (DB)RichEdit;
- delete the file at the end
I would be very greatfull
marioway
Hi,
>- open Word and append a document which one can edit;
I can't understand that. Sorry. Would you explain it more, please?
>- save that doc as an RTF-file in a specified directory
>- after closing word loading the file into the (DB)RichEdit;
>- delete the file at the end
Sure. Here it is:
...
WordDoc.SaveAs('c:\temp\fo o.rtf', 6); \\ 6 means wdFormatRTF constant as a second parameter in WordDocument.SaveAs method
WordDoc.Close; // closes the current document
WordApp.Quit; // exits MS Word
RichEdit1.Lines.LoadFromFi le('c:\tem p\foo.rtf' );
DeleteFile('c:\temp\foo.rt f');
end;
Regards, Geo
>- open Word and append a document which one can edit;
I can't understand that. Sorry. Would you explain it more, please?
>- save that doc as an RTF-file in a specified directory
>- after closing word loading the file into the (DB)RichEdit;
>- delete the file at the end
Sure. Here it is:
...
WordDoc.SaveAs('c:\temp\fo
WordDoc.Close; // closes the current document
WordApp.Quit; // exits MS Word
RichEdit1.Lines.LoadFromFi
DeleteFile('c:\temp\foo.rt
end;
Regards, Geo
ASKER
Hi,
Well, when I use the code you sent me first (on top), Word opens, creates a new doc, with the text 'Welcom To Delphi World', prints it out and closes Word, without giving me the opportunity to change the text first.
Marioway
Well, when I use the code you sent me first (on top), Word opens, creates a new doc, with the text 'Welcom To Delphi World', prints it out and closes Word, without giving me the opportunity to change the text first.
Marioway
ASKER
Hello, I'm leaving now for 1 week on vacation. I'll be back the 8th of november.
See you then
marioway
See you then
marioway
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Geo, I'm back in town. Tried your solution and it works fine. Thanks a lot !!!
Marioway
Marioway
>How do I make a new document in WORD from within a Delphi application
uses
ComObj;
procedure TForm1.Button1Click(Sender
var
WordApp, WordDoc: OLEVariant;
begin
WordApp := CreateOleObject('Word.Appl
WordApp.Visible := True;
WordApp.Caption:='Winword From Delphi';
// to create new doc
WordDoc:=WordApp.Documents
WordDoc.Paragraphs.Item(1)
WordDoc.Paragraphs.Item(1)
WordDoc.Paragraphs.Item(1)
WordDoc.Paragraphs.Item(1)
// save the doc
WordDoc.SaveAs('c:\mydoc.d
// print the doc
WordDoc.PrintOut;
WordDoc.Close; // closes the current document
WordApp.Quit; // exits MS Word
end;
>and insert the formatted text into a DBRichtEdit.
Would you explain it a little bit more, please?
Regards, Geo