QXlsx icon indicating copy to clipboard operation
QXlsx copied to clipboard

xlsxdocument::write() fails with NaN

Open Julieng031 opened this issue 4 years ago • 2 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!

Julieng031 avatar Apr 10 '21 15:04 Julieng031

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?

j2doll avatar Apr 15 '21 13:04 j2doll

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

Julieng031 avatar Apr 17 '21 08:04 Julieng031