错误报告:libxlc++;无法处理某些单元格,引发逻辑错误,基本字符串::\M\u构造null无效 我试图用C++中的库LIXL处理Excel文件。我正在使用Ubuntu 18.04。我设法重现了错误,因此附上了代码和excel示例文件。您可以运行代码并查看是否引发异常。我还附上了输出的屏幕截图,您可以看到异常被抛出

错误报告:libxlc++;无法处理某些单元格,引发逻辑错误,基本字符串::\M\u构造null无效 我试图用C++中的库LIXL处理Excel文件。我正在使用Ubuntu 18.04。我设法重现了错误,因此附上了代码和excel示例文件。您可以运行代码并查看是否引发异常。我还附上了输出的屏幕截图,您可以看到异常被抛出,c++,c++11,nullpointerexception,libxl,logic-error,C++,C++11,Nullpointerexception,Libxl,Logic Error,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)

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
                      */
                   }
      
            }}
     }
}
}}

Book*Book=xlCreateXMLBook();
如果(书){
if(book->load(“file2.xlsx”)){
工作表*Sheet=book->getSheet(0);
若有(第页){
对于(int row=sheet->firstRow();rowlastRow();++row)
{
对于(int col=sheet->firstCol();collastCol();++col)
{
CellType CellType=表格->单元格类型(行、列);
if(表格->公式(行、列))
{
//在这里做点什么
}
其他的
{
if(cellType==cellType\u EMPTY)
{
;
}
else if(cellType==cellType\u编号)
{
;
}
else if(cellType==cellType\u字符串)
{

std::cout
sheet->readStr(row,col)
将返回
std::nullptr
,这对于构造
std::string
无效。请参见此处的示例(测试
NULL
),我知道
sheet->readStr(row,col)
给出了std::nullptr,但问题是它为什么返回std::nullptr?该单元格有一个字符串值,可以在excel文件中看到,但readStr()仍返回std::nullptr。“返回NULL…发生错误。使用
xlBookErrorMessage()
获取错误信息。”我尝试过,但是它给出了同样的逻辑错误。你能把代码写成答案,这样我就可以看到它是如何解决或帮助调试这个问题的?你也给出了C版本。但是C++版本是“代码>书:Error MexAug();< /Cord> @ EmployedRussian。你能明白为什么会出现这个问题吗?