There is the LibXL library, but it is paid for.
Example: Generate a spreadsheet from scratch
#include "libxl.h"
int main()
{
BookHandle book = xlCreateBook(); // xlCreateXMLBook()
if(book)
{
SheetHandle sheet = xlBookAddSheet(book, L"Sheet1");
if(sheet)
{
xlSheetWriteStr(sheet, 2, 1, L"Hello, World !", NULL);
xlSheetWriteNum(sheet, 3, 1, 1000, NULL);
}
xlBookSave(book, L"example.xls");
xlBookRelease(book);
}
return 0;
}
A free open source alternative is the XLSX I / O library.
Example
//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);