Previously, the log said that the xlslib database can only write Excel tables, but it cannot be read, but reading is a frequently needed operation ,,,
So with today's libxls, this is specifically used to read Excel tables.
Source code can be downloaded here: http://sourceforge.net/projects/libxls/
Download, decompress, and compile and install
./Configre
Make
Sudo make install
Because the directory of the header file and the library file is not in the correct position, you need to manually copy them to the system path.
Sudo CP-r-V/usr/local/libxls/include/libxls // usr/include
Sudo CP-r-V/usr/local/libxls/lib // USR
Usage:
Including header files: # include <libxls/XLS. h>
Related functions and types used:
Xlsworkbook * PWB;
Xlsworksheet * PWS;
Struct st_row_data * row;
Open an Excel table
PWB = xls_open (argv [1], "UTF-8 ");
Read the 1st page of the table
PWS = xls_getworksheet (PWB, 0 );
Xls_parseworksheet (PWS );
Get the content of a row (r)
Row = & PWS-> rows. Row [R];
Get the text of a column
Row-> cells. Cell [3]. Str
Close
Xls_close_ws (PWS );
Xls_close_wb (PWB );
Compile command: gcc-O readxls. C-lxlsreader
A simple example of readxls. C:
#include <stdio.h>#include <stdlib.h>#include <libxls/xls.h>#include <unistd.h>/////////////////////////////////////////////////void strrpl(char *result, char *str, char *old_str, char *new_str);/////////////////////////////////////////////////int main(int argc, char **argv) { xlsWorkBook *pWb; xlsWorkSheet *pWs; struct st_row_data *row; int r,c; char buf[512], result[512]; if (argc < 2) { sprintf(stderr, "please input the xml file."); return EXIT_FAILURE; } // open workbook, choose standard coversion pWb = xls_open(argv[1], "UTF-8"); if (NULL == pWb) { fprintf(stderr, "File not found!\n"); return EXIT_FAILURE; } // open and parse the first sheet pWs = xls_getWorkSheet(pWb, 0); xls_parseWorkSheet(pWs); // process all rows of the first sheet for (r=0; r<=pWs->rows.lastrow; r++) { row = &pWs->rows.row[r]; for (c=0; c<=pWs->rows.lastcol; c++) { if (row->cells.cell[c].str != NULL) { printf("%\t", row->cells.cell[c].str); } } printf("\n"); } // close workSheet xls_close_WS(pWs); // close workbook xls_close_WB(pWb); return 0;}