找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3265|回复: 1
打印 上一主题 下一主题
收起左侧

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. }
复制代码





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:232829 发表于 2017-9-13 10:53 | 只看该作者
没有用过不知道好不好用。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表