我正在使用Libxl for c++来读取.xlsx文件。代码如下
void main()
{
Book* book = xlCreateXMLBook();
if (book) {
if(book->load("input.xlsx")) {
Sheet* sheet = book->getSheet(0);
if (sheet) {
long int id;
for(int i=1; i<15; i++) {
id = sheet->readNum(i,0);
cout << id << endl;
}
}
}
}
book->release();
}excel工作表具有以下数据,并且输出似乎不同。
Original Data | Output from code
UNKNOWN | 0
47012 | 141366
48964 | 154840
425214 | 0
47018 | 134427任何帮助都是非常感谢的。
发布于 2013-08-20 12:44:35
readNum返回一个双精度型而不是长整型
我假设“未知”是一个字符串。如果是这样的话,你可以这样做:
double id;
const wchar_t* str;
for(int i=1; i<15; i++) {
str = sheet->readStr(i, 0);
if (str) {
wcout << str << endl; // need to use wcout as it's a wide string
} else {
id = sheet->readNum(i,0);
cout << id << endl;
}
}根据文档,如果单元格不包含字符串,则readStr将返回NULL,因此您可以重新读取数字。
https://stackoverflow.com/questions/17026253
复制相似问题