Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Generating embedded charts via Qt ActiveX

Generating embedded charts via Qt ActiveX

Scheduled Pinned Locked Moved Solved General and Desktop
qaxobjectactivexexcelcharts
24 Posts 3 Posters 11.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mrjj
    2 Nov 2016, 14:59

    @alizadeh91
    Sadly its not just a 1 to 1 convert.

    VBA:
    Sub charObj()
    Dim myChartObject As ChartObject
    Set myChartObject = ActiveSheet.ChartObjects.Add(Left:=200, Top:=200, _
    Width:=400, Height:=300)
    End Sub

    We can see it adds to ChartObjects of the active sheet. So we know it also has a collection and not
    just the workbook.

    in Qt we do
    QAxObject *workbook = excel->querySubObject("Workbooks")->querySubObject("Add");
    QAxObject *worksheet = workbook->querySubObject("Worksheets(1)");
    Which gives us the sheet.

    There should also be a way to get ActiveSheet like VBA.

    A Offline
    A Offline
    alizadeh91
    wrote on 2 Nov 2016, 15:56 last edited by alizadeh91 11 Feb 2016, 15:57
    #15

    @mrjj Ok, I've got it and from this I've found that I have to write below code to add a embedded chart in a worksheet:

    worksheet->querySubObject("ChartObjects")->querySubObject("Add")
    

    But it gives following error:

    QAxBase: Error calling IDispatch member ChartObjects: Member not found
    

    I wish there was some examples in web but there is nothing...

    M 1 Reply Last reply 2 Nov 2016, 15:59
    0
    • A alizadeh91
      2 Nov 2016, 15:56

      @mrjj Ok, I've got it and from this I've found that I have to write below code to add a embedded chart in a worksheet:

      worksheet->querySubObject("ChartObjects")->querySubObject("Add")
      

      But it gives following error:

      QAxBase: Error calling IDispatch member ChartObjects: Member not found
      

      I wish there was some examples in web but there is nothing...

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Nov 2016, 15:59 last edited by
      #16

      @alizadeh91
      Well

      I had luck with
      QAxObject* test = workbook->querySubObject("ActiveSheet");
      QAxObject* charts = test->querySubObject("ChartObjects");
      QList<QVariant> f; f << 200 << 400 << 200 << 200;
      QVariant ch = charts->dynamicCall("Add(int, int, int, int)", f );

      Added Chart to first sheet

      Now is issue how to get the chart to set it up.

      Not sure what Add returns.
      IF we could get handle to the new chart, rest of code be the same and it would be embedded.

      A 1 Reply Last reply 2 Nov 2016, 16:01
      1
      • M mrjj
        2 Nov 2016, 15:59

        @alizadeh91
        Well

        I had luck with
        QAxObject* test = workbook->querySubObject("ActiveSheet");
        QAxObject* charts = test->querySubObject("ChartObjects");
        QList<QVariant> f; f << 200 << 400 << 200 << 200;
        QVariant ch = charts->dynamicCall("Add(int, int, int, int)", f );

        Added Chart to first sheet

        Now is issue how to get the chart to set it up.

        Not sure what Add returns.
        IF we could get handle to the new chart, rest of code be the same and it would be embedded.

        A Offline
        A Offline
        alizadeh91
        wrote on 2 Nov 2016, 16:01 last edited by
        #17

        @mrjj I don't know why it gives that error that the member is not found (ChartObjects) :(

        M 1 Reply Last reply 2 Nov 2016, 16:17
        0
        • A alizadeh91
          2 Nov 2016, 16:01

          @mrjj I don't know why it gives that error that the member is not found (ChartObjects) :(

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Nov 2016, 16:17 last edited by
          #18

          @alizadeh91
          Because it must be via ActiveSheet or else it dont know it , i think.
          Or it dont know Add() that way.
          That is the frustrating part. Finding out where it keeps the stuff you want.

          A 1 Reply Last reply 3 Nov 2016, 19:00
          1
          • M mrjj
            2 Nov 2016, 16:17

            @alizadeh91
            Because it must be via ActiveSheet or else it dont know it , i think.
            Or it dont know Add() that way.
            That is the frustrating part. Finding out where it keeps the stuff you want.

            A Offline
            A Offline
            alizadeh91
            wrote on 3 Nov 2016, 19:00 last edited by
            #19

            @mrjj I've changed the code as below and this codes works:

            QAxObject* excel = new QAxObject( "Excel.Application", 0 );
                QAxObject* workbooks = excel->querySubObject( "Workbooks" );
                QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", "D:\\test.xls" );
                QAxObject* sheets = workbook->querySubObject( "Worksheets" );
                QAxObject* sheet = sheets->querySubObject( "Item( int )", 1 );
                QAxObject* chart = sheet->querySubObject("ChartObjects(int)",1)->querySubObject("Chart");
            

            As seen, ChartObjects(int) has a member called 'Chart' and the code works. So it seems that ChartObjects is not defined by itself or something like that.

            1 Reply Last reply
            1
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 4 Nov 2016, 07:40 last edited by mrjj 11 Apr 2016, 07:41
              #20

              Ah so ("ChartObjects(int)",1)->querySubObject("Chart");
              gives the first chart.
              Good work.
              Thank you for reporting back.

              A 1 Reply Last reply 4 Nov 2016, 13:33
              1
              • M mrjj
                4 Nov 2016, 07:40

                Ah so ("ChartObjects(int)",1)->querySubObject("Chart");
                gives the first chart.
                Good work.
                Thank you for reporting back.

                A Offline
                A Offline
                alizadeh91
                wrote on 4 Nov 2016, 13:33 last edited by
                #21

                @mrjj But still having problem with adding new embedded chart!!!

                M 1 Reply Last reply 4 Nov 2016, 13:57
                0
                • A alizadeh91
                  4 Nov 2016, 13:33

                  @mrjj But still having problem with adding new embedded chart!!!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 4 Nov 2016, 13:57 last edited by
                  #22

                  @alizadeh91

                  Did you try the test code ?.

                  It inserts embedded for me.

                  QAxObject* test = workbook->querySubObject("ActiveSheet");
                  QAxObject* charts = test->querySubObject("ChartObjects");
                  QList<QVariant> f; f << 200 << 400 << 200 << 200;
                  charts->dynamicCall("Add(int, int, int, int)", f );

                  I didnt check if
                  ("ChartObjects(int)",1)->querySubObject("Chart"); will give you that.

                  From docs, the Add should return the chart object but I could not get it to cast to
                  QAxObject* .

                  A 1 Reply Last reply 4 Nov 2016, 14:01
                  3
                  • M mrjj
                    4 Nov 2016, 13:57

                    @alizadeh91

                    Did you try the test code ?.

                    It inserts embedded for me.

                    QAxObject* test = workbook->querySubObject("ActiveSheet");
                    QAxObject* charts = test->querySubObject("ChartObjects");
                    QList<QVariant> f; f << 200 << 400 << 200 << 200;
                    charts->dynamicCall("Add(int, int, int, int)", f );

                    I didnt check if
                    ("ChartObjects(int)",1)->querySubObject("Chart"); will give you that.

                    From docs, the Add should return the chart object but I could not get it to cast to
                    QAxObject* .

                    A Offline
                    A Offline
                    alizadeh91
                    wrote on 4 Nov 2016, 14:01 last edited by alizadeh91 11 Apr 2016, 14:03
                    #23

                    @mrjj I've changed sheet2->querySubObject("ChartObjects"); to sheet2->querySubObject("ChartObjects()"); and it worked

                    1 Reply Last reply
                    3
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 4 Nov 2016, 14:04 last edited by
                      #24

                      Super :)
                      oh it must have "()" on.
                      The syntax is pretty funky via the automation server.
                      Good work.

                      1 Reply Last reply
                      2

                      24/24

                      4 Nov 2016, 14:04

                      • Login

                      • Login or register to search.
                      24 out of 24
                      • First post
                        24/24
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved