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

时间:2012-09-02 08:36:01

标签: c++ qt ms-word word-2007

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

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

但我有问题。在documentation中,信息显示为属性。所以当我使用

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

2 个答案:

答案 0 :(得分:1)

好的,经过大量研究后,我发现没有可能从信息枚举中获取价值。也许在Qt的未来版本中,但现在我必须在Visual Basic中创建库并从C ++代码调用函数。

答案 1 :(得分:1)

刚刚在这里找到了一个非常酷的答案: 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");
}