通过qt activex生成嵌入式图表

Generating embedded charts via qt activex

我找到了使用 Qt Activex 在 excel 中插入图表类型工作表(非嵌入式图表)的代码,如下所示:

代码运行良好。我想知道在哪里可以找到处理图表特别是嵌入图表的标准 APIs/some 示例。我在哪里可以找到一些示例或 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)");

我希望这段代码有效:

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

编辑:我已将第二行更改为以下并且有效 测试->querySubObject("ChartObjects()");