Here is a free DLL you can use to read XLS files.
Features:
do not need EXCEL or other compatible spreadsheet software
file types supported: BIFF8
corresponding EXCEL versions:
Microsoft Excel 97 (XL8),
Microsoft Excel 2000 (XL9),
Microsoft Excel 2002 (XL10),
Microsoft Excel 2003 (XL11),
Microsoft Excel 2007 (XL12)
character set: standard ANSI
sheets: data only
formulas: result only
numbers with full precision
Updates
Encrypted files do not crash any more (case of XLS files with password). An error message is issued by XLS_createWorkbook() . The function XLS_RowsScan() can now be called more than once within the same sheet.
Example of use:
#include <stdlib.h> #include <stdio.h> #include <string.h> #include "xlsread.h" /*====== callback function for processing cells ====*/ int put(int row, int col, char *str, double val) { printf(" row %d - col %d : ", row, col) ; /* print all cells */ if (str) printf("[%d] \"%.40s\"\n", strlen(str), str) ; else printf("%g\n", val) ; return 0 ; } /*================================ main program ====*/ int main( int argc, char *argv[ ]) { char *filein[] = { "file1.xls", "file2.xls", "" } ; /* file list */ char *err_msg ; WORKBOOK *wkbook ; int i = 0 ; for (i = 0 ; strlen(filein[i]) ; i++) /* scan files */ { printf("\n==== %s\n", filein[i]) ; wkbook = XLS_WorkbookNew(filein[i], &err_msg) ; /* get workbook */ if (wkbook) { unsigned long j = 0; for (;;) /* scan sheets */ { SHEET *sheet = XLS_SheetNew(wkbook, &j, &err_msg) ; if (sheet) { printf(" Sheet %s", sheet->name) ; /* show name & */ printf(" - rows %d to %d - cols %d to %d\n", /* size */ sheet->rowFirst, sheet->rowLast, sheet->colFirst, sheet->colLast) ; XLS_RowsScan(sheet, 0, put) ; /* scan sheet */ XLS_SheetDelete(&sheet) ; } else break ; } XLS_WorkbookDelete(&wkbook) ; } else printf(">>>> %s\n", err_msg) ; } }
Explanations:
For each file, one must create a workbook and then, it isq possible to scan sheets.
The main sheet properties are name, rowFirst, rowLast, colFirst and colLast as used above.
The dive in a sheet, call XLS_RowsScan().
This function requires a callback, that is a function which will be called for each cell.
It is put() in the above example.
Prototype: int put(int row, int col, char *str, double val)
Input parameters are:
the cell coordinates: row and col,
the cell value: str
or val
if
the cell is numeric, str
is NULL, and val
contains the value
if the cell contains text, str
points on it.
Return value:
if 0: the next cell will be processed until the end of the sheet,
if not null, the XLS_RowsScan() returns with that value.
The zip file contains xlsread.h, .lib and .dll.
Build tool: MS VC++ 6
Contact:
Henri
Serindat
hserindat@numericable.fr