I want to write some tel numbers to excel file, some of them start with 0(like 02167820096). I try to set the NumberFormatLocal property of that column to string type:
QAxObject* col=worksheet->querySubObject("Columns(int)",1);
if (!col)
{
qDebug()<<"col is NULL";
}
qDebug()<<"col 1 NumberFormatLocal:"<<col->property("NumberFormatLocal").toString();
col->setProperty("NumberFormatLocal","@");
qDebug()<<"col 1 NumberFormatLocal:"<<col->property("NumberFormatLocal").toString();
The output is
col 1 NumberFormatLocal: "G/通用格式"
col 1 NumberFormatLocal: "@"
and I can see the cell in 1st column is indeed set to string type("@").
QAxObject * range = worksheet->querySubObject("Cells(int,int)", 1, 1);
if (!range)
{
qDebug()<<"range does not exist";
}
QVariant tel=QString("%1").arg(record["tel"].toString()); //tel is 02167820096
//qDebug()<<tel;
//range->dynamicCall("SetValue(const QVariant&)", tel);
qDebug()<<"NumberFormatLocal:"<<range->property("NumberFormatLocal").toString();
qDebug()<<"NumberFormat:"<<range->property("NumberFormat").toString();
range->setProperty("Value", tel.toString());
range->clear();
and the output is
NumberFormatLocal: "@"
NumberFormat: "@"
but when I open the saved excel file, all cells in it are marked as general type, the code didn't work at all!
Help! Thanks...