如何从MS Word 2007中获取枚举类型值



我需要获取文档中的当前页面,并设置范围。我发现这是可能做到的:

Range.Information(wdActiveEndPageNumber)     //example in C#

但我对此有意见。在文档中,信息作为属性可见。所以当我使用时

QString number = myRange->property("Information(wdActiveEndPageNumber)").toString()

我一无所获。我也试过dynamicCall,但两者都不起作用。像Text或Start这样的简单属性运行得很好,但我不知道该如何处理这些枚举。

完整代码:

QAxObject *word, *doc;
word = new QAxObject("Word.Application", this);
word->setProperty("DisplayAlerts", false);
word->setProperty("Visible", true);
doc = word->querySubObject("Documents");
doc->dynamicCall("Open(const QString&)", "path to file");
QAxObject *act = word->querySubObject("ActiveDocument");
QAxObject *next = act->querySubObject("Content");
next->dynamicCall("Select()");
next->dynamicCall("Copy()");
QClipboard *clip = QApplication::clipboard();
myTextEdit->setText(clip->text());
QString number = next->property("Information(3)").toString();
QMessageBox::information(this, tr("cos"), tr("%1").arg(number)); //here i need to know how many pages i've got

好吧,经过大量研究,我发现还不可能从Information枚举中获得价值。也许在Qt的未来版本中,但现在我不得不在Visual Basic中创建库,并从C++代码中调用函数。

刚刚在这里找到了这个问题的一个非常酷的答案:http://www.qtforum.org/article/31970/how-do-i-get-use-the-ienumerable-interface-in-qt.html

答案又来了。带有包含枚举的returnList。。

QAxObject *enum1 = returnList->querySubObject("_NewEnum");
IEnumVARIANT* enumInterface; //to get this, include <windows.h>
enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface);
enumInterface->Reset(); //start at the beginning of the list.
for (int i=0;i<returnList->dynamicCall("Count").toInt();i++)
{
    VARIANT *theItem;
    enumInterface->Next(1,theItem,NULL);
    QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal);
    qDebug() << item->dynamicCall("Caption");
}