- Offizieller Beitrag
WPTools includes the unit WPWordConv which 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"
Code
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;
Alles anzeigen