qt中如何操作word文檔獲取當前行數從而進行一系列操作,以下參考:
//獲取當前所在頁數
int currentPageNumber()
{
QAxObject* activeWindow = m_wordDocuments->querySubObject("ActiveWindow");
QAxObject* pane = activeWindow->querySubObject("ActivePane");
QAxObject* pages = pane->querySubObject("Pages");
int pageNumber = pages->property("Count").toInt();
return pageNumber;
}
//獲取當前行數
int currentRow()
{
QAxObject* selection = m_wordWidget->querySubObject("Selection");
int row = selection->dynamicCall("Information(QVariant&)",10).toInt();
return row;
}
注意:如果出現換頁操作,獲取當前行數會在前一頁的基礎上記錄行數,有時候需要減掉前一頁的行數;