libxls
What is 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. It is not compatible with big endian systems.
libxls can read excel files since Excel 97 (the BIFF8 format)
libxls cannot write Excel files.
libxls is also shipped with xls2csv, a tool which converts an xls file to a csv format, more suitable for parsing.
The OpenOffice.org's Documentation of the Microsoft Excel File Format and OpenOffice.org's Coumpound Document file format were of much help to correct bugs in libxls.
Download
Current "stable" version (V0.2.0)
- Source: libxls-0.2.0.tar.gz
- Win32 binary: libxls-0.2.0-win32.tar.gz
- Mac binary: libxls-0.2.0-i386-apple.tar.gz
- Cygwin binary: libxls-0.2.0-cygwin.tar.gz
First release
This version contained a php extension to parse XLS files, not included in the automatic build process, and only distributed as a Windows DLL.
libxls 0.0.1 beta
How to use libxls ?
libxls is a C library, so you need to include the right header files:
#include <stdio.h> #include <libxls/xls.h>
You also need to link with libxlsreader.a
.
Then you'll need to open an Excel file:
xlsWorkBook* pWB; pWB=xls_open("file.xls", "iso-8859-15//TRANSLIT");
For a good start you could have a look to xls2csv.c.
How to use xls2csv ?
xls2csv takes as its first argument the name of an Excel file. It write to standard output the file converted to csv format.
For example, we can convert the file test.xls into a csv file called test.csv with the following command:
xls2csv test.xls > test.csv
Changelog
Current SVN
New features
- libxls can read Excel formulas results saved in files:
if(cell->id == 0x06) { // formula if(cell->l == 0) { // its a number ... use cell->d } else { if(cell->str == "bool") // its boolean, and test cell->d > 0.0 for true if(cell->str == "error") // formula is in error else ... cell->str is valid as the result of a string formula. }
- New functions
xls_row
andxls_cell
to get cell content. Deprecates the use of direct access to row and cell content.xlsRow* xls_row(xlsWorkSheet* pWS, WORD cellRow); xlsCell* xls_cell(xlsWorkSheet* pWS, WORD cellRow, WORD cellCol);
V0.2.0
Bugs corrected
- Corrected Cygwin bug when decoding Excel Numbers
- OLE2 file header id is now checked
- Corrected wrong fcell usage which could lead to cell moves on a row
- There was always one more empty cell on the right on each row
- Some formattings in xls_getfcell where incorrects
- Corrected some reading problems with SST having CONTINUE records