2

I am working with QAxObject and able to open existing file & read different sheets & cells.

But when i am creating a new excel file using QAxObject. It is creating the test_1.xls file. But when i open this file it gives me error. I am using ms-excel-2007 .

Code :---

   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 when i try to open this file :-----

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

Please suggest what i am missing to create .xls file in correct format ?

Katoch
  • 2,709
  • 9
  • 51
  • 84

1 Answers1

2

OK,I solved this problem. Because I install Office2007, the "Save" function will save the file in 2007 format, but I save it to "*.xls", some format can not be recognized correctly.

so the solution is, use "SaveAs" to save excel to 2003 format.

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);
Community
  • 1
  • 1
Katoch
  • 2,709
  • 9
  • 51
  • 84