Hi i am trying to process an excel files using the library Libxl in C++. I am using Ubuntu 18.04. I managed to reproduce the error and so am attaching the code and also the excel sample file. You can run the code and see if the exception is thrown. Also i am attaching the screenshot of the output where you can see that the exception is thrown.
Code inside main.cpp
Book* book = xlCreateXMLBook();
if(book){
if(book->load("file2.xlsx")){
Sheet *sheet = book->getSheet(0);
if(sheet){
for(int row = sheet->firstRow(); row < sheet->lastRow(); ++row)
{
for(int col = sheet->firstCol(); col < sheet->lastCol(); ++col)
{
CellType cellType = sheet->cellType(row, col);
if(sheet->isFormula(row, col))
{
//do something here
}
else
{
if(cellType == CELLTYPE_EMPTY)
{
;
}
else if(cellType == CELLTYPE_NUMBER)
{
;
}
else if(cellType == CELLTYPE_STRING)
{
std::cout<<"This is the string: "<<(sheet->readStr(row,col))<<" "<<std::endl;
/*
const std::string s = sheet->readStr(row,col); //this cause the program to terminate by logic error
*/
}
}}
}
}
}}
You can just copy paste the code and try for yourself and see if it gives you the same exception.
Sample excel file
The excel file can be downloaded from the following link: file2.xlsx
The screenshot of the output of the above code on the above sample file2.xlsx is shown below:
Also note that in the above code sample i have commented out the part const std::string s =sheet->readStr(row,col);
which gives the actual logic error. You can see that error comes at around row 25 or row 26. I have tried the program with different files and i encounter this same problem with every file. The only difference is sometimes the error comes at row 25 and sometimes it comes at row 30 . This seems to be a random error. How can i resolve this? I know sheet->readStr(row,col)
gives std::nullptr but the question is why is it returning std::nullptr? That cell has a string value as can be seen in the excel sheet but still readStr() is returning std::nullptr.
Aucun commentaire:
Enregistrer un commentaire