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. Replacing Field values in Word Document QAxObject
Forum Updated to NodeBB v4.3 + New Features

Replacing Field values in Word Document QAxObject

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 282 Views
  • 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.
  • I Offline
    I Offline
    ivasija-evonem
    wrote on 17 Nov 2020, 12:00 last edited by
    #1

    Dear all,

    I'm really new to QT and I was tasked to update some field values in word document programmatically, currently I can replace text from word document fine, but when that field value is inside an object (table or anything) it's not working, my code is:

            QString     outFile("D:\\#test files\\output.docx");
            QString     inFile1("D:\\#test files\\input.docx");
            QAxObject   axObject("Word.Application");
            QAxObject* documents = axObject.querySubObject("Documents");
            QAxObject* document = documents->querySubObject("Open(const QString&, bool)", inFile1, true);
            QAxObject* selection = axObject.querySubObject("Selection");
            auto find = selection->querySubObject("Find");
            QString sOld = "${name}";
            QString sNew = "Ibrahim";
            bool bMatchCase = false;
            bool bMatchWholeWord = false;
            bool bMatchWildCards = false;
            bool bReplaceAll = true;
            QVariantList vl = { sOld, bMatchCase, bMatchWholeWord, bMatchWildCards, false, false, true, 1, false, sNew, bReplaceAll ? "2" : "1" };
            find->dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)", vl);
            document->dynamicCall("SaveAs(const QString&)", outFile);
            document->dynamicCall("Close()");
            axObject.dynamicCall("Quit()");
    

    If you can help it would be awesome :)

    Best regards,
    Ibrahim

    J 1 Reply Last reply 17 Nov 2020, 12:23
    0
    • I ivasija-evonem
      17 Nov 2020, 12:00

      Dear all,

      I'm really new to QT and I was tasked to update some field values in word document programmatically, currently I can replace text from word document fine, but when that field value is inside an object (table or anything) it's not working, my code is:

              QString     outFile("D:\\#test files\\output.docx");
              QString     inFile1("D:\\#test files\\input.docx");
              QAxObject   axObject("Word.Application");
              QAxObject* documents = axObject.querySubObject("Documents");
              QAxObject* document = documents->querySubObject("Open(const QString&, bool)", inFile1, true);
              QAxObject* selection = axObject.querySubObject("Selection");
              auto find = selection->querySubObject("Find");
              QString sOld = "${name}";
              QString sNew = "Ibrahim";
              bool bMatchCase = false;
              bool bMatchWholeWord = false;
              bool bMatchWildCards = false;
              bool bReplaceAll = true;
              QVariantList vl = { sOld, bMatchCase, bMatchWholeWord, bMatchWildCards, false, false, true, 1, false, sNew, bReplaceAll ? "2" : "1" };
              find->dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)", vl);
              document->dynamicCall("SaveAs(const QString&)", outFile);
              document->dynamicCall("Close()");
              axObject.dynamicCall("Quit()");
      

      If you can help it would be awesome :)

      Best regards,
      Ibrahim

      J Offline
      J Offline
      JonB
      wrote on 17 Nov 2020, 12:23 last edited by
      #2

      @ivasija-evonem
      You may not a useful answer here, as I don't think this has anything to do with Qt/QAxObject. You need to either read up in what you need to do in Word to achieve this, or try your code from a Word VBA macro/recording from Word, to determine what really needs to be done to find the items correctly.

      1 Reply Last reply
      0

      1/2

      17 Nov 2020, 12:00

      • Login

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