Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAxObject ms Word - Unable to replace text, non default arguments syntax of dynamicCall()
Forum Updated to NodeBB v4.3 + New Features

QAxObject ms Word - Unable to replace text, non default arguments syntax of dynamicCall()

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clynamen
    wrote on last edited by
    #1

    I'm having trouble trying to replace text in a ms word doc through QAxObject.
    I didn't find the right syntax to pass only some arguments in dynamicCall, leaving the default ones.

    e.g. in vba you can do this:
    @myRange.Find.Execute FindText:="hi", ReplaceWith:="hello"@

    while in the online code I have seen the coders always pass all the arguments.

    this syntax seems to work to me
    @content->dynamicCall("InsertAfter (Text:=QVariant&)", "hello");@

    But I'm not sure if it is correct.

    the real problem however is that I can't replace text in the document using the Find.Execute() method.

    if I try to call this method the Find object emits an exception signal with these parameters:

    @Code: -119799803
    Source: ""
    Description: ""
    Help: "" @

    Here is the code that gives the error:

    @ QAxWidget* mWordWidget = new QAxWidget("Word.Application", this);
    mWordWidget->setVisible(true);
    mWordWidget->dynamicCall( "SetVisible(bool)", true);

    QAxObject* documents = mWordWidget->querySubObject("Documents");
    QAxObject* doc = documents->querySubObject("Add()");
    doc = mWordWidget->querySubObject("ActiveDocument");
    QAxObject* content = doc->querySubObject("Content");
    content->dynamicCall("InsertAfter (Text:=QVariant&)", "hello");
    content = doc->querySubObject("Content");
    QAxObject* find = content->querySubObject("Find");
    connect(find, SIGNAL(exception(int, const QString&, const QString&, const QString&)), this, SLOT(catchException(int, const QString&, const QString&, const QString&)));
    QList<QVariant> list;
    list.push_back("hello");
    list.push_back(true);
    list.push_back(true);
    list.push_back(false);
    list.push_back(false);
    list.push_back(false);
    list.push_back(QVariant());
    list.push_back(QVariant());
    list.push_back(QVariant());
    list.push_back("world");
    list.push_back(QVariant());
    list.push_back(QVariant("all"));
    list.push_back(false);
    list.push_back(false);
    list.push_back(false);
    qDebug() << "is find object null: " << find->isNull();
    find->dynamicCall("Execute (QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant& ,QVariant& ,QVariant& , QVariant&, QVariant&, QVariant&, QVariant&)", list);
    

    // find->dynamicCall("Execute (FindText:=QVariant&, ReplaceWith:=QVariant&)", "hello", "world");@

    here a Qt project with the code, ready to be compiled.

    https://dl.dropbox.com/u/11874818/replaceTextQAxObjectMsWord.zip

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CreMindES
      wrote on last edited by
      #2

      Hi,

      I'm would be also interested in the solution. Have you found one? Btw. I'm getting exection code -917766139.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        smallping
        wrote on last edited by
        #3

        Hi,
        this problem troubled me too, Have you found the solution about it?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          smallping
          wrote on last edited by
          #4

          Here is the code that replace the text successfully:
          @QAxWidget* mWordWidget = new QAxWidget("Word.Application", this);
          mWordWidget->setProperty("Visible", true);

          QAxObject* documents = mWordWidget->querySubObject("Documents");
          documents->dynamicCall("Add()");
          QAxObject doc = mWordWidget->querySubObject("ActiveDocument");
          QAxObject
          content = doc->querySubObject("Content");
          content->dynamicCall("InsertAfter (Text:=QVariant&)", "hello");
          content = doc->querySubObject("Content");
          QAxObject selection = mWordWidget->querySubObject("Selection");
          QAxObject
          find = selection->querySubObject("Find");

          QList<QVariant> list2;
          list2.append("hello");//find text
          list2.append(QVariant());//2
          list2.append(QVariant());//3
          list2.append(QVariant());//4
          list2.append(QVariant());//5
          list2.append(QVariant());//6
          list2.append(QVariant());//7
          list2.append(QVariant());//8
          list2.append(QVariant());//9
          list2.append("olleh");//replace text
          list2.append(2);//replace all:2
          list2.append(QVariant());//12
          list2.append(QVariant());//13
          list2.append(QVariant());//14
          list2.append(QVariant());//15
          connect(find, SIGNAL(exception(int, const QString&, const QString&, const QString&)), this, SLOT(catchException(int, const QString&, const QString&, const QString&)));

          find->dynamicCall("Execute (QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant& ,QVariant& ,QVariant& , QVariant&, QVariant&, QVariant&, QVariant&)", list2);
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved