我有一个使用Excel的Qt应用程序,我想在文档中添加一个工作表。最简单的解决方案就是调用
QAxObject *sheets = workbook->querySubObject("Worksheets");
sheets->dynamicCall("Add()");
但是这样你就可以在最后一张现有纸张之前添加一张纸,但是我想把它放在最后一张纸之后。生成的文档会告诉你:
IDispatch* Add (QVariant Before, QVariant After, QVariant Count, QVariant Type) [slot]
Connect a signal to this slot:
QObject::connect(sender, SIGNAL(someSignal(QVariant, QVariant, QVariant, QVariant)), object, SLOT(Add(QVariant, QVariant, QVariant, QVariant)));
Or call the function directly:
QVariantList params = ...
QAxObject * result = object->querySubObject("Add(QVariant, QVariant, QVariant, QVariant)", params);
但是params怎么样?正如我所看到的,“之后”是第二个参数,但我根本不需要“之前”。我应该指定什么作为参数?
答案 0 :(得分:2)
您必须指定最后一张和新张,否则如果省略BEFORE和AFTER,默认情况下将在活动工作表之前插入新工作表。
你可以做一些这样的事情,在最后一张纸之后插入:
// set of sheets
QAxObject* sheets = workbook->querySubObject( "Worksheets" );
// Sheets number
int intCount = sheets->property("Count").toInt();
// Capture last sheet and add new sheet
QAxObject* lastSheet = sheets->querySubObject("Item(int)", intCount);
sheets->dynamicCall("Add(QVariant)", lastSheet->asVariant());
// Capture the new sheet and move to after last sheet
QAxObject* newSheet = sheets->querySubObject("Item(int)", intCount);
lastSheet->dynamicCall("Move(QVariant)", newSheet->asVariant());
Regards,
Valdir.