Code Monkey home page Code Monkey logo

libxls's Introduction

Build Status Build Status

libxls - Read XLS files from C

This is libxls, a C library for reading Excel files in the nasty old binary OLE format. We are in the process of preparing a 1.5 release and moving the project over from SourceForge. If you need a stable release, head back to SourceForge, or see the releases section, which currently has copies of everything from SourceForge.

Please note that the current stable releases have several public security vulnerabilities. We'll have them fixed in 1.5. Hang tight.

Changes since 1.4:

  • Hosted on GitHub (hooray!)
  • New in-memory parsing API
  • Internals rewritten to return errors instead of exiting
  • Heavily fuzz-tested with clang's libFuzzer, fixing many memory leaks and cough CVEs
  • Improved compatibility with C++
  • Continuous integration tests on Mac, Linux, and Windows
  • Lots of other small fixes, see the commit history

The C API is pretty simple, this will get you started:

xls_error_t error = LIBXLS_OK;
xlsWorkBook *wb = xls_open_file("/path/to/finances.xls", "UTF-8", &error);
if (wb == NULL) {
    printf("Error reading file: %s\n", xls_getError(error));
} else {
    for (int i=0; i<wb->sheets.count; i++) { // sheets
        xl_WorkSheet *work_sheet = xls_getWorkSheet(work_book, i);
        error = xls_parseWorkSheet(work_sheet);
        for (int j=0; j<=work_sheet->rows.lastrow; j++) { // rows
            xlsRow *row = xls_row(work_sheet, j);
            for (int k=0; k<=work_sheet->rows.lastcol; k++) { // columns
                xlsCell *cell = &row->cells.cell[k];
                // do something with cell
                if (cell->id == XLS_RECORD_FORMULA) { // formula
                } else 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.
                }
            }
        }
        xls_close_WS(work_sheet);
    }
    xls_close_WB(wb);
}

The library also includes a CLI tool for converting Excel files to CSV:

./xls2csv /path/to/file.xls

Libxls should run fine on both little-endian and big-endian systems, but if not please open an issue.

If you want to hack on the source, you should first familiarize yourself with the Microsoft Excel File Format as well as Coumpound Document file format (documentation provided by the nice folks at OpenOffice.org).

Installation

If you want a stable version, check out the Releases section, which has copies of everything you'll find in Sourceforge, and download version 1.4.0.

For full instructions see INSTALL, or here's the tl;dr:

To install a stable release:

./configure
make
make install

If you've cloned the git repository, you'll need to run this first:

./bootstrap

That will generate all the supporting files (assuming autotools is already present on the system).

libxls's People

Contributors

evanmiller avatar dhoerl avatar tbeu avatar jennybc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.