我正在使用QAxObject
并且能够打开现有文件&阅读不同的床单和细胞
但是当我使用QAxObject
创建新的Excel文件时。它正在创建test_1.xls
文件。
但是,当我打开这个文件时,它给了我错误。我正在使用ms-excel-2007
。
代码:---
QAxWidget excel_1("Excel.Application");
excel_1.setProperty("Visible", false);
QAxObject * workbooks_1 = excel_1.querySubObject("WorkBooks");
workbooks_1->dynamicCall("Add");
QAxObject * workbook_1 = excel_1.querySubObject("ActiveWorkBook");
QAxObject * worksheets = workbook_1->querySubObject("WorkSheets");
excel_1.setProperty("DisplayAlerts", 0);
workbook_1->dynamicCall("SaveAs (const QString&)", QString("D:\\Temp\\test_1.xls"));
workbook_1->dynamicCall("Close (Boolean)", false);
excel_1.setProperty("DisplayAlerts", 1);
excel_1.dynamicCall("Quit (void)");
error message
当我尝试打开此文件时:-----
The file you are trying to open is diffrent format than xls.
Verify that file is corrupted or not do you want to open this file or not
请以正确的格式建议我创建.xls
文件时缺少的内容?
答案 0 :(得分:1)
所以解决方法是,使用“SaveAs”将excel保存为2003格式。
How to set excel column format though Qt?
QList<QVariant> lstParam;
lstParam.append("D:\\Temp\\test_1.xls");
lstParam.append(-4143);
lstParam.append("");
lstParam.append("");
lstParam.append(false);
lstParam.append(false);
lstParam.append(1);
lstParam.append(2);
lstParam.append(false);
lstParam.append(false);
lstParam.append(false);
lstParam.append(false);
workbook_1->dynamicCall("SaveAs(QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant)", lstParam);