19

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
  • well looks like the answer after is "no, no way" the links below would give to who has enough time to spend a great start though Aug 31, 2010 at 17:41
  • Above comment no longer valid - a real answer has been provided below :-)
    – David H
    Jul 18, 2012 at 14:03

5 Answers 5

19
+50

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.

3
  • note: xlsLib is a library to generate excel files, but otherwise great answer - much more than I managed to find myself Aug 30, 2010 at 11:40
  • 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: 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.
    – Todd Main
    Aug 30, 2010 at 15:59
  • 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 Aug 31, 2010 at 17:40
18

Actually, there is such a project - its called libxls on source forge. There is a ObjectiveC class interface to the project as well. With this project you can open an excel file, and read most of the information in it (cell values as well as the file's properties).

In addition there is an iOS Objective C interface to the library.

3
  • 1
    "ObjectiveC framework, works on both Mac and iOS" is exactly what I was looking back then ... good answer Jul 18, 2012 at 14:00
  • 1
    Can you suggest where i am wrong? i have download and compile xlslib and add in my App but it give me error as below for u16string in function definition while function declaration is okay.format.cpp:122:11: Out-of-line definition of 'format_t' does not match any declaration in 'xlslib_core::format_t' and format.cpp:122:52: Reference to 'u16string' is ambiguous and format.cpp:129:1: Expected unqualified-id
    – Hindu
    Nov 27, 2012 at 5:24
  • 1
    There are two libs - libxls to read excel files (it has the objc framework) and xlslib to write excel files (not yet ported to iOS but working on it). Libxl looks nice in that you can edit if you need that.
    – David H
    Nov 27, 2012 at 23:35
2

@David H
I find his answer is the best to solve the problem. You will find his DHlibxls is better to analyzing the xls file in the ios program. Here is in my blog‘s summary

2

Other way, some where use libxls.

any way, more choose:

https://github.com/QuetzalMX/QuetzalXLSReader

1

I recently got into a project where the client wanted to import information from an Excel file into an app. I know a lot of people say, just transform it into a CSV and parse it that way, but I really didn't want the client to go through yet another step and introduce a different file format - as simple as that may be.

I tried using DHlibxls, but I felt it was a little bit too complicated, so I created QZXLSReader. It's a drag-and-drop solution so it's a lot easier to use. I don't think it's as feature complete, but it worked for me.

It's basically a library that can open XLS files and parse them into Obj-C classes. Once you have the classes, it's very easy to send them to Core Data or a dictionary or what have you.

I hope it helps!

1
  • @oliveresF I have added QZXLSReader. in our project and NSString *xlsFileURL =[[NSBundle mainBundle] pathForResource:@"GTM_map_list" ofType:@"xls"]; QZWorkbook *excelReader = [[QZWorkbook alloc] initWithContentsOfXLS:[NSURL URLWithString:xlsFileURL]]; but getting excelReader.workSheets nil Dec 20, 2015 at 11:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.