I'm writing an Open Office link for my application, so our customers can create letters from templates and send them by mail/email.
I'm having some difficulties, however, to store the document in *.doc format (for MS WORD 97-XP).
I created a test project that takes text from a memobox and stores it in a new document. I can save the document as *odt without any problems. But when i give the parameters to save it as a *.doc, it creates a *.doc file, but the file is still in *.odt format (i.e. if i open it with MS Word, it gives an error message, asking permission to repair the file).
Could somebody pls give me an indication where I'm doing something wrong?
Code: Select all
procedure TFMain.btnexportClick(Sender: TObject);
var
Desktop, LoadParams, Document, TextCursor, FilterParams:Variant;
test : widestring;
begin
Server := CreateOleObject('com.sun.star.ServiceManager'); //Server is declared as a Variant
Desktop := Server.CreateInstance('com.sun.star.frame.Desktop');
LoadParams := VarArrayCreate([0, -1], varVariant);
Document := Desktop.LoadComponentFromURL('private:factory/swriter','_blank',0,LoadParams);
TextCursor := Document.Text.CreateTextCursor;
test := memo1.lines.text;
document.Text.insertString(TextCursor,test,0);
FilterParams := VarArrayCreate([0,0], varVariant);
FilterParams[0] := CreateProperty('FilterName', 'MS Word 97');
document.StoreToURL('file:///C:/test.doc',FilterParams);
end;
function TFMain.CreateProperty(const AName: AnsiString; AValue: Variant): Variant;
begin
Result := Server.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
Result.Name := AName;
Result.Value := AValue;
end;