I've tried to create embedded charts in excel with Qt activex objects and wrote some codes:
QAxObject *excel = new QAxObject("Excel.Application", 0);
QAxObject *workbook = excel->querySubObject("Workbooks")->querySubObject("Add");
QAxObject* sheets = workbook->querySubObject( "Worksheets" );
QAxObject* sheet1 = workbook->querySubObject("Worksheets(1)");
QAxObject* charts = sheet1->querySubObject("ChartObjects");
QList f; f << 200 << 400 << 200 << 200;
QVariant ch = charts->dynamicCall("Add(int, int, int, int)", f );
But the code gives following error msg:
QAxBase: Error calling IDispatch member ChartObjects: Member not found
What is the problem? It seems that the sheet is not valid but I am able to write into it!
解决方案Hi MostafaAlizadeh,
Did you get error on this line “QAxObject* charts = sheet1->querySubObject("ChartObjects");”? Could you check whether sheet1 is null? As far as I know, for a new workbook, there is one worksheet named “Sheet1” instead of “Worksheets(1)”.
I suggest you try something like below:
QAxObject* sheet1 = workbook->querySubObject("Sheet1");
Best Regards,
Edward