For example, the following gives you the object of active sheet:
QAxObject *excelWorkSheet = pexcel->querySubObject("ActiveSheet");

But, where can I find the list of commands that I can give to excel objects?
I tried to find Excel COM docs, but they were for VB and totally confusing.
My aim is to create a chart from a table.
Qt Code:
  1. QAxObject* excel = new QAxObject("Excel.Application", 0);
  2. if (!excel)
  3. {
  4. QMessageBox::critical(this,
  5. "Error while creating excel object!",
  6. "No excel object can be instantiated!\n"
  7. "Please, check if you have MS Excel installed.");
  8. log("Excel object cannot be created (is not Excel installed?)!", 1);
  9. return;
  10. }
  11. //QAxObject* application = excel->querySubObject("Application()");
  12. QAxObject* workbooks = excel->querySubObject("Workbooks()");
  13. if (!workbooks)
  14. {
  15. QMessageBox::critical(this,
  16. "Error while creating excel object!",
  17. "No excel object can be instantiated!\n"
  18. "Workbooks in Excel document can be found.");
  19. log("Excel object cannot be created (is not Excel installed?)!", 1);
  20. return;
  21. }
  22. QAxObject* workbook = workbooks->querySubObject("Add()");
  23. QAxObject* worksheet = workbook->querySubObject("Worksheets(int)", 1 );
  24. ChartView* active = activeMdiChild();
  25. if (!active)
  26. {
  27. log("There is no activated chart window!", 1);
  28. return;
  29. }
  30. QStandardItemModel *model = active->getModel();
  31. if (!model)
  32. {
  33. log("There is no data in chart window!", 1);
  34. return;
  35. }
  36. for (int x=1; x<model->columnCount()+1; x++)
  37. {
  38. QAxObject *range = worksheet->querySubObject("Range(QString)",
  39. getExcelColumnName(x) + "1" +
  40. ":" +
  41. getExcelColumnName(x) + "1"
  42. );
  43. range->setProperty("Value", model->horizontalHeaderItem(x-1)->text());
  44. delete range;
  45. }
  46. for (int y=1; y<model->rowCount()+1; y++)
  47. for (int x=1; x<model->columnCount()+1; x++)
  48. {
  49. QAxObject *range = worksheet->querySubObject("Range(QString)",
  50. getExcelColumnName(x) + QString("%1").arg(y+1) +
  51. ":" +
  52. getExcelColumnName(x) + QString("%1").arg(y+1)
  53. );
  54. range->setProperty("Value", model->item(y-1, x-1)->data(Qt::EditRole));
  55. delete range;
  56. }
To copy to clipboard, switch view to plain text mode 
QAxObject *chart = worksheet->querySubObject("ChartObjects.Add(int, int, int, int)", 200,200,200,200);

Qt Code:
  1. workbook->dynamicCall("SaveAs (const QString&)", fileName);
  2. workbook->dynamicCall("Close()");
  3. excel->dynamicCall("Quit()");
To copy to clipboard, switch view to plain text mode