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

C++ 如何从MS Word 2007获取枚举类型值?,c++,qt,ms-word,word-2007,C++,Qt,Ms Word,Word 2007,我需要获取文档中的当前页面,并设置范围。我发现可以通过以下方式实现: Range.Information(wdActiveEndPageNumber) //example in C# 但我有问题。在中,信息作为属性可见。所以当我使用 QString number = myRange->property("Information(wdActiveEndPageNumber)").toString() 我什么也得不到。我也试过dynamicCall,但两种方法都不起作用。像Text

我需要获取文档中的当前页面,并设置范围。我发现可以通过以下方式实现:

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

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

这又是答案。 使用包含您的枚举的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");
}
QAxObject*enum1=returnList->querySubObject(“\u NewEnum”);
IEnumVARIANT*枚举接口//要得到这个,包括
enum1->queryInterface(IID_IEnumVARIANT,(void**)和enumInterface);
枚举接口->重置()//从列表的开头开始。
对于(int i=0;idynamicCall(“Count”).toInt();i++)
{
变体*Etem;
enumInterface->Next(1,item,NULL);
QAxObject*item=新QAxObject((IUnknown*)ITEEM->punkVal);
qDebug()动态调用(“标题”);
}

Qt,把它放在标签中,但我对任何解决方案都持开放态度。我的意思是,myRange是什么类型的,您使用什么API访问Word?(ActiveX?)。核心Qt不做这样的事情。添加了完整的代码。是的,我用ActiveX