使用Qt activex对象在Excel中创建嵌入式图表 [英] Creating embedded charts in excel with Qt activex objects
问题描述
我尝试使用Qt activex对象在excel中创建嵌入式图表,并编写了一些代码:
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<QVariant> f; f << 200 << 400 << 200 << 200;
QVariant ch = charts->dynamicCall("Add(int, int, int, int)", f );
但是代码给出了以下内容错误消息:
But the code gives following error msg:
QAxBase:调用IDispatch成员时出错ChartObjects:找不到成员
问题是什么?看来该表无效,但我可以写入它!
What is the problem? It seems that the sheet is not valid but I am able to write into it!
推荐答案
您好MostafaAlizadeh,
Hi MostafaAlizadeh,
您是否在此行中收到错误"QAxObject * charts = sheet1-> querySubObject(" ChartObjects");"?你能检查一下sheet1是否为空?据我所知,对于一个新的工作簿,有一个名为"Sheet1"而不是"Worksheets(1)"的工作表。
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
这篇关于使用Qt activex对象在Excel中创建嵌入式图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!