zoukankan      html  css  js  c++  java
  • linux 上使用libxls读和使用xlslib写excel的方法简介

    读取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 下安装web开发环境
    Nginx服务器之 Nginx的基本配置
    Nginx服务器之基础学习
    java反射 之 反射基础
    java IO流 之 其他流
    java IO流 之 字符流
    java IO流 之 字节流
    java 线程 Lock 锁使用Condition实现线程的等待(await)与通知(signal)
    java线程 公平锁 ReentrantLock(boolean fair)
    MarkdownPad 2破解
  • 原文地址:https://www.cnblogs.com/sancong/p/6439614.html
Copyright © 2011-2022 走看看