Results 1 to 6 of 6

Thread: Where is documentation for excel manipulating commands?

  1. #1
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Where is documentation for excel manipulating commands?

    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 

  2. #2
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Where is documentation for excel manipulating commands?

    I have found some Object Model manual on the site of MS, but it is quite hard to find out the use cases in Qt...
    http://office.microsoft.com/en-us/ex...080550097.aspx

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Where is documentation for excel manipulating commands?

    At a guess* this:
    Qt Code:
    1. QAxObject *chart = worksheet->querySubObject("ChartObjects.Add(int, int, int, int)", 200,200,200,200);
    To copy to clipboard, switch view to plain text mode 
    should be this:
    Qt Code:
    1. QAxObject *charts = worksheet->querySubObject("ChartObjects");
    2. QAxObject *newChart = charts->dynamicCall("Add(int, int, int, int)", 200,200,200,200);
    To copy to clipboard, switch view to plain text mode 

    I have used dumpcpp (it's in the docs) to get a more natural set of C++ proxy classes for the ActiveX objects. Never done it with Excel though.

    * I mean it.

  4. The following user says thank you to ChrisW67 for this useful post:

    falconium (25th April 2011)

  5. #4
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Where is documentation for excel manipulating commands?

    Yes, I have figured it out so far... but I'm wasting a lot of time despite having the excel object model doc since almost everything seems to be special.

    QAxObject *chart = worksheet->querySubObject("ChartObjects()");
    chart->dynamicCall("Add(long, long, long, long)", 200, 200, 200, 200);
    chart->dynamicCall("Select()");
    chart->setProperty("ChartType(long)", "xlXYScatterLines"); // 74?
    QAxObject *charttitle = chart->querySubObject("ChartTitle()");
    charttitle->setProperty("Text(const QString&)", "X");

    Now I'm stucked at the indicated lines... ehh, let's see this dumpcpp. Thanks!
    Last edited by falconium; 25th April 2011 at 03:53.

  6. #5
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Where is documentation for excel manipulating commands?

    OK, now I have extracted the header and source files of excel by dumpcpp and have found the following in them:

    Qt Code:
    1. inline Excel::XlChartType ChartType() const; //Returns the value of ChartType
    2. inline void SetChartType(Excel::XlChartType value); //Sets the value of the ChartType property
    To copy to clipboard, switch view to plain text mode 
    So, I suppose I would have to use the SetChartType command instead of the interrogation, but it doesn't work when I specify either 'long' or 'XlChartType' as parameters.

    Qt Code:
    1. QAxObject *chart = worksheet->querySubObject("ChartObjects()");
    2. chart->dynamicCall("Add(long, long, long, long)", 200, 200, 200, 200);
    3. chart->setProperty("SetChartType( /*what comes here?*/ )", /*what comes here?*/ );
    To copy to clipboard, switch view to plain text mode 

    What should I use here?

    Thanks!

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Where is documentation for excel manipulating commands?

    You should use the proxy classes that dumpcpp has created for you and not dynamicCall() and setProperty(). In the generated header you should find classes for the Excel Application, Workbooks, Workbook, ChartObjects etc. Each of these should have its properties and methods exposed with standard C++ methods. All of this will be, by default anyway, wrapped in a namespace Excel. So you code becomes much more natural, for example:
    Qt Code:
    1. // Include the generated proxy classed definitions
    2. #include "excel.h"
    3.  
    4. Excel::Application * excel = new Excel::Application(this);
    5. Excel::Worksheets *sheets = excel->WorkSheets();
    6. qDebug() << sheets->Count();
    7. etc...
    To copy to clipboard, switch view to plain text mode 

    You will probably need the Microsoft Office type library (MSO.DLL) dumped to be able to build the Excel files.

Similar Threads

  1. Manipulating member name to be controlled by string
    By jwflammer in forum Qt Programming
    Replies: 3
    Last Post: 28th February 2011, 02:19
  2. manipulating qmainwindow widget through qdialog
    By xeroblast in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2010, 07:17
  3. Manipulating excel files in Qt?
    By icttrack in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2010, 11:44
  4. Replies: 1
    Last Post: 7th July 2007, 08:41
  5. Adding Qt's documentation to Xcode documentation browser
    By fabietto in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2007, 15:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.