Generating embedded charts via Qt ActiveX
- 
What is the difference between the chart object you get with this code and the 
 one you refer to as embedded?
 It seems the same
 as
 http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.htmlYou add chart 
 AxObject *chart = workbook->querySubObject("Charts")->querySubObject("Add");
 You set type
 chart->setProperty("Chart Type", 73);The API is for the programming of Excel. Its Automation API. @mrjj Thanks, The chart that is created is a 'worksheet chart' which is a worksheet which is dedicated to a fullscreen chart. I want to create a embedded chart in a ordinary worksheet. 
- 
@mrjj Thanks, The chart that is created is a 'worksheet chart' which is a worksheet which is dedicated to a fullscreen chart. I want to create a embedded chart in a ordinary worksheet. @alizadeh91 
 Hmm
 I think it comes from the fact we create it
 QAxObject *chart = workbook->querySubObject("Charts")->querySubObject("Add");
 on the workbookI wonder if we can ask worksheet->querySubObject("Charts")xxx 
 so its added to the collection of the sheet.
 Or
 "ActiveSheet"-->querySubObject("Charts")If you see here 
 https://msdn.microsoft.com/en-us/library/office/ff194426.aspxSo I think its about what collection you put it in. 
- 
@alizadeh91 
 Hmm
 I think it comes from the fact we create it
 QAxObject *chart = workbook->querySubObject("Charts")->querySubObject("Add");
 on the workbookI wonder if we can ask worksheet->querySubObject("Charts")xxx 
 so its added to the collection of the sheet.
 Or
 "ActiveSheet"-->querySubObject("Charts")If you see here 
 https://msdn.microsoft.com/en-us/library/office/ff194426.aspxSo I think its about what collection you put it in. 
- 
@alizadeh91 
 They are using the same model. The syntax is just different. With Qt you are running it via
 a Automation server which VBA also does but its just more natural looking.So even syntax not the same, the object its uses and often also actual structure is the same. So if you know how to get a embedded chart in VBA, the same will work for Qt. Therefore an understanding of the model (of Excel) is needed to use the Qt code. 
- 
@alizadeh91 
 They are using the same model. The syntax is just different. With Qt you are running it via
 a Automation server which VBA also does but its just more natural looking.So even syntax not the same, the object its uses and often also actual structure is the same. So if you know how to get a embedded chart in VBA, the same will work for Qt. Therefore an understanding of the model (of Excel) is needed to use the Qt code. @mrjj Thanks, Could u give me an example (some codes for VBA and Qt which are equivalent). I need a start point to start learning it 
- 
@mrjj Thanks, Could u give me an example (some codes for VBA and Qt which are equivalent). I need a start point to start learning it @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 SubWe 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. 
- 
@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 SubWe 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. @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 foundI wish there was some examples in web but there is nothing... 
- 
@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 foundI wish there was some examples in web but there is nothing... @alizadeh91 
 WellI 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.
- 
@alizadeh91 
 WellI 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.@mrjj I don't know why it gives that error that the member is not found (ChartObjects) :( 
- 
@mrjj I don't know why it gives that error that the member is not found (ChartObjects) :( @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.
- 
@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.@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. 
- 
Ah so ("ChartObjects(int)",1)->querySubObject("Chart"); 
 gives the first chart.
 Good work.
 Thank you for reporting back.
- 
Ah so ("ChartObjects(int)",1)->querySubObject("Chart"); 
 gives the first chart.
 Good work.
 Thank you for reporting back.@mrjj But still having problem with adding new embedded chart!!! 
- 
@mrjj But still having problem with adding new embedded chart!!! 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* .
- 
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* .@mrjj I've changed sheet2->querySubObject("ChartObjects"); to sheet2->querySubObject("ChartObjects()"); and it worked 
- 
Super :) 
 oh it must have "()" on.
 The syntax is pretty funky via the automation server.
 Good work.
