标题:
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。非常方便。
0.png
(41.9 KB, 下载次数: 68)
下载附件
2017-9-1 15:43 上传
所有资料51hei提供下载:
libxl-3.1(破解版).rar
(3.27 MB, 下载次数: 15)
2017-9-1 12:22 上传
点击文件名下载附件
下载积分: 黑币 -5
源程序如下:
#include <iostream>
#include <libxl.h>
#include <Windows.h>
using namespace std;
using namespace libxl;
//中文的内容读出来后要进行编码的转换,这个为转换函数:wchar_t to char
char *w2c(char *pcstr,const wchar_t *pwstr, size_t len)
{
int nlength=wcslen(pwstr);
//获取转换后的长度
int nbytes = WideCharToMultiByte( 0, 0, pwstr, nlength, NULL,0,NULL, NULL );
if(nbytes>len) nbytes=len;
// 通过以上得到的结果,转换unicode 字符为ascii 字符
WideCharToMultiByte( 0,0, pwstr, nlength, pcstr, nbytes, NULL, NULL );
return pcstr ;
}
int main(int argc, char* argv[])
{
Book* book = xlCreateXMLBook();
if(book->load(L"1.xlsx")){
Sheet * sheet = book->getSheet(0);
if(sheet){
CellType celltype = sheet->cellType(1,1);
cout<<"the type is:"<<celltype<<endl;
const wchar_t * t = sheet->readStr(1,1);
char *pcstr = (char *)malloc(sizeof(char)*(2 * wcslen(t)+1));
memset(pcstr , 0 , 2 * wcslen(t)+1 );
w2c(pcstr,t,2 * wcslen(t)+1) ;
cout<<"result:"<<pcstr<<endl;
free(pcstr);
}
}
system("pause");
return 0;
}
复制代码
作者:
xinqinglhj
时间:
2017-9-13 10:53
没有用过不知道好不好用。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1