December 4, 2010

Volker Volker
Ant Farmer
5428 posts

Excel API for C/C++

Page  
1

Does anyone know of a platform independent C or C++ library/API for reading and writing Excelâ„¢ files?

The native API from Microsoft is not an option, as it might not be installed on every machine we target nor is it available on Macs.

I know of jexcelapi for Java, but never heard of a similar lib for our beloved C++ :)

41 replies

December 4, 2010

xsacha xsacha
Lab Rat
517 posts

KSpread (part of KOffice) reads/writes Excel files. KSpread uses Qt (and KDE libs).

Have you checked to see how they do it?

 Signature 

- Sacha

December 4, 2010

Andre Andre
Robot Herder
6399 posts

Do you really need Excel output, or do you just need to output data that Excel can read?

If the latter is enough, considder a simpler format like csv. Otherwise, you may want to investigate either the .ods or the .xlsx format. Both are packed structures with XML files, but they are not simple I have heard. I never worked with them directly.

A last option that may be workable is to go through ODBC and QtSql. You can read and write Excel files that way, but of course there are limits to what you can do there.

December 5, 2010

Volker Volker
Ant Farmer
5428 posts

I’ve found some infos on the Excel 2003 XML format on this page [blogs.msdn.com]. Could be a good start.

CSV ist not an option, it’s very cumbersome to read and write correctly. And the users receiving the CSV must take care of the correct settings (charset, delimiter, enclosing quotes and all that). That’s error prone and the support for it is a nightmare – we all are developers, aren’t we? :-) Also we need it in both directions (import Excel sheets of our users into our database and generate spread sheets for the users filled with our data).

Unfortunately we also must support opening Excel files in the native (i.e. non-XML) format, otherwise we would had to convert them by hand. Giving xlsx to our users would be ok.

December 5, 2010

Volker Volker
Ant Farmer
5428 posts

We can have Jexcelapi on the server using java. No problem with that. This way we have to put everything to the server, but I want do do some things in the Qt/C++ based client.

December 5, 2010

xsacha xsacha
Lab Rat
517 posts
Volker wrote:
Unfortunately we also must support opening Excel files in the native (i.e. non-XML) format, otherwise we would had to convert them by hand. Giving xlsx to our users would be ok.

I believe Microsoft has a tool for converting non-XML to XML. You may be able to use it in a batch process.

So you only need to get info out? You don’t need to be able to edit it and save it? There are quite a number of tools to convert XML files in to other formats, I believe.

 Signature 

- Sacha

December 5, 2010

Volker Volker
Ant Farmer
5428 posts

You did read of that “platform independent” thingy, didn’t you? :) To be able to work on a Mac I cannot use the Microsoft tools. And of course that tool exists, it’s called Excel :)

December 5, 2010

xsacha xsacha
Lab Rat
517 posts

I think it’s a downloadable tool for people with old versions of Excel actually. Standalone. But yes, it was a Windows app.

You have Excel on Mac [ehow.co.uk] too :P

There may be a Mac app for this. Or you could try wine (or similar).

Probably make life much easier.

 Signature 

- Sacha

December 5, 2010

Volker Volker
Ant Farmer
5428 posts

Come on… you cannot force your commercial customers to install wine just to convert some crappy xls files :-)

Everthing other than a lib I can incorporate to my app is not acceptable; it’s more pleasent for the user if we upload the files to the business logic server then.

December 5, 2010

xsacha xsacha
Lab Rat
517 posts

Alright, I guess since it is for paying customers it is best to treat them nice.

Good luck with your Excel API. I’m sure someone has written something like it for Qt somewhere. You checked Qt-Apps already and similar sites?

This can search Excel files: http://qt-apps.org/content/show.php/recoll?content=66138
But might not have the full API.

 Signature 

- Sacha

December 5, 2010

Volker Volker
Ant Farmer
5428 posts

I’ve searched around with google, got some things that might be interesting, but nothing with using Qt in the first search results. It’s not on a very high priority at the moment, so no need to worry. I thought it’s worth a try in this forum – if you don’t ask, you won’t get an answer…

December 28, 2010

Yash Yash
Lab Rat
92 posts

There are 2 C++ libaries to create excel.
One is free xlslib : http://xlslib.sourceforge.net/
Other is commercial libXL : http://www.libxl.com/

Sorry for late response and I don’t know whether you need this or not. But for others I share…

 Signature 

http://kineticwing.com : Web IDE, QSS Editor
http://speedovation.com : Development Lab

December 28, 2010

Volker Volker
Ant Farmer
5428 posts

Thanks for the links. libxl I will have a look into. xlslib unfortunately cannot read XLS files. This is the crucial part. Writing the files could be quite easily approached with the new XML based format (thats seems not too complicated as long as there are no formulas or cross references, which we do not need).

December 28, 2010

qtrahul qtrahul
Lab Rat
188 posts

Another available option is to attempt to extract the code from an open source excel reading competitor.

Open Office – http://www.openoffice.org/ – is likely to be used,

Gnumeric is probably a better option.
Excel code is here – http://git.gnome.org/browse/gnumeric/tree/plugins/excel

December 29, 2010

Yash Yash
Lab Rat
92 posts

Libxls
libxls is a C library which can read Excel (xls) files. It has been tested on Linux x86 and Cygwin but may work on any little-endian system. …
libxls.sourceforge.net [libxls.sourceforge.net]

[EDIT: clickable link, Volker]

 Signature 

http://kineticwing.com : Web IDE, QSS Editor
http://speedovation.com : Development Lab

December 29, 2010

Volker Volker
Ant Farmer
5428 posts

Thanks for the link Yash, it looks promising. It could be a good start and maybe I find some time to make a Qt version.

Page  
1

  ‹‹ Extension to QSortFilterProxyModel      Academic training centers around the world ››

You must log in to post a reply. Not a member yet? Register here!