xlsxdocument::write() fails with NaN
Julieng031 opened this issue · comments
Julieng031 commented
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!
Jay Two commented
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?
Julieng031 commented
Done. Hope it is the correct way to do it!