标题: libxl-3.1.0下载 可操作excel,不依赖excel安装环境 [打印本页]

作者: wangfans    时间: 2017-9-1 12:22
标题: libxl-3.1.0下载 可操作excel,不依赖excel安装环境
我们常用ole方式操作excel,需要安装excel,并且如果访问越界会runtime error。
采用libxl操作excel,不依赖excel安装环境。直接读取excel,并且不会出现runtime error。非常方便。


所有资料51hei提供下载:
libxl-3.1(破解版).rar (3.27 MB, 下载次数: 15)



源程序如下:
  1. #include <iostream>
  2. #include <libxl.h>
  3. #include <Windows.h>

  4. using namespace std;
  5. using namespace libxl;

  6. //中文的内容读出来后要进行编码的转换,这个为转换函数:wchar_t to char
  7. char *w2c(char *pcstr,const wchar_t *pwstr, size_t len)

  8. {
  9.         int nlength=wcslen(pwstr);
  10.         //获取转换后的长度
  11.         int nbytes = WideCharToMultiByte( 0, 0, pwstr, nlength, NULL,0,NULL, NULL );
  12.         if(nbytes>len)   nbytes=len;
  13.         // 通过以上得到的结果,转换unicode 字符为ascii 字符
  14.         WideCharToMultiByte( 0,0, pwstr, nlength,   pcstr, nbytes, NULL,   NULL );
  15.         return pcstr ;
  16. }

  17. int main(int argc, char* argv[])
  18. {
  19.         Book* book = xlCreateXMLBook();
  20.         if(book->load(L"1.xlsx")){
  21.                 Sheet * sheet = book->getSheet(0);
  22.                 if(sheet){
  23.                         CellType celltype = sheet->cellType(1,1);
  24.                         cout<<"the type is:"<<celltype<<endl;

  25.             const wchar_t * t = sheet->readStr(1,1);
  26.                         char *pcstr = (char *)malloc(sizeof(char)*(2 * wcslen(t)+1));
  27.                         memset(pcstr , 0 , 2 * wcslen(t)+1 );
  28.                         w2c(pcstr,t,2 * wcslen(t)+1) ;
  29.                         cout<<"result:"<<pcstr<<endl;
  30.                         free(pcstr);
  31.                 }
  32.         }
  33.         system("pause");
  34.         return 0;
  35. }
复制代码






作者: xinqinglhj    时间: 2017-9-13 10:53
没有用过不知道好不好用。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1