Results 1 to 10 of 10

Thread: ActiveQT + Excel charts

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default ActiveQT + Excel charts

    Goodevening to everybody,
    I should create an excel chart from my QT 4.6 application.
    I'using ActiveQT on Mingw (Win XP SO), and I obtain to write some data to an excel sheet.

    How I can add a Series to the chart now?
    This is my code.
    Qt Code:
    1. QAxObject * excel = new QAxObject("Excel.Application",0);
    2. QAxObject *workbooks = excel->querySubObject( "Workbooks" );
    3. QAxObject *workbook = workbooks->querySubObject( "Add");
    4. QAxObject *sheets = workbook->querySubObject( "Worksheets" );
    5. QAxObject *charts =workbook->querySubObject("Charts");
    6. QAxObject *chart = charts->querySubObject("Add");
    7.  
    8. QAxObject *sheet = sheets->querySubObject( "Item( int )", 1 );
    9. sheet->setProperty("Name","Dati applicazione");
    10.  
    11. QAxObject*cell=sheet->querySubObject("Cells(int,int)",1,1);
    12. cell->dynamicCall("SetValue(String)","Serie");
    13.  
    14. cell=sheet->querySubObject("Cells(int,int)",1,2);
    15. cell->dynamicCall("SetValue(String)","Dati");
    16.  
    17. for (int i=2; i<10; i++){
    18. cell=sheet->querySubObject("Cells(int,int)",i,1);
    19. cell->dynamicCall("SetValue(int)",i-1);
    20. cell=sheet->querySubObject("Cells(int,int)",i,2);
    21. cell->dynamicCall("SetValue(double)",qrand());
    22. }
    23.  
    24. chart->setProperty("Name","Report Grafico dei dati");
    25. chart->setProperty("CharThype",73);
    26.  
    27. QAxObject *series = chart->property("SeriesCollection");
    To copy to clipboard, switch view to plain text mode 
    I got this error:
    QAxBase: Error calling IDispatch member SeriesCollection: Member not found
    Thanks for your time

    Michele

  2. #2
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: ActiveQT + Excel charts

    Hi,

    QAxObject *series = chart->querySubObject("SeriesCollection");

    Then try to use NewSeries.

    Maybe you should try this before in VBA to see how to do it.

    HTH, Bernd

  3. #3
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQT + Excel charts

    hello bst,
    thanks for your reply but... no way
    It got Segmentation Fault and the pointer of debug highlight this code:
    Qt Code:
    1. bool QAxBase::isNull() const
    2. {
    3. return !d->ptr;
    4. }
    To copy to clipboard, switch view to plain text mode 

    so the QAxBase class don't return anything for this code:

    Qt Code:
    1. QAxObject *series = chart->querySubObject("SeriesCollection");
    2. QAxObject *serie = series->querySubObject("NewSeries");
    To copy to clipboard, switch view to plain text mode 

    When I try to exec NewSeries command, it got Segmentation Fault.

    I use VBA on excel several time, it show Object and Collection, in this case a collaction give the problem.

    It is possible to create a "Collection-equivalent" QAxBase object?
    How can I create a new series?
    Where could I show how I should use the Excel methods?

    Thanks for your time

  4. #4
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: ActiveQT + Excel charts

    Hi,

    doesn't work here either. I've no idea why :-(

    What works here is to 'force' Charts.Add to already add a series. This can be done by 'Selecting the source-range' before calling Charts.Add. Here - for one series - it's enough to write into the cells and set XValues and Values later.

    HTH, Bernd
    --
    Qt Code:
    1. #include <QtGui/QtGui>
    2. #include <QAxWidget>
    3. #include <QAxObject>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. QAxWidget *excel = new QAxWidget("Excel.Application", 0);
    10. excel->setProperty("SheetsInNewWorkbook", 1);
    11. // excel->setProperty("Visible", true);
    12. QAxObject *workbooks = excel->querySubObject("Workbooks");
    13. QAxObject *workbook = workbooks->querySubObject("Add");
    14. QAxObject *worksheet = workbook->querySubObject("Worksheets (int)", 1);
    15.  
    16. worksheet->setProperty("Name","Dati applicazione");
    17.  
    18. QAxObject *cell = worksheet->querySubObject("Cells(int,int)", 1, 1);
    19. cell->dynamicCall("SetValue(String)", "Serie");
    20.  
    21. cell = worksheet->querySubObject("Cells(int,int)", 1, 2);
    22. cell->dynamicCall("SetValue(String)", "Dati");
    23.  
    24. for (int i = 2; i < 10; i++){
    25. cell = worksheet->querySubObject("Cells(int,int)", i, 1);
    26. cell->dynamicCall("SetValue(int)", i - 1);
    27. cell = worksheet->querySubObject("Cells(int,int)", i, 2);
    28. cell->dynamicCall("SetValue(double)", qrand());
    29. }
    30.  
    31. QAxObject *charts = workbook->querySubObject("Charts");
    32. QAxObject *chart = charts->querySubObject("Add");
    33. chart->setProperty("Name", "Report Grafico dei dati");
    34. chart->setProperty("ChartType", 73);
    35.  
    36. QAxObject * serie = chart->querySubObject("SeriesCollection(int)", 1);
    37. QAxObject * xvalues = worksheet->querySubObject("Range(A2:A9)");
    38. QAxObject * yvalues = worksheet->querySubObject("Range(B2:B9)");
    39.  
    40. serie->setProperty("XValues", xvalues->asVariant());
    41. serie->setProperty("Values", yvalues->asVariant());
    42.  
    43. workbook->dynamicCall("SaveAs (const QString&)", "E:/test/chartbyqt");
    44. workbook->dynamicCall("Close (Boolean)", false);
    45. excel->dynamicCall("Quit (void)");
    46.  
    47. return 0;
    48. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQT + Excel charts

    mmm interesting!!

    do u think I could use this way for more than one series?
    I should build an excel file, with several sheets: most of these contains (datetime-values) couples, and at the end i should plot all series in a chart.

    Probably this way give me the answer.

    Thanks a lot for your time, I'll try it soon.

    Michele

    PS. I saw other way to connect with OCX object such as VOLE, it divide the Object, from Collection, so the NewSeries command can be used, probabily the answer is concernent this.

  6. #6
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: ActiveQT + Excel charts

    Hi,

    this works here. The 'trick' ist the range->dynamicCall("Select (void)");

    HTH, Bernd
    --
    Qt Code:
    1. #include <QtGui/QtGui>
    2. #include <QAxWidget>
    3. #include <QAxObject>
    4. #include <QDebug>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QAxWidget *excel = new QAxWidget("Excel.Application", 0);
    11. //excel->setProperty("SheetsInNewWorkbook", 3);
    12. //excel->setProperty("Visible", true);
    13. QAxObject *workbook = excel->querySubObject("Workbooks")->querySubObject("Add");
    14. QAxObject *worksheet = workbook->querySubObject("Worksheets(1)");
    15. worksheet->setProperty("Name", "Dati applicazione");
    16. worksheet->querySubObject("Cells(1,1)")->dynamicCall("SetValue", "Serie");
    17. worksheet->querySubObject("Cells(1,2)")->dynamicCall("SetValue", "Dati");
    18.  
    19. QAxObject *cell;
    20. double dval;
    21. for (int i = 2; i < 10; i++){
    22. dval = qrand();
    23. cell = worksheet->querySubObject("Cells(int,int)", i, 1);
    24. cell->dynamicCall("SetValue(int)", i - 1);
    25. cell = worksheet->querySubObject("Cells(int,int)", i, 2);
    26. cell->dynamicCall("SetValue(double)", dval);
    27. cell = worksheet->querySubObject("Cells(int,int)", i, 3);
    28. cell->dynamicCall("SetValue(double)", dval/2);
    29. cell = worksheet->querySubObject("Cells(int,int)", i, 4);
    30. cell->dynamicCall("SetValue(double)", dval/3);
    31. }
    32. // Selecting 3 columns will force charts.add to create 3 series !
    33. QAxObject *range = worksheet->querySubObject("Range(A2:C9)");
    34. range->dynamicCall("Select (void)");
    35.  
    36. QAxObject *chart = workbook->querySubObject("Charts")->querySubObject("Add");
    37. chart->setProperty("Name", "Report Grafico dei dati");
    38. chart->setProperty("ChartType", 73);
    39.  
    40. QAxObject * series = chart->querySubObject("SeriesCollection");
    41. // qDebug() << series->property("Count"); // 3 !
    42.  
    43. QAxObject * serie = series->querySubObject("Item (int)", 1);
    44. QAxObject * xvalues = worksheet->querySubObject("Range(A2:A9)");
    45. QAxObject * yvalues = worksheet->querySubObject("Range(B2:B9)");
    46. serie->setProperty("XValues", xvalues->asVariant());
    47. serie->setProperty("Values", yvalues->asVariant());
    48.  
    49. serie = series->querySubObject("Item (int)", 2);
    50. yvalues = worksheet->querySubObject("Range(C2:C9)");
    51. serie->setProperty("XValues", xvalues->asVariant());
    52. serie->setProperty("Values", yvalues->asVariant());
    53.  
    54. serie = series->querySubObject("Item (int)", 3);
    55. yvalues = worksheet->querySubObject("Range(D2:D9)");
    56. serie->setProperty("XValues", xvalues->asVariant());
    57. serie->setProperty("Values", yvalues->asVariant());
    58.  
    59. workbook->dynamicCall("SaveAs (const QString&)", "E:/test/chartbyqt");
    60. workbook->dynamicCall("Close (Boolean)", false);
    61. excel->dynamicCall("Quit (void)");
    62.  
    63. return 0;
    64. //return a.exec();
    65. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 21
    Last Post: 8th December 2011, 02:18
  2. Help with Bar charts
    By romeo in forum Qwt
    Replies: 0
    Last Post: 30th June 2010, 16:58
  3. ActiveQt hosting Excel sheet
    By ArmanS in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2010, 10:27
  4. ActiveQt + Excel
    By nile.one in forum Qt Programming
    Replies: 7
    Last Post: 19th October 2007, 22:58
  5. MVC charts for Qt4
    By wysota in forum Qt-based Software
    Replies: 8
    Last Post: 28th September 2006, 16:06

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
  •  
Qt is a trademark of The Qt Company.