如何在文本框中查找/替换文本Word使用QAxObject(自动化与Qt)

时间:2017-08-30 12:32:02

标签: c++ qt

我想知道是否有人可以帮助我...在我在文本框中尝试之前,查找文本和替换(在MS Word中)很简单。文本框中的文本被替换,但文本框中的文本无法替换。我已经找到了很多关于这个主题的答案,但是当你使用Qt时它们都是无用的(QAxObject,QAxBase) ...),它太复杂了,需要专业人士。这是我用来查找/替换文本的代码(不适用于文本框):

int main(int argc,char *argv[]){
    QApplication app(argc,argv);

    QAxObject *wApp = new QAxObject("{000209FF-0000-0000-C000-000000000046}");
    QAxObject *wDoc = wApp->querySubObject("Documents");
    wDoc->querySubObject("Open(QString)","aURL to the .docx file");
    QAxObject *wActive = wApp->querySubObject("ActiveDocument()");
    QAxObject *wContent = wActive->querySubObject("Content");
    QAxObject *wFind = wContent->querySubObject("Find");

            bool bMatchCase      = true;
            bool bMatchWholeWord = true;
            bool bMatchWildCards = false;
            bool bReplaceAll     = true;

            QString old = "Text";
            QString New = "NewText";

            QVariantList vA;

    vA = { old, bMatchCase, bMatchWholeWord, bMatchWildCards, false, false, true, 1, false,New, bReplaceAll ? "2" : "1" };

    wFind->dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)",vA);
    wApp->setProperty("Visible",true);
    wDoc->dynamicCall("Close(bool)",true);
    return app.exec();
}

来源:https://forum.qt.io/topic/82574/how-to-find-replace-text-in-a-docx-file-using-qaxobject/3

感谢您的帮助。

0 个答案:

没有答案