LibXL randomly (but consistantly) fails to read a string or number from a .XLS

786 Views Asked by At

Okay, here's the thing:

I've been developing this program for quite a while now. Its function is to search, read, and organize data from various xls files.

Everything compiles and works for the most part except for one thing: For some reason, sometimes libXL just WILL NOT read a string or integer from a cell for that .xls file. And I say randomly because it only appears random, but EVERYTIME I run the program, it consistently fails for the same files at the same cells.

I know this because I've rigged the code to inform me when it failed to read the string or the number ("errortype::invalid_string", "errortype::num==0")

This program is written in c++, windows 7, Visual Studio Express 2013

Here's a code snippet from my getval() function

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;}

If anyone has some insight as to why this might be happening, it's much appreciated. If you require more information to solve the problem, I'll gladly provide it.

1

There are 1 best solutions below

0
On

I am not sure which version of the DLL you are using.

For the integer reading problem, you may try

double num = y->readNum(x.row, x.col);

Seems I experienced the same problem before.

Similar trial to change the string type.