1
我想寫一些電話號碼excel文件,其中一些從0開始(如02167820096)。 我嘗試在列的NumberFormatLocal屬性設置爲字符串類型:如何通過Qt設置excel列格式?
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();
輸出是
col 1 NumberFormatLocal: "G/通用格式"
col 1 NumberFormatLocal: "@"
,我可以看到在第一列的單元格確實被設置爲字符串類型(「@ 「)。
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();
和輸出
NumberFormatLocal: "@"
NumberFormat: "@"
,但是當我打開保存Excel文件時,它被標記爲普通型的所有單元格,代碼沒有在所有的工作!
幫助!謝謝...
對不起,現在沒關係。 – areslp
我也試過這樣:範圍 - > dynamicCall( 「SetNumberFormatLocal(常量的QVariant&)」 的QVariant( 「@」));但它不工作,要麼...... – areslp
'範圍 - >清除();'你爲什麼清晰的範圍? – Lol4t0