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

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
swampwiz
Posts: 32
Joined: Wed Mar 17, 2010 11:30 am

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

Post by swampwiz »

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 4.1.2 (perhaps later since swampwiz doesn't provide accurate information here -- MrProgrammer, forum moderator)
FJCC
Moderator
Posts: 9271
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

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

Post by FJCC »

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.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Post by Zizi64 »

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; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
swampwiz
Posts: 32
Joined: Wed Mar 17, 2010 11:30 am

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

Post by swampwiz »

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 4.1.2 (perhaps later since swampwiz doesn't provide accurate information here -- MrProgrammer, forum moderator)
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

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

Post by Zizi64 »

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; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
swampwiz
Posts: 32
Joined: Wed Mar 17, 2010 11:30 am

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

Post by swampwiz »

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 4.1.2 (perhaps later since swampwiz doesn't provide accurate information here -- MrProgrammer, forum moderator)
Post Reply