用法:
然后根据自己的情况添加库
下面说一下key的用法:
如果你用的是vs,就用下图的用法,在setkey后面填写相关信息就行
VS模式
用libxl写
#include "libxl.h"
using namespace libxl;
int main()
{
Book* book = xlCreateXMLBook();
book->setKey(name, key);
if (book)
{
Sheet* sheet = book->addSheet(L"Sheet1");
if (sheet)
{
for (int i = 1; i < 1000; i++)
{
sheet->writeStr(i, 2, L"Hello, World !");
}
}
book->save(L"example.xlsx");
book->release();
}
return 0;
}
用libxl读
#include <iostream>
#include "libxl.h"
#include <iostream>
#include <locale.h>
#include <windows.h>
using namespace libxl;
#pragma comment(lib,"libxl.lib")
using namespace libxl;
using namespace std;
void WcharToString(string& szDst, const wchar_t* wchar)
{
DWORD dwNum = WideCharToMultiByte(CP_OEMCP, NULL, wchar, -1, NULL, 0, NULL, FALSE);
char* psText;
psText = new char[dwNum];
WideCharToMultiByte(CP_OEMCP, NULL, wchar, -1, psText, dwNum, NULL, FALSE);
szDst = psText;
delete[]psText;
}
int main()
{
Book* book = xlCreateXMLBook();
book->setKey(name, key);
if (book)
{
if (book->load(L"example.xlsx"))
{
Sheet* sheet = book->getSheet(0);
if (sheet)
{
for (int i = 1; i < 1000; i++)
{
const wchar_t* chars = sheet->readStr(i, 2);
string str;
WcharToString(str, chars);
std::cout << str <<std::endl;
}
}
}
book->release();
}
return 0;
}
如果你用的是QT,就用下图的用法,在setkey后面填写相关信息就行
QT模式
Book* book = xlCreateXMLBook(); // Book for xlsx
book->setKey(QString(name).toStdWString().c_str(), QString(key).toStdWString().c_str());
包含windows与linux的
懂的都懂
libx4.2.0的库 链接: libxl4.2.0
提取码:0914
需要key的可以联系我