views:

293

answers:

1

I've searched in google but I don't seem to find a way to read Excel files from Objective-C. The only answers I find are to first convert to CSV and then read as a text file, but I don't want that.

I know there must be a way, while I used many times the PHP modules to read/write Excel files, so I'm supposing there's also a C library to do that (which then could be used in Objective-C/iPhone app)

So ... does anyone know of such a library I could use on the iPhone?

+2  A: 

I think the PHP libraries use the Office OpenXML formats... The best library for reading/writing binary Excel files ( without running Excel itself and calling it via COM ) I've used is Apache POI - http://poi.apache.org/, but this is Java. You could attempt to use GCJ to get that working on the iPhone, but who knows what Apple would make of it. You could manually port the whole thing to Obj-C/ C++ I guess...

There are a few C / C++ libraries that do a limited subset, but they probably are not incredibly reliable or simple to use.

http://xlslib.sourceforge.net/index.php - LGPL

http://www.libxl.com/ - Commercial, $199, who knows if they would give you source for that to compile into your app.

http://www.codeproject.com/KB/office/ExcelFormat.aspx - C++ source, incredibly unclear licence like everything on code project. Who knows.

Another 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 a complete nightmare, Gnumeric is probably a better bet. Excel code is here - http://git.gnome.org/browse/gnumeric/tree/plugins/excel - its likely to need a lot of messing about to make it work outside Gnumeric. KSpread has similar code here : http://websvn.kde.org/trunk/koffice/filters/kspread/excel/import/ , but I believe Gnumeric has a better reputation for accuracy wrt to Excel import.

rjw
note: xlsLib is a library to generate excel files, but otherwise great answer - much more than I managed to find myself
Ican Zilb
Great answer (I'd +1 it, but I ran out of upvotes today - I'll come back to do it later). The CodeProject one mentioned above may be the way to go - what is done is there is from the Excel binary format: http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx#EXB - and you would have to significantly clean up and enhance that code. That's if you're dealing with Excel 97-2003 formats - with 2007/2010, its much easier as it's all just XML.
Otaku
the answer is not what I was looking for even by a long shot, while I have no ROI from the apps I make, so spending good amount of the time only on the excel import is not the way to go. Although I'm awarding the bounty since it is indeed a great answer, cheers
Ican Zilb