C++ 读写Excel表格文件 Libxl破解版 支持2007版本 xlsx 中文

网上有几篇关于读写excel文件的文章,大概差不多,这里给个传送门。

其他的几个方式没有试,直接用了Libxl库,所以效率没有进行比较。【后来对BasicExcel库测试了下,发现对于xlsx文件根本就行不通,所以还是用Libxl吧】

百度文库里有个资料对于基本函数的说明不错,给个链接:。

第一:下载破解版,。破解版可以读取超过100行,第一行没有logo。里面包含使用说明,包括头文件和库文件引用方法。

第二:关于Libxl,对于03版本的xls文件,,读写起来中文支持都比较好,不使用unicode编码就可以很好实现,这个例子可以看官网的例子。而对于07版本的xlsx文件,必须使用unicode编码才可以进行。上面给的下载链接里的cpp文件主要是实现了读取xlsx文件中的中文。

#include <iostream>#include <libxl.h>#include <Windows.h>using namespace std;using namespace libxl;//中文的内容读出来后要进行编码的转换,这个为转换函数:wchar_t to charchar *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;}

坚守自己的原则,世界上的诱-惑很多,

C++ 读写Excel表格文件 Libxl破解版 支持2007版本 xlsx 中文

相关文章:

你感兴趣的文章:

标签云: