QtExcel / QXlsx

Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.

Home Page:https://qtexcel.github.io/QXlsx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xlsxdocument::write() fails with NaN

Julieng031 opened this issue · comments

Hello,

I recently found this library. Thanks, it is really useful!

When using "xlsxdocument::write()" with double format having "NaN" value, it generates an error opening the file in Excel. I share my "simple" workaround:

bool Worksheet::writeNumeric(int row, int column, double value, const Format &format)
{
    // NaN workaround
    if(std::isnan(value))
        return writeBlank(row, column, format);
    else {
        Q_D(Worksheet);
        if (d->checkDimensions(row, column))
            return false;

        Format fmt = format.isValid() ? format : d->cellFormat(row, column);
        d->workbook->styles()->addXfFormat(fmt);
        d->cellTable[row][column] = QSharedPointer<Cell>(new Cell(value, Cell::NumberType, fmt, this));
        return true;
    }
}

Note that in my project, I need to return a blank cell but could be replaced by Excel "#N/A". Hope it helps!

Dear @Julieng031

Sorry for the late reply.
I created a repository for testing. https://github.com/JayTwoLab/qxlsx-issues-154
Can you make a pull request for testing?

Done. Hope it is the correct way to do it!