procedure OpenOfficeReplace(
const AFileURL:
string; ASearch:
string;
const AReplace:
string);
var
StarOffice: Variant;
StarDesktop: Variant;
StarDocument: Variant;
FileReplace: Variant;
FileParams: Variant;
FileProperty: Variant;
EmptyParam: Variant;
SaveParams: OleVariant;
SaveProperty: OleVariant;
begin
EmptyParam:= VarArrayCreate([0,-1],varVariant);
StarOffice := CreateOleObject('
com.sun.star.ServiceManager');
StarDesktop := StarOffice.CreateInstance('
com.sun.star.frame.Desktop');
FileParams := VarArrayCreate([0, 0], varVariant);
FileProperty := StarOffice.Bridge_GetStruct('
com.sun.star.beans.PropertyValue');
FileProperty.
Name := '
Hidden';
FileProperty.Value := True;
FileParams[0] := FileProperty;
StarDocument := StarDesktop.LoadComponentFromURL(AFileURL, '
_blank', 0, FileParams);
FileReplace := StarDocument.CreateReplaceDescriptor;
FileReplace.SearchCaseSensitive := False;
FileReplace.SetSearchString(ASearch);
FileReplace.SetReplaceString(AReplace);
StarDocument.ReplaceAll(FileReplace);
SaveParams:= VarArrayCreate([0, 0], varVariant);
SaveProperty := StarOffice.Bridge_GetStruct('
com.sun.star.beans.PropertyValue');
SaveProperty.
Name:= '
FilterName';
SaveProperty.Value:= '
MS Word 97';
SaveParams[0]:= SaveProperty;
StarDocument.storeAsUrl(AFileURL, SaveParams);
// ShowMessage('Replace has been finished');
StarDocument.Close(True);
StarDesktop.Terminate;
StarOffice := Unassigned;
end { OpenOfficeReplace } ;