Skip to content

Commit

Permalink
Version 1.5.0, Release Candidate 0
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmiller committed Jan 31, 2019
1 parent 43b6d47 commit 79f9ea9
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 42 deletions.
14 changes: 7 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ nobase_include_HEADERS = \
bin_PROGRAMS = xls2csv
noinst_PROGRAMS = test_libxls test2_libxls

dist_man1_MANS = man/xls2csv.man

lib_LTLIBRARIES = libxlsreader.la

xls2csv_SOURCES = \
Expand Down Expand Up @@ -49,6 +51,11 @@ test2_libxls_LDADD = libxlsreader.la
check_PROGRAMS = test_libxls test2_libxls
TESTS = test_libxls

EXTRA_DIST = test/files/test2.xls

distclean-local:
-rm -f $(builddir)/test.htm

EXTRA_PROGRAMS = fuzz_xls

# Force C++ linking for fuzz target
Expand All @@ -58,10 +65,3 @@ fuzz_xls_SOURCES = fuzz/fuzz_xls.c
fuzz_xls_CFLAGS = -Wall -Werror -pedantic-errors -std=c99
fuzz_xls_LDADD = libxlsreader.la @LIB_FUZZING_ENGINE@
fuzz_xls_LDFLAGS = -static

# Extra files to distribute
EXTRA_DIST = doc test/files/test2.xls

dist-hook:
rm -rf `find $(distdir)/doc -name CVS`

68 changes: 40 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ 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](https://sourceforge.net/projects/libxls/).** If you need
a stable release, head back to SourceForge, or see the
[releases](https://github.com/libxls/libxls/releases) section, which currently
has copies of everything from SourceForge.
format, plus a command-line tool for converting XLS to CSV (named, appropriately
enough, `xls2csv`).

Please note that the current stable releases have several public security
vulnerabilities. We'll have them fixed in 1.5. Hang tight.
After several years of neglect, libxls is under new management as of the 1.5.x
series. Head over to [releases](https://github.com/libxls/libxls/releases) to
get the latest stable version of libxls 1.5, which fixes *many* security
vulnerabilities found in libxls 1.4 and earlier.

Changes since 1.4:
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](https://github.com/libxls/libxls/issues).

Changes to libxls since 1.4:

* Hosted on GitHub (hooray!)
* New in-memory parsing API
* 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 *cough* CVEs
* 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
Expand All @@ -31,35 +34,44 @@ 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
exit(1);
}
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_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 {
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.
// 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);
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](https://github.com/libxls/libxls/issues/new).

Expand All @@ -71,7 +83,7 @@ Installation
If you want a stable version, check out the
[Releases](https://github.com/libxls/libxls/releases) section, which has copies of everything
you'll find in [Sourceforge](https://sourceforge.net/projects/libxls/files/),
and download version 1.4.0.
and download version 1.5.0 or later.

For full instructions see [INSTALL](INSTALL), or here's the tl;dr:

Expand Down
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
AC_INIT([libxls],[1.4.0],[emmiller@gmail.com])
AC_INIT([libxls],[1.5.0-rc0],[emmiller@gmail.com])
AC_CONFIG_SRCDIR([test/test.c])
PACKAGE=libxls

LIBXLS_MAJOR_VERSION=1
LIBXLS_MINOR_VERSION=4
LIBXLS_MINOR_VERSION=5
LIBXLS_MICRO_VERSION=0

VERSION=$LIBXLS_MAJOR_VERSION.$LIBXLS_MINOR_VERSION.$LIBXLS_MICRO_VERSION
Expand All @@ -28,7 +28,7 @@ AC_CANONICAL_BUILD
AC_CANONICAL_HOST

AC_CONFIG_HEADERS([config.h])
AC_PREFIX_DEFAULT(/usr/local/libxls)
AC_PREFIX_DEFAULT(/usr/local)

AC_PROG_INSTALL
AC_PROG_CC
Expand Down
41 changes: 41 additions & 0 deletions man/xls2csv.man
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.TH XLS2CSV 1 "31 January 2019"
.SH NAME
xls2csv \- convert binary Excel (.xls) files to CSV
.SH SYNOPSIS
.B xls2csv
.IR input-file
[\fB-l\fR]
[\fB-v\fR]
[\fB-e\fR \fIencoding\fR]
[\fB-t\fR \fIsheet\fR]
[\fB-q\fR \fIquote char\fR]
[\fB-f\fR \fIfield separator\fR]
.P
.SH DESCRIPTION
.B xls2csv
converts binary Excel files (.xls) to comma-separated values (CSV), sending the plain-text output to standard out.
.PP
Unless otherwise specified, all sheets in the workbook are processed, and the output values are double-quoted, separated by semicolons, and encoded as UTF-8. This behavior may be customized with the options below.
.SH OPTIONS
.TP
.BR \-l
List sheets contained in the file but do not output their contents.
.TP
\fB\-t\fR \fIsheet\fR
Only process the named sheet.
.TP
\fB-e\fR \fIencoding\fR
The iconv output encoding (default "UTF-8")
.TP
\fB-q\fR \fIquote char\fR
The character used to quote strings (default '"')
.TP
\fB-f\fR \fIfield separator\fR
The character used to separate strings (default ';')
.TP
\fB-v\fR
Verbose mode
.SH BUGS
The conversion tool has not been tested on big-endian machines.
.SH AUTHOR
Copyright (C) 2004-2019 the libxls authors
9 changes: 6 additions & 3 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <string.h>
#include <ctype.h>

#include "xls.h"
#include "../include/xls.h"

int main(int argc, char *argv[])
{
Expand All @@ -51,10 +51,13 @@ int main(int argc, char *argv[])
xls_error_t code = LIBXLS_OK;
struct st_row_data* row;
WORD t,tt;
pWB=xls_open_file("test/files/test2.xls", "UTF-8", &code);
char *srcdir = getenv("srcdir");
char path[2048];
snprintf(path, sizeof(path), "%s/test/files/test2.xls", srcdir ? srcdir : ".");
pWB=xls_open_file(path, "UTF-8", &code);

if (pWB == NULL) {
fprintf(stderr, "Unable to open file: %s\n", xls_getError(code));
fprintf(stderr, "Unable to open %s: %s\n", path, xls_getError(code));
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test2.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <string.h>
#include <ctype.h>

#include "xls.h"
#include "../include/xls.h"

int main(int argc, char *argv[])
{
Expand Down

0 comments on commit 79f9ea9

Please sign in to comment.