LibXL随机(但始终)无法从. xls中读取字符串或数字
LibXL randomly (but consistantly) fails to read a string or number from a .XLS
事情是这样的:
我开发这个程序已经有一段时间了。它的功能是从各种xls文件中搜索、读取和组织数据。除了一件事之外,所有的东西都可以编译并正常工作:由于某些原因,有时libXL只是将不读取字符串或整数该.xls文件的单元格。我说随机是因为它看起来是随机的,但是每次我运行程序,它总是失败的相同的文件在相同的细胞。
我知道这一点,因为我操纵了代码,以便在读取字符串或数字失败时通知我("errortype::invalid_string", "errortype::num==0")
这个程序是用c++, windows 7, Visual Studio Express 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;}
如果有人对为什么会发生这种情况有一些见解,我将不胜感激。如果您需要更多的信息来解决这个问题,我很乐意提供。
我不确定您使用的是哪个版本的DLL。
对于整数读取问题,您可以尝试
double num = y->readNum(x.row, x.col);
看来我以前也遇到过同样的问题。
类似的尝试改变字符串类型
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++将文本文件中的数据读取到结构数组中
- 正在将csv文件读取为双精度矢量
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 为什么在读取文件大小时文件IO速度会发生变化
- 正在读取二进制文件(is_open)
- 如何在c++中从文本文件中逐行读取整数
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 独立读取-修改-写入顺序
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组
- 如何在linux中使用cpp读取.xls文件
- LibXL随机(但始终)无法从. xls中读取字符串或数字