读取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的方法简介的更多相关文章

  1. linux上redis安装配置及其防漏洞配置及其攻击方法

    Linux上redis安装: 需先在服务器上安装yum(虚拟机可使用挂载的方式安装) 安装配置所需要的环境运行指令:  yum -y install gcc 进入解压文件执行make 指令进行编译 执 ...

  2. [转]提高 Linux 上 socket 性能,加速网络应用程序的 4 种方法

    原文链接:http://www.ibm.com/developerworks/cn/linux/l-hisock.html 使用 Sockets API,我们可以开发客户机和服务器应用程序,它们可以在 ...

  3. linux上查找文件存放地点和文件中查找字符串方法

    一.查找文件存放地点 1.locate 语法:locate <filename> locate命令实际是"find -name"的另一种写法,但是查找方式跟find不同 ...

  4. Linux 上的数据可视化工具

    Linux 上的数据可视化工具 5 种开放源码图形化工具简介 Linux® 上用来实现数据的图形可视化的应用程序有很多,从简单的 2-D 绘图到 3-D 制图,再到科学图形编程和图形模拟.幸运的是,这 ...

  5. 在Linux上部署Web项目

    You believe it or not there is a feeling, lifetime all not lost to time. 在Linux上部署Web项目 这个是普通的web项目, ...

  6. Linux上的free命令详解、swap机制

    Linux上的free命令详解   解释一下Linux上free命令的输出. 下面是free的运行结果,一共有4行.为了方便说明,我加上了列号.这样可以把free的输出看成一个二维数组FO(Free ...

  7. PHP在linux上执行外部命令

    PHP在linux上执行外部命令 一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以 ...

  8. Linux上性能异常定位以及性能监控

    引言:大多数的服务都是跑在Linux上的,Linux现在也已经到了一个很广泛的应用,但是仍然会有很多问题出现,我们就来讨论下我们性能监控的指标,性能监控无非就是从I/O,内存,CPU,TCP连接数,网 ...

  9. Linux上的free命令详解

    解释一下Linux上free命令的输出. 下面是free的运行结果,一共有4行.为了方便说明,我加上了列号.这样可以把free的输出看成一个二维数组FO(Free Output).例如: FO[2][ ...

随机推荐

  1. JS预解释

    1.声明(declare)  var num   // 告诉浏览器在全局作用域中有一个num变量 定义(defined) num = 12 // 给我们的比变量进行赋值 2.var:在预解释时只是提前 ...

  2. php打开csv

    <?php $fh=fopen("a.csv","r");//这里我们只是读取数据,所以采用只读打开文件流 $arr=fgetcsv($fh);//这个函 ...

  3. python redis之连接池的原理

    python redis之连接池的原理 转载地址 什么是连接池 通常情况下, 当我们需要做redis操作时, 会创建一个连接, 并基于这个连接进行redis操作, 操作完成后, 释放连接, 一般情况下 ...

  4. 77. Combinations (JAVA)

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  5. 解决deepin没有ll等命令的办法

    编辑~/.bashrc, 添加alias 如下 vim ~/.bashrc 设置别名. 添加如下行 alias ll='ls -alF' alias la='ls -A' alias vi='vim' ...

  6. Zookeeper客户端使用(使用zkclient)

    Zookeeper客户端使用 二.使用zkclient 在pom.xml中加入依赖 <dependency> <groupId>com.101tec</groupId&g ...

  7. Ubuntu下Cmake编译C++程序Helloworld

    1.首选新建工程目录 mkdir helloworld 2.新建文件目录 cd helloworld mkdir bin mkdir lib mkdir src mkdir include mkdir ...

  8. 【串线篇】SpringBoot数据访问【数据源/mybatis/指定映射文件位置】

    一.配置数据源 1.1.jdbc版本 JDBC(.tomcat.jdbc.pool.DataSource作为数据源) <?xml version="1.0" encoding ...

  9. selenium操作下拉选和网页提示框

    import time from selenium import webdriver from selenium.webdriver.support.select import Select#处理下拉 ...

  10. null转为数字的坑

    在项目中,需要用到某个字段等于0时来处理逻辑 if (+item.ext === 0) {} // 前面的+号是转为数字 // 如果item.ext 为 null时, +item.ext 就等于 0 ...