1 Star 0 Fork 0

disenQF/libxls

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

Build Status Build Status Fuzzing Status

libxls - Read XLS files from C

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

After several years of neglect, libxls is under new management as of the 1.5.x series. Head over to releases to get the latest stable version of libxls 1.5, which fixes many security vulnerabilities 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 you find a bug, please file it on the GitHub issue tracker.

Changes to libxls since 1.4:

  • Hosted on GitHub (hooray!)
  • New in-memory parsing API (see xls_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

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));
    exit(1);
}
for (int i=0; i<wb->sheets.count; i++) { // sheets
    xlsWorkSheet *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_BLANK) {
                // do something with a blank cell
            } else if (cell->id == XLS_RECORD_NUMBER) {
               // use cell->d, a double-precision number
            } else if (cell->id == XLS_RECORD_FORMULA) {
                if (strcmp(cell->str, "bool") == 0) {
                    // its boolean, and test cell->d > 0.0 for true
                } else if (strcmp(cell->str, "error") == 0) {
                    // formula is in error
                } else {
                    // cell->str is valid as the result of a string formula.
                }
            } else if (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 for xls2csv has more details.

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 Compound 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.5.0 or later.

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. It assumes autotools is already installed 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:

libxls -- A multiplatform, C/C++ library for parsing Excel(TM) files. Copyright 2004 Komarov Valery Copyright 2006 Christophe Leitienne Copyright 2008-2017 David Hoerl Copyright 2013 Bob Colbert Copyright 2013-2018 Evan Miller The included libxls code is licensed under the BSD 2-clause license: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
C 等 4 种语言
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/disenQF/libxls.git
git@gitee.com:disenQF/libxls.git
disenQF
libxls
libxls
master

搜索帮助