我发现使用Qt Activex在excel中插入图表类型工作表(非嵌入式图表)的代码如下所示:
代码工作正常。我想知道在哪里可以找到标准API /一些处理图表的示例,特别是嵌入式图表。我在哪里可以找到一些示例或API来通过qt Activex处理excel中的嵌入式图表。
如果有人能指导我使用QActivex生成嵌入式Excel图表,我将非常感激
QAxObject *excel = new QAxObject("Excel.Application", 0);
QAxObject *workbook = excel->querySubObject("Workbooks")->querySubObject("Add");
QAxObject *worksheet = workbook->querySubObject("Worksheets(1)");
worksheet->setProperty("Name", "Dati applicazione");
worksheet->querySubObject("Cells(1,1)")->dynamicCall("SetValue", "Serie");
worksheet->querySubObject("Cells(1,2)")->dynamicCall("SetValue", "Dati");
QAxObject *cell;
double dval;
for (int i = 2; i < 10; ++i) {
dval = qrand();
cell = worksheet->querySubObject("Cells(int,int)", i, 1);
cell->dynamicCall("SetValue(int)", i-1);
cell = worksheet->querySubObject("Cells(int,int)", i, 2);
cell->dynamicCall("SetValue(double)", dval);
cell = worksheet->querySubObject("Cells(int,int)",i,3);
cell->dynamicCall("SetValue(double)", dval/2.0);
cell = worksheet->querySubObject("Cells(int,int)", i, 4);
cell->dynamicCall("SetValue(double)", dval/3.0);
}
QAxObject *range = worksheet->querySubObject("Range(A2:C9)");
range->dynamicCall("Select(void)");
QAxObject *chart = workbook->querySubObject("Charts")->querySubObject("Add");
chart->setProperty("Name", "Report Grafico dei dati");
chart->setProperty("Chart Type", 73);
QAxObject *series = chart->querySubObject("SeriesCollection");
QAxObject *serie = series->querySubObject("Item (int)", 1);
QAxObject *xvalues = worksheet->querySubObject("Range(A2:A9)");
QAxObject *yvalues = worksheet->querySubObject("Range(B2:B9)");
serie->setProperty("XValues", xvalues->asVariant());
serie->setProperty("Values", yvalues->asVariant());
serie = series->querySubObject("Item (int)", 2);
yvalues = worksheet->querySubObject("Range(C2:C9)");
serie->setProperty("XValues", xvalues->asVariant());
serie->setProperty("Values", yvalues->asVariant());
serie = series->querySubObject("Item (int)",3);
yvalues = worksheet->querySubObject("Range(D2:D9)");
serie->setProperty("XValues", xvalues->asVariant());
serie->setProperty("Values", yvalues->asVariant());
workbook->dynamicCall("SaveAs(const QString&)", "E:\\test\\test.xls");
workbook->dynamicCall("Close (Bollean)", false);
excel->dynamicCall("Quit (void)");
答案 0 :(得分:0)
我希望这段代码有效:
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 );
但不幸的是它给出了这个错误,我不知道为什么
QAxBase: Error calling IDispatch member ChartObjects: Member not found
编辑:我已将第二行更改为下方并且有效 测试 - &GT; querySubObject( “ChartObjects()”);