我想将一些电话号码写入 excel 文件,其中一些以 0 开头(如 02167820096)。我尝试将该列的 NumberFormatLocal 属性设置为字符串类型:
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文件时,其中的所有单元格都被标记为通用类型,代码根本不起作用!
帮助!谢谢...