WPCubed Product Support

FAQ: Load DOC into WPTools

support

WPTools includes the unit WPWordConvwhich can load and use the converter DLLs which are usually installed on Windows.

Those DLLs can be used to convert a DOC file into RTF code "on the fly". They are automatically used by the Open dialog when the unit WPWordConv was added to the project.

But it is also possible to call them directly, for example if always a certain converter should be called.

Simple Example Project - it contains the combobox "ConverterList"

type
  TForm1 = class(TForm)
    WPRichText1: TWPRichText;
    Panel1: TPanel;
    Button1: TButton;
    ConverterList: TComboBox;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    converter : TWPWordConverter;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  converter := TWPWordConverter.Create(Self);
  converter.GetConverterNames(ConverterList.Items,wpcnvImport);
  ConverterList.ItemIndex := 0;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   converter.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var mem : TMemoryStream;
begin
  if OpenDialog1.Execute then
  begin
     mem := TMemoryStream.Create;
     try
       converter.Convert( OpenDialog1.FileName, mem, wpcnvImport, ConverterList.ItemIndex);
       mem.Position := 0;
       WPRichText1.LoadFromStream(mem, 'RTF', true);
     finally
       mem.Free;
     end;
  end;
end;
#1 ♥ 0
9.8k Views 1 users read 2 min
support

News: For WPTools 7 you can now license the optional native DocX reader and writer units.
DocX is the "new" office format - it is basically a ZIP file with embedded XML and binary data.

#2 ♥ 0