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)

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

  1. 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.
    }
  2. New functions xls_row and xls_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

  1. Corrected Cygwin bug when decoding Excel Numbers
  2. OLE2 file header id is now checked
  3. Corrected wrong fcell usage which could lead to cell moves on a row
  4. There was always one more empty cell on the right on each row
  5. Some formattings in xls_getfcell where incorrects
  6. Corrected some reading problems with SST having CONTINUE records