好吧,问题是:
我开发这个程序已经有一段时间了。它的功能是搜索、读取和组织各种xls文件中的数据。
除了一件事外,所有的东西都是编译和工作的:出于某种原因,有时libXL --仅仅是--不会从.xls文件的单元格中读取字符串或整数。我说它是随机的,因为它只显示为随机的,但是每次我运行程序时,它总是在相同的单元格上对相同的文件失败。
我之所以知道这一点,是因为我操纵了代码,以便在它无法读取字符串或数字("errortype::invalid_string“、"errortype::num==0")时通知我。
此程序是用c++,windows 7,Visual 2013编写的
下面是来自getval()函数的代码片段
std::string getval(cell x, libxl::Sheet* y){
std::string header= "none";
if (y->cellType(x.row, x.col) == libxl::CELLTYPE_EMPTY)
header = "none";
else if (y->cellType(x.row, x.col) == libxl::CELLTYPE_BLANK)
header = "none";
else if (y->cellType(x.row, x.col) == libxl::CELLTYPE_STRING){
if (info_level > 2)std::cout << "\n" << "Getting value from cell: (" << x.row << ", " << x.col << ")";
const wchar_t* s = y->readStr(x.row, x.col);
if (s){
std::wstring w = std::wstring(s);
header = std::string(w.begin(), w.end());
}
else
header = "errortype::invalid_string";
}
else if (y->cellType(x.row, x.col) == libxl::CELLTYPE_NUMBER){
long long num = 0;
num = y->readNum(x.row, x.col);
//int res = int(num);
if (num != 0){
std::stringstream ss;
ss << num;
header = ss.str();
}
else
header = "errortype::num==0";
}
else if (y->cellType(x.row, x.col) == libxl::CELLTYPE_BOOLEAN)
header = "errortype::celltype_bool";
else if (y->cellType(x.row, x.col) == libxl::CELLTYPE_ERROR)
header = "errortype::celltype_error";
return header;}如果有人对这种情况可能发生的原因有一定的洞察力,那是非常感谢的。如果你需要更多的信息来解决这个问题,我很乐意提供。
发布于 2015-08-11 11:15:40
我不确定您使用的DLL的哪个版本。
对于整数读取问题,您可以尝试
double num = y->readNum(x.row, x.col);好像我以前也经历过同样的问题。
类似的尝试来更改字符串类型。
https://stackoverflow.com/questions/31572924
复制相似问题