QXlsx
QXlsx copied to clipboard
Forcing Excel to treat a number as a string
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.
In Excel I found an option which suppresses the warnings. But I am searching for a solution within QXlsx. Thanks for your support.
Dear @PMime Can I see the example code you wrote?
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).
-
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.