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