Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Read binary Excel files from C/C++

License

NotificationsYou must be signed in to change notification settings

libxls/libxls

Repository files navigation

Build StatusFuzzing Status

libxls - Read XLS files from C

This is libxls, a C library for reading Excel files in the nasty old binary OLEformat, plus a command-line tool for converting XLS to CSV (named, appropriatelyenough,xls2csv).

After several years of neglect, libxls is under new management as of the 1.5.xseries. Head over toreleases toget the latest stable version of libxls 1.5, which fixesmany securityvulnerabilities found in libxls 1.4 and earlier.

Libxls 1.5 also includes new APIs for parsing files stored in memory buffers,and returns errors instead of exiting upon encountering malformed input. If youfind a bug, please file it on theGitHub issue tracker.

Changes to libxls since 1.4:

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

TheC API is pretty simple, this will get you started:

xls_error_terror=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));exit(1);}for (inti=0;i<wb->sheets.count;i++) {// sheetsxlsWorkSheet*work_sheet=xls_getWorkSheet(work_book,i);error=xls_parseWorkSheet(work_sheet);for (intj=0;j<=work_sheet->rows.lastrow;j++) {// rowsxlsRow*row=xls_row(work_sheet,j);for (intk=0;k<=work_sheet->rows.lastcol;k++) {// columnsxlsCell*cell=&row->cells.cell[k];// do something with cellif (cell->id==XLS_RECORD_BLANK) {// do something with a blank cell            }elseif (cell->id==XLS_RECORD_NUMBER) {// use cell->d, a double-precision number            }elseif (cell->id==XLS_RECORD_FORMULA) {if (strcmp(cell->str,"bool")==0) {// its boolean, and test cell->d > 0.0 for true                }elseif (strcmp(cell->str,"error")==0) {// formula is in error                }else {// cell->str is valid as the result of a string formula.                }            }elseif (cell->str!=NULL) {// cell->str contains a string value            }        }    }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

The man page forxls2csv has more details.

Libxls should run fine on both little-endian and big-endian systems, but if notplease open anissue.

If you want to hack on the source, you should first familiarize yourself withtheMicrosoft Excel File Formatas well asCompound Document fileformat (documentation providedby the nice folks at OpenOffice.org).

Installation

If you want a stable version, check out theReleases section, which has copies of everythingyou'll find inSourceforge,and download version 1.5.0 or later.

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

To install a stable release:

./configuremakemake install

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

./autogen.sh

That will generate all the supporting files. It assumes autotools is alreadyinstalled on the system (and also expects Autoconf Archive to be present).

Language bindings

If C is not your cup of tea, you can make use of libxls in several other languages, including:

About

Read binary Excel files from C/C++

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp