3

I'm building a Delphi app and I want to read a Word document and display it in a rich edit. How can I do that?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Andrei
  • 61
  • 2
  • 3
  • 2
    Very big ask. In general you won't achieve this. You could save as RTF but the fidelity will be poor. – David Heffernan Oct 12 '11 at 18:18
  • 5
    Or intead of use a RichEdit put an `TOleContainer` component in your form and then use the `CreateObjectFromFile` method in this way `OleContainer1.CreateObjectFromFile('your doc file path goes here',false);` – RRUZ Oct 12 '11 at 18:36
  • AFAIK, Word provides an ActiveX control for Outlook. – Premature Optimization Oct 12 '11 at 19:50
  • 3
    Asking for emails is not how we do it here. – David Heffernan Oct 12 '11 at 22:55
  • ok i managed to import the .doc using a ole container. but now i get error 87: parameter incorrect every time i try tu use it's functionality. that's odd because i didn't modify anything except from adding that ole container and a file-open menu – Andrei Oct 13 '11 at 14:04

2 Answers2

1
function OpenWordFile(const FName: string): string;
var wordText: string;
begin
  openWord := CreateOleObject('Word.Application');
  openWord.Visible := False;
  openWord.Documents.Open(FName);
  openWord.ActiveDocument.Select;
  wordText:= openWord.Selection.Text;
  openWord.ActiveDocument.Close;
  openWord.Quit;
  openWord := unassigned;
  /////
  Result:= wordText;
end;
Srdjan Vukmirica
  • 743
  • 2
  • 8
  • 22
  • This does not *display a Word document in a RichEdit*. It opens a Word document and copies plain text to the clipboard (which is absolutely inappropriate behavior - the clipboard is the property of the user, not an application). – Ken White Feb 25 '15 at 23:11
0

If you are considering a 3rd party control that can accomplish this, RichView allows you to import word documents.

http://www.trichview.com/

I believe it uses word itself to do the importing, so your target machines will have to have it installed to be able to import.

A Lombardo
  • 774
  • 5
  • 25