2012-09-02 43 views
0

我需要在文檔中獲取當前頁面,並設置範圍。我發現有可能通過:如何從MS Word 2007中獲取枚舉類型值?

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

但我有問題。在documentation中,信息作爲屬性可見。所以當我用

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

我什麼都沒有。我也嘗試過dynamicCall,但要麼不行。簡單的屬性作爲文本或開始工作很好,但我不知道如何處理這些枚舉。

整個代碼:

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 
+0

這是什麼API /庫? –

+0

Qt,有它的標籤,但我打開任何解決方案 – Blood

+0

我的意思是,什麼類型是myRange,你用什麼API來訪問Word? (的ActiveX?)。核心Qt不會做這樣的事情。 –

回答

1

好了,經過大量的研究,我發現,有沒有可能尚未採取從信息枚舉值。也許在未來的Qt版本中,但是現在我必須在Visual Basic中創建庫並從C++代碼調用函數。

1

剛剛發現一個非常酷的這個問題的答案在這裏: http://www.qtforum.org/article/31970/how-do-i-get-use-the-ienumerable-interface-in-qt.html

這裏再次答案。 With returnList contains your enum ..

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"); 
}