QXlsx icon indicating copy to clipboard operation
QXlsx copied to clipboard

Forcing Excel to treat a number as a string

Open PMime opened this issue 4 years ago • 3 comments

I filled an Excel table via QXlsx with numbers that should in any case be treated as strings. In Excel the affected cells show a green triangle which says that the content is actually a number.

image

In Excel I found an option which suppresses the warnings. But I am searching for a solution within QXlsx. Thanks for your support.

PMime avatar May 26 '20 12:05 PMime

Dear @PMime Can I see the example code you wrote?

j2doll avatar May 28 '20 12:05 j2doll

The following method transfers a CString variable (from MFC) to a QVariant/QString method. It can be a house number, for example 12 but also 12a.

void AddValue(CString strValue) {
    AddValue(QVariant(QString::fromLocal8Bit(strValue)));
}

The next method handles different types of QVariant. Every column has a different type. -1 means that the type is automatically chosen.

void AddValue(QVariant oValue)
{
    ...
    else if (m_oTypeList.at(m_iCurrentColumn - 1) == -1)
    {
        m_oDocument.write(m_iRowCount, m_iCurrentColumn, oValue, oFormat);
    }
    ...
}

The result is the table shown above. The column Hausnummer (house number) identifies the CString as a number which should not be (as there are also house numbers like 12a).

PMime avatar May 31 '20 16:05 PMime

  • I don't know MFC. I think youI should ask someone who knows MFC well.

  • What would be the result of putting the following debugging code?

m_oDocument.write(m_iRowCount, m_iCurrentColumn, oValue, oFormat);
  
qDebug()
 << oValue
 << doc.cellAt( m_iRowCount, m_iCurrentColumn )->value().type();

The published data is so small that no one seems to be able to debug it.

j2doll avatar Jun 02 '20 12:06 j2doll