Read Excel file: Libxls-1.4.0.zip
: http://sourceforge.net/projects/libxls/
Installation method:
./configure
Make
Make install
Example:
Create a file readXls.cpp with the following code:
#include <stdexcept>
#include <xls.h>
#include <iostream>
using namespace xls;
using namespace Std;
/////////////////////////////////////////////////
int main (int argc, char **argv)
{
if (ARGC < 2)
{
Cerr << "Please input the Excel file." << Endl;
return 1;
}
xlsworkbook* Pworkbook = Xls_open (argv[1], "UTF-8");
if (NULL = = Pworkbook)
{
Cerr << "file is not Excel" << Endl;
return 1;
}
xlsworksheet* Pworksheet = Xls_getworksheet (pworkbook, 0);
Xls_parseworksheet (Pworksheet);
for (int r=0; r<=pworksheet->rows.lastrow; r++)
{
xlsrow* row = &pWorkSheet->rows.row[r];
for (int c=0; c<pworksheet->rows.lastcol; C + +)
{
byte* Pcurcellinfo = row->cells.cell[c].str;
if (NULL! = pcurcellinfo)
{
cout << Pcurcellinfo;
GetChar ();
}
}
cout << Endl;
}
Xls_close_ws (Pworksheet);
XLS_CLOSE_WB (Pworkbook);
return 0;
}
Compilation: g++ Readxls.cpp-o Readxls-i/usr/local/libxls/include-l/usr/local/libxls/lib-lxlsreader
If the runtime appears: Error while loading shared Libraries:libxxx.so.1:cannot open shared
This means: The system does not know xxx.so in which directory, this time will be in the/etc/ld.so.conf to add xxx.so directory
Workaround:
1. In/etc/ld.so.conf, add "Dynamic Library in the road", save, then run:/sbin/ldconfig–v update the configuration. The dynamic library path, such as Libxls, is/usr/local/libxsl/lib
2. Create a new. conf file under/etc/ld.so.conf.d/and add "Dynamic Library on the road" on it, running/sbin/ldconfig.
Reference Documentation:
http://blog.csdn.net/yao_guet/article/details/7326065
http://blog.csdn.net/zhangqiu1989/article/details/8822853
The API documentation can be consulted:
http://www.codeweblog.com/libxls%E4%BD%BF%E7%94%A8/
/////////////////////////////////////////////////////////
Generate Excel File: Xlslib-package-2.5.0.zip
: http://sourceforge.net/projects/xlslib/
Installation method:
./configure
Make
Make install
Example:
Create the file WriteXls.cpp and write the following code:
#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); Starting at 0, line 1th, column 2nd, C3
Wb. Dump ("Workbook.xls");
return 0;
}
Compile:
g++ writexls.cpp-lxls-i/usr/local/include/xlslib/-i/usr/local/include/-l/usr/local/lib/-o writeXls
Reference Document: http://ju.outofmemory.cn/entry/106483
Statement: This blog is to refer to others, for their own convenience to use, summed up a bit! Thank you, bloggers.
Introduction to the method of using Libxls to read and write Excel using Xlslib on Linux