linux 上使用libxls讀和使用xlslib寫excel的方法簡介,libxlsxlslib

來源:互聯網
上載者:User

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

聲明:此部落格都是參考別人的,為了自己方便使用,總結了一下!謝謝各位博主

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.