讀取excel文件:libxls-1.4.0.zip
下載地址:http://sourceforge.net/projects/libxls/
安裝方法:
./configure
make
make install
sudo cp -r -v /usr/local/libxls/include/libxls/ /usr/include
sudo cp -r -v /usr/local/libxls/include/xlx.h /usr/include
sudo cp -r -v /usr/local/libxls/lib/ /usr
//示例:
#include <stdio.h>
#include <stdlib.h>
#include <xls.h>
#include <unistd.h>
/////////////////////////////////////////////////
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("%s\t",row->cells.cell[c].str);
}
}
printf("\n");
}
// close workSheet
xls_close_WS(pWs);
// close workbook
xls_close_WB(pWb);
return 0;
}
編譯:gcc -o readXls readXls.c -lxlsreader
參考文檔: http://blog.csdn.net/yao_guet/article/details/7326065
http://www.codeweblog.com/libxls%E4%BD%BF%E7%94%A8/
http://blog.csdn.net/zhangqiu1989/article/details/8822853
/////////////////////////////////////////////////////////
生成excel文件:xlslib-package-2.5.0.zip
下載地址:http://sourceforge.net/projects/xlslib/
安裝方法:
./configure
make
make install
示例:
#include <string.h>
#include <xlslib/xlslib.h>
using namespace xlslib_core;
using namespace std;
int main (int argc, char *argv[])
{
workbook wb;
xf_t* xf = wb.xformat();
worksheet* ws;
ws = wb.sheet("sheet1");
string label = "Hello, World!";
ws->label(1,2,label,xf); // 從0開始數,第1行,第2列,即C3
wb.Dump("workbook.xls");
return 0;
}
編譯:
g++ helloxls.cpp -lxls -I /usr/local/include/xlslib/ -I /usr/local/include/ -L /usr/local/lib/ -o helloxls
參考文檔:http://ju.outofmemory.cn/entry/106483
聲明:此博客都是參考別人的,為了自己方便使用,總結了一下!謝謝各位博主
http://www.bkjia.com/Linuxjc/1195497.htmlwww.bkjia.comtrue