Recent

Author Topic: [SOLVED] Does anybody run OpenOffice from Lazarus?  (Read 2837 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1489
[SOLVED] Does anybody run OpenOffice from Lazarus?
« on: August 26, 2024, 05:14:12 am »
Here's wiki explanation,

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.  
« Last Edit: August 28, 2024, 08:30:16 am by egsuh »

loaded

  • Hero Member
  • *****
  • Posts: 853
Re: Does anybody run OpenOffice from Lazarus?
« Reply #1 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.  
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

egsuh

  • Hero Member
  • *****
  • Posts: 1489
Re: Does anybody run OpenOffice from Lazarus?
« Reply #2 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?

cdbc

  • Hero Member
  • *****
  • Posts: 1646
    • http://www.cdbc.dk
Re: Does anybody run OpenOffice from Lazarus?
« Reply #3 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
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Zvoni

  • Hero Member
  • *****
  • Posts: 2738
Re: Does anybody run OpenOffice from Lazarus?
« Reply #4 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
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

egsuh

  • Hero Member
  • *****
  • Posts: 1489
Re: Does anybody run OpenOffice from Lazarus?
« Reply #5 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 !!!!

Thaddy

  • Hero Member
  • *****
  • Posts: 16158
  • Censorship about opinions does not belong here.
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #6 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.
If I smell bad code it usually is bad code and that includes my own code.

egsuh

  • Hero Member
  • *****
  • Posts: 1489
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #7 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.
« Last Edit: August 29, 2024, 10:31:28 am by egsuh »

egsuh

  • Hero Member
  • *****
  • Posts: 1489
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #8 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.

cdbc

  • Hero Member
  • *****
  • Posts: 1646
    • http://www.cdbc.dk
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #9 on: August 29, 2024, 11:18:45 am »
Hi
First off: LibreOffice supports/uses unicode, as answered here
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
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

rvk

  • Hero Member
  • *****
  • Posts: 6575
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #10 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  ;)

egsuh

  • Hero Member
  • *****
  • Posts: 1489
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #11 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.

Thaddy

  • Hero Member
  • *****
  • Posts: 16158
  • Censorship about opinions does not belong here.
Re: [SOLVED] Does anybody run OpenOffice from Lazarus?
« Reply #12 on: August 30, 2024, 03:37:56 pm »
That is not a bug, but the lack of support for Korean of the font file.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018