QtExcel / QXlsx

Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.
https://qtexcel.github.io/QXlsx/
MIT License
1.16k stars 358 forks source link

Cell is incorrectly interpreted as DateTime #190

Closed celoewe1971 closed 1 year ago

celoewe1971 commented 3 years ago

Hi,

First of all: Great work 👍

Now to what I have found: In the attached test file, the two cells A2 and A3 are interpreted as DateTime. This is wrong. The values are clearly numbers. The reason is the custom formatting of the cell as you can see in the screenshot (german excel).

NumFormatParser::isDateTime(const QString &formatCode) causes the error. The formatCode is checked for 'd' and 'm' with regard to the date. Shouldn't false be returned if '#' is part of it ?

screenshot test.xlsx ,

j2doll commented 1 year ago

Dear @celoewe1971

Thanks for the great analysis.

Can you show me some example code?

celoewe1971 commented 1 year ago

Hello @j2doll

example code for what ? The current code ist not working correct when you use text.xlsx. So I think the code fragment should be like

... // date/time can only be positive number, // so only the first section of the format make sense. case '#': // this is new an working case ';': return false; ...

j2doll commented 1 year ago

This has been reflected. https://github.com/QtExcel/QXlsx/commit/d0f846a31ed45b2c0c25ff829ffe7e8dcfb9c503

Please test it out and post the results.

celoewe1971 commented 1 year ago

Works fine. Following test code displays the correct 100 (not a wrong datetime with the 'old' code)

using namespace QXlsx;

Document xlsx("Test.xlsx");
if (xlsx.load()) 
{
   int row = 2; int col = 1;
   Cell* cell = xlsx.cellAt(row, col); // get cell pointer.
   if ( cell != NULL )
   {
      QVariant var = cell->readValue(); 
      qDebug() << var; // display value.
   }
}
j2doll commented 1 year ago

Works fine. Following test code displays the correct 100 (not a wrong datetime with the 'old' code)

using namespace QXlsx;

Document xlsx("Test.xlsx");
if (xlsx.load()) 
{
   int row = 2; int col = 1;
   Cell* cell = xlsx.cellAt(row, col); // get cell pointer.
   if ( cell != NULL )
   {
      QVariant var = cell->readValue(); 
      qDebug() << var; // display value.
   }
}

Thanks for the great help. 👍