LibXL随机(但始终)无法从. 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);

看来我以前也遇到过同样的问题。

类似的尝试改变字符串类型

最新更新