Is there a C-language API that can read an ODS file?

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Is there a C-language API that can read an ODS file?

Postby swampwiz » Sat Sep 05, 2020 11:21 pm

What I want to do is access an API written in C (or C++, C#, VB) to read in an ODS file and then programmatically look at values (I'm most interested in reading the background color of the cell, as I would be iterating through the entire spreadsheet and looking for the first column of a row that has a certain background color, and then once that is done, computing a value for each row based on the total vector of values from the background coloe iteration). Maybe there is a scripting language in the Spreadsheet app itself that can do this?
Last edited by swampwiz on Mon Sep 07, 2020 5:26 pm, edited 1 time in total.
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 3.1.1, Build 9420
swampwiz
 
Posts: 18
Joined: Wed Mar 17, 2010 11:30 am

Re: Is the a C-language API that can read an ODS file?

Postby FJCC » Sun Sep 06, 2020 1:49 am

There is a Basic macro language available in Calc for writing macros and Python is also convenient. I have seen macros written in c++, I think, but only a very few times. In any case, searching through the cells will require using the API regardless of the language.

Is the cell background set using a style or conditional formatting or purely manually? Searching for a style will be far easier than iterating through every cell.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7752
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Is the a C-language API that can read an ODS file?

Postby Zizi64 » Sun Sep 06, 2020 8:03 am

I'm most interested in reading the background color of the cell, as I would be iterating through the entire spreadsheet


A sheet has about a million of rows. Your code will be slow when you use direct (manual) formatting properties. If you not need to set different color for every individual row, then it is better to use only one (or a few) Cell Style instead of the million formatting command.

Use the Styles. It is the most valuable feature of the AOO/LO. This feature makes the Apacshe OpenOffice/LibreOffice much better than the MS Office.
You can create and apply (or delete) your own Styles by usage of the API of the AOO/LO programmatically, too.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9554
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Is the a C-language API that can read an ODS file?

Postby Villeroy » Sun Sep 06, 2020 12:00 pm

Hiding information in formatting attributes is a mistake. You would be better off if you could convert the color information into cell data as demonstrated here: http://forum.openoffice.org/en/forum/vi ... 61#p194261
--------------
Virtually nobody manipulates this office suite with C++. because it is far too complicated. You won't gain any performance anyway because every single API call takes a lot of time regardless of the language. Here is the SDK package which includes some documentation and example code: https://www.openoffice.org/api/SDK/
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28569
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Is the a C-language API that can read an ODS file?

Postby swampwiz » Mon Sep 07, 2020 6:16 pm

Villeroy wrote:Hiding information in formatting attributes is a mistake. You would be better off if you could convert the color information into cell data as demonstrated here: http://forum.openoffice.org/en/forum/vi ... 61#p194261
--------------
Virtually nobody manipulates this office suite with C++. because it is far too complicated. You won't gain any performance anyway because every single API call takes a lot of time regardless of the language. Here is the SDK package which includes some documentation and example code: https://www.openoffice.org/api/SDK/


I looked at the link, and it had an ODS file that used a function called CELL-BACKCOLOR(), but even with the RGB extension installed, I don't see this function in the function list.
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 3.1.1, Build 9420
swampwiz
 
Posts: 18
Joined: Wed Mar 17, 2010 11:30 am

Re: Is there a C-language API that can read an ODS file?

Postby Zizi64 » Mon Sep 07, 2020 6:47 pm

I looked at the link, and it had an ODS file that used a function called CELL-BACKCOLOR(), but even with the RGB extension installed, I don't see this function in the function list.


The macro embedded into the linked document is a simple macro, but not an Add-in. Only those custom functions will be appeared in the function list of the Calc, what are structured and embedded into an Add-in extension (The Add-in is a specific type of the .oxt files.)

The usual macros will work when you call by them by name, but they will not be appeared in the function list. You must know the name of the macro function (you can examine the macro code in the IDE)

Put the macro code into a Module of the Standard directory of the MyMacros: then they will available in all spreadsheet files.
Tha macros - embedded into a document file - are more portable, but they are not available from other files.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9554
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Is there a C-language API that can read an ODS file?

Postby Villeroy » Mon Sep 07, 2020 7:00 pm

My function CELL_BACKCOLOR is a StarBasic function. It is possible to write user-defined functions in StarBasic and embed them in documents. This is a simplification compared to the effort of writing sphisticated add-ins. Open my conditional_formatting.ods and hit Alt+F11 for the StarBasic macro browser. There you find the loaded document conditional_format.ods with library "Standard" having module "CELL_FUNC" with various functions to extract formatting attributes from cells. The functions use positional index data instead of references because cell functions do not pass any object data to scripts. They only pass numbers or strings as documented here: [Calc, Basic] Introspective cell functions .
This set of script functions is intended to fix broken documents where information is hidden in formatting attributes.
The macro browser has a button [Organize...] which calls another dialog providing the ability to move code modules. If you copy my module "CELL_FUNC" to the standard library under "My Macros" the functions will be availlable globally. Ctrl+Drag&Drop performs a copy. You may also use Drag&Drop and then close the document without saving to preserve the document's module.

=CELL_BACKCOLOR(SHEET();ROW();1) returns the RGB value of a cell on this sheet in the same row, column #1, for instance Sheet1.A13 if this formula is somewhere in row #13.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28569
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Is there a C-language API that can read an ODS file?

Postby swampwiz » Tue Sep 15, 2020 6:44 pm

Zizi64 wrote:
I looked at the link, and it had an ODS file that used a function called CELL-BACKCOLOR(), but even with the RGB extension installed, I don't see this function in the function list.


The macro embedded into the linked document is a simple macro, but not an Add-in. Only those custom functions will be appeared in the function list of the Calc, what are structured and embedded into an Add-in extension (The Add-in is a specific type of the .oxt files.)

The usual macros will work when you call by them by name, but they will not be appeared in the function list. You must know the name of the macro function (you can examine the macro code in the IDE)

But I used the same name as that used in the example of the thread that was recommended.
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 3.1.1, Build 9420
swampwiz
 
Posts: 18
Joined: Wed Mar 17, 2010 11:30 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 3 guests