Delphi 7 Open Office Save Problem

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
emrah24
Posts: 3
Joined: Tue Sep 04, 2018 7:19 am

Delphi 7 Open Office Save Problem

Post by emrah24 »

hello my codes are down.
This code is working but I want to save it as .doc and make this process in the background (hidden).

thanks in advance

Code: Select all

procedure OpenOfficeReplace(const AFileURL: string; ASearch: string; const AReplace: string);
var
  StarOffice: Variant;
  StarDesktop: Variant;
  StarDocument: Variant;
  FileReplace: Variant;
  FileParams: Variant;
  FileProperty: Variant;

begin

  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 := False;
  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);

  //ShowMessage('Replace has been finished');

 StarDocument.Close(True);
 StarDesktop.Terminate;
 StarOffice := Unassigned;

         end;
Last edited by robleyd on Tue Sep 04, 2018 7:57 am, edited 1 time in total.
Reason: Remove Known Issues icon [robleyd, Moderator]
OpenOffice 3.1 on Windows Vista
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Delphi 7 Open Office Save Problem

Post by Lupp »

(I never did such things based on the Delphi bridge, but:)
-1- You need to use the docFrame.ContainerWindow.setVisible(Boolean) with False after loading if you want to run the process in the background.
-2- You did not tell what file type the loaded URL has, but it seems, it was a format native to OpenOffice.
-3- As you want to save to .doc I assume, the original was .odt.
-4- You need to use either the storeAsUrl or the storeToUrl method.
-5- Closing the document anyway after that, there shouldn't be a relevant difference insofar.
-6- See https://api.libreoffice.org/docs/idl/re ... 6c966d4809 for more details.
(The link concerns LibO, but the content should also be valid for AOO.)
-7- Regard the FilterName specifically if you want to store to an alien format (rarely recommendable).

Code: Select all

args(0).Name = "FilterName"
args(0).Value = "Microsoft Word 97/2000/XP"
should work. The UrlString should contain the .doc extension then to avoid misunderstandings.

A question in return:
Do you know how to get the bridge work with Freepascal / Lazarus? Lacking detailed experience I would appreciate an example.

BTW:
Your signaturew tells OOo V 3.1 (That was before the branching off of LibO.) That's very old meanwhile (2008 at latest I suppose). Recent AOO is V 4.1.5, recent LibO is V 6.1.0.
You may probably experience problems with getting reliable information in cases where something was changed since 3.1.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
emrah24
Posts: 3
Joined: Tue Sep 04, 2018 7:19 am

Re: Delphi 7 Open Office Save Problem

Post by emrah24 »

thanks. but i could not

doc or odt not important

I'm not work code.
OpenOffice 3.1 on Windows Vista
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Delphi 7 Open Office Save Problem

Post by Lupp »

Sorry. I obviously don't understand. Do you expect me to rework the Delphi code for you - or what else?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
emrah24
Posts: 3
Joined: Tue Sep 04, 2018 7:19 am

Re: Delphi 7 Open Office Save Problem

Post by emrah24 »

I'm Sory.
I have a .doc file and I need to do multiple replace but I have opne office on my computer.
I am trying to do this in Delphi 7 as well. That's all I said :(
OpenOffice 3.1 on Windows Vista
Post Reply