View on GitHub

XLSX I/O

XLSX I/O - C library for reading and writing .xlsx files

Download this project as a .zip file Download this project as a tar.gz file

XLSX I/O

Cross-platform C library for reading values from and writing values to .xlsx files.

Description

XLSX I/O aims to provide a C library for reading and writing .xlsx files. The .xlsx file format is the native format used by Microsoft(R) Excel(TM) since version 2007.

Goal

The library was written with the following goals in mind:

Reading .xlsx files:

Writing .xlsx files:

Libraries

The following libraries are provided:

Command line utilities

Some command line utilities are included:

Dependancies

This project has the following depencancies:

Note that minizip is preferred, as there have been reports that .xlsx files generated with XLSX I/O built against libzip can’t be opened with LibreOffice.

There is no dependancy on Microsoft(R) Excel(TM).

XLSX I/O was written with cross-platform portability in mind and works on multiple operating systems, including Windows, macOS and Linux.

Building from source

Requirements:

There are 2 methods to build XLSX I/O:

Building with make

Building with CMake (preferred method)

For Windows prebuilt binaries are also available for download (both 32-bit and 64-bit)

Example C program

//open .xlsx file for reading
xlsxioreader xlsxioread;
if ((xlsxioread = xlsxioread_open(filename)) == NULL) {
  fprintf(stderr, "Error opening .xlsx file\n");
  return 1;
}

//list available sheets
xlsxioreadersheetlist sheetlist;
const char* sheetname;
printf("Available sheets:\n");
if ((sheetlist = xlsxioread_sheetlist_open(xlsxioread)) != NULL) {
  while ((sheetname = xlsxioread_sheetlist_next(sheetlist)) != NULL) {
    printf(" - %s\n", sheetname);
  }
  xlsxioread_sheetlist_close(sheetlist);
}

//read values from first sheet
char* value;
printf("Contents of first sheet:\n");
xlsxioreadersheet sheet = xlsxioread_sheet_open(xlsxioread, NULL, XLSXIOREAD_SKIP_EMPTY_ROWS);
while (xlsxioread_sheet_next_row(sheet)) {
  while ((value = xlsxioread_sheet_next_cell(sheet)) != NULL) {
    printf("%s\t", value);
    free(value);
  }
  printf("\n");
}
xlsxioread_sheet_close(sheet);

//clean up
xlsxioread_close(xlsxioread);

License

XLSX I/O is released under the terms of the MIT License (MIT), see LICENSE.txt.

This means you are free to use XLSX I/O in any of your projects, from open source to commercial.

This library does not require Microsoft(R) Excel(TM) to be installed.