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


读取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

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

 

相关内容