码迷,mamicode.com
首页 > 系统相关 > 详细

linux 上使用libxls读和使用xlslib写excel的方法简介

时间:2017-11-10 18:43:32      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:except   方便   配置   make   load   dex   space   read   getchar   

读取excel文件:libxls-1.4.0.zip
下载地址:http://sourceforge.net/projects/libxls/
安装方法:
  ./configure
  make
  make install

//示例:

建立文件readXls.cpp, 代码如下:

#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;
}

编译:g++ readXls.cpp -o readXls -I/usr/local/libxls/include -L/usr/local/libxls/lib -lxlsreader

如果运行时出现:error while loading shared libraries: libxxx.so.1: cannot open shared 

这表示:系统不知道xxx.so放在哪个目录下,这时候就要在/etc/ld.so.conf中加入xxx.so所在的目录

解决方法:

  1.在/etc/ld.so.conf中加入【动态库所在路劲】,保存之后,再运行:/sbin/ldconfig –v更新一下配置即可。如libxls的动态库路径是 /usr/local/libxsl/lib
  2.在/etc/ld.so.conf.d/下新建一个.conf文件,并在其中加入【动态库所在路劲】就可以了,在运行/sbin/ldconfig。

 

参考文档:

   http://blog.csdn.net/yao_guet/article/details/7326065

  http://blog.csdn.net/zhangqiu1989/article/details/8822853

api文档可参考:

  http://www.codeweblog.com/libxls%E4%BD%BF%E7%94%A8/

/////////////////////////////////////////////////////////
生成excel文件:xlslib-package-2.5.0.zip
下载地址:http://sourceforge.net/projects/xlslib/
安装方法:
  ./configure
  make
  make install

示例:

建立文件writeXls.cpp,写入如下代码:
#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++ writeXls.cpp -lxls -I /usr/local/include/xlslib/ -I /usr/local/include/ -L /usr/local/lib/ -o writeXls

参考文档:http://ju.outofmemory.cn/entry/106483

声明:此博客都是参考别人的,为了自己方便使用,总结了一下!谢谢各位博主

linux 上使用libxls读和使用xlslib写excel的方法简介

标签:except   方便   配置   make   load   dex   space   read   getchar   

原文地址:http://www.cnblogs.com/lvdongjie/p/7815510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!