Mega Code Archive

 
Categories / Delphi / Activex OLE
 

Converting MS Word DOC to RTF using OLE

Title: Converting MS-Word DOC to RTF using OLE Question: I want to load a Word document into a RitchText control. Answer: Open a new Application and place: a button named Button3, a RitchText object named WordEditor and an OpenDialog component. From now on, you can browse for any *.doc file and load it into the RitchText object. NOTE: Format:=6 instructs Word to save the file as RTF. Extension is not enough. Other File Formats: .Format File Argument Format -------- ------ 0 Normal (Word format) 1 Document Template 2 Text Only (extended characters saved in ANSI character set) 3 Text+Breaks (plain text with line breaks; extended characters saved in ANSI character set) 4 Text Only (PC-8) (extended characters saved in IBM PC character set) 5 Text+Breaks (PC-8) (text with line breaks; extended characters saved in IBM PC character set) 6 Rich-text format (RTF) *********************************************************************** procedure TImport_Form.ToolButton3Click(Sender: TObject); Var WordApp:Variant; begin if OpenDialog1.Execute then Begin Edit1.Text:=ExtractFileName(OpenDialog1.FileName); StatusBar1.SimpleText:=OpenDialog1.FileName; WordApp := CreateOleObject('Word.Basic'); If not VarIsEmpty(WordApp) then Begin WordApp.FileOpen(OpenDialog1.FileName); WordApp.FileSaveAs(Name := 'c:\temp_bb.rtf', Format:=6); WordApp.AppClose; WordApp:=Unassigned; WordEditor.Lines.LoadFromFile('c:\temp_bb.rtf'); End Else ShowMessage('Could not start MS Word'); End; end; ************************************************************************* P.S source code is FREEWARE, so you can use it as you want. Enjoy and have Fun, Roni Havas