Lazarus

Programming => General => Topic started by: egsuh on August 26, 2024, 05:14:12 am

Title: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: egsuh on August 26, 2024, 05:14:12 am
Here's wiki explanation,

https://wiki.lazarus.freepascal.org/Office_Automation (https://wiki.lazarus.freepascal.org/Office_Automation)

but when I tried, I cannot create Ole object.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3.    ServerName = 'com.sun.star.ServiceManager';
  4. var
  5.   Server     : Variant;
  6.   Desktop    : Variant;
  7.   LoadParams : Variant;
  8.   Document   : Variant;
  9.   TextCursor : Variant;
  10. begin
  11.   if Assigned(InitProc) then
  12.     TProcedure(InitProc);
  13.  
  14.   try
  15.     Server := CreateOleObject(ServerName);  // Error is raised EOleSysError, saying wrong class string.
  16.   except
  17.     ShowMessage('Unable to start OO.');
  18.     Exit;
  19.   end;
  20.  
  21.   Desktop := Server.CreateInstance('com.sun.star.frame.Desktop');
  22.  
  23.   LoadParams := VarArrayCreate([0, -1], varVariant);
  24.  
  25.   // ..............
  26. end;
  27.  
  28.  
Title: Re: Does anybody run OpenOffice from Lazarus?
Post by: loaded on August 26, 2024, 02:02:24 pm
I use the following code that I created through trial and error in my work. It works very well.  :)

Code: Pascal  [Select][+][-]
  1. uses ComObj,Variants;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   OpenOffice    : OleVariant;
  6.   LoadParams : OleVariant;
  7.   Sheet   : Variant;
  8.   Exs:WideString;
  9. begin
  10.   try
  11.     OpenOffice := CreateOleObject('com.sun.star.ServiceManager');
  12.     LoadParams := VarArrayCreate([0, 0], varVariant);
  13.     LoadParams[0] := OpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
  14.     LoadParams[0].Name := 'Hidden'; LoadParams[0].Value := false;
  15.     OpenOffice := OpenOffice.createInstance('com.sun.star.frame.Desktop');
  16.     Sheet := OpenOffice.loadComponentFromURL('private:factory/scalc', '_blank', 0, LoadParams);
  17.     Sheet:= Sheet.getSheets.getByIndex(0);
  18.     Exs:=Utf8decode('Example');Sheet.getCellbyPosition(0,0).setformula(Exs);
  19.   except
  20.     showmessage('Open Office Kurulu Değil');
  21.     Exit;
  22.   end;
  23. end;  
  24.  
Title: Re: Does anybody run OpenOffice from Lazarus?
Post by: egsuh on August 27, 2024, 05:47:06 am
Well, following code is not executed.

OpenOffice := CreateOleObject('com.sun.star.ServiceManager');

What is your system? Mine is Windows 11, and OpenOffice 4.1.15 is installed. Is there no problem of 32bit vs. 64bit applications? Do I need anything else than simply installing OpenOffice?
Title: Re: Does anybody run OpenOffice from Lazarus?
Post by: cdbc on August 27, 2024, 08:50:04 am
Hi
I dunno, but on the off-chance, you're running 'LibreOffice', maybe go sniffling on their support site, for the right /automation/ server... Could be it's not called 'com.sun.star.ServiceManager' anymore...
Regards Benny
Title: Re: Does anybody run OpenOffice from Lazarus?
Post by: Zvoni on August 27, 2024, 09:07:35 am
IIRC, CreateOleObject is actually searching the Registry for the Server-String
Word.Application for MS Word --> "Computer\HKEY_CLASSES_ROOT\Word.Application"

In case of OO/LO, i'd look manually for the reg-Key and check what's the correct value
Title: Re: Does anybody run OpenOffice from Lazarus?
Post by: egsuh on August 28, 2024, 08:29:59 am
Hello guys,

Based on your advises, I re-installed Open Office and it works now. Thanks a lot !!!!
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: Thaddy on August 28, 2024, 10:21:19 am
Note that openoffice is somewhat deprecated in favor of libreoffice. You can google on that if you want.
It does not matter for the question and answers, though: the compatibility is there.
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: egsuh on August 29, 2024, 10:28:17 am
Quote
Note that openoffice is somewhat deprecated in favor of libreoffice. You can google on that if you want.
It does not matter for the question and answers, though: the compatibility is there.

Thank you for your information. But it seems that OpenOffice.org has changed to Apache OpenOffice, which is still supported.
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: egsuh on August 29, 2024, 11:04:21 am
I uninstalled OpenOffice and installed LibreOffice, and the program itself still works. But I have next problem ... the charset? codepage? problem.

Code: Pascal  [Select][+][-]
  1.     s := 'This is 가나다라마바사';
  2.     oText.insertString( TextCursor, 'Heading  가나다라'#13, False );          

Texts should be displayed as in the above code snippet, but they are shown as the attached image.
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: cdbc on August 29, 2024, 11:18:45 am
Hi
First off: LibreOffice supports/uses unicode, as answered here (https://ask.libreoffice.org/t/unicode-symbol-not-displaying-in-libreoffice-5-2-2/21943/2)
Which leads me to think, that maybe you could use:
Code: Pascal  [Select][+][-]
  1.     s := UTF8Decode('This is 가나다라마바사');
  2.     oText.insertString( TextCursor, UTF8Decode('Heading  가나다라'#13), False );
  3.  

to convert your utf8-strings to unicode...
Just a thought  :-\
Regards Benny
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: rvk on August 29, 2024, 11:19:27 am
I uninstalled OpenOffice and installed LibreOffice, and the program itself still works. But I have next problem ... the charset? codepage? problem.
Wasn't this already covered?

Code: Pascal  [Select][+][-]
  1. oText.insertString( TextCursor, Utf8Decode('Heading  가나다라'#13), False );

Edit: Just a few seconds late  ;)
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: egsuh on August 30, 2024, 04:21:07 am
Following works.

Code: Pascal  [Select][+][-]
  1.      s := UTF8Decode('This is 가나다라마바사');
  2.     oText.insertString( TextCursor, UTF8Decode('Heading  가나다라'#13), False );

Really really thank you.

I attached correct form. Some styles seem not to have Korean fonts, but simply I don't have to use those styles.
Title: Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
Post by: Thaddy on August 30, 2024, 03:37:56 pm
That is not a bug, but the lack of support for Korean of the font file.
TinyPortal © 2005-2018