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. How to add a table in MS Word Document using ActiveQt?
Qt 6.11 is out! See what's new in the release blog

How to add a table in MS Word Document using ActiveQt?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 4.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello everybody!
    I wrote a piece of code which should add a new table to my document but it doesn't work because of bad argument. the problem is with "range". How should I write it correctly?
    @
    void ChartWindow::makeWordDoc()
    {
    char const* const WordDocumentSaveAs = "SaveAs(QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&)";
    char const* const WordDocumentsAdd = "Add(QVariant&, QVariant&, WdNewDocumentType, QVariant&)";
    char const* const TablesAdd = "Add(QVariant&, QVariant&, QVariant&, QVariant&, QVariant&)";

    CoInitialize(NULL);
    
    QAxObject *wordApp = new QAxObject("Word.Application");
    wordApp->setProperty("Visible", true);
    QAxObject *wordDocs = wordApp->querySubObject("Documents");
    QAxObject *wordDoc = wordDocs->querySubObject(WordDocumentsAdd,"Normal",false,"wdNewBlankDocument",true);
    QAxObject *range = wordDoc->querySubObject( "Content()" );
    QAxObject *tables = wordDoc->querySubObject("Tables()");
    range->dynamicCall( "Expand(wdTable)" );
    range->dynamicCall( "Collapse(0)" );
    QAxObject *table = tables->querySubObject(TablesAdd, range->asVariant(),3,2,"wdWord9TableBehavior","wdAutoFitWindow");
    wordDoc->dynamicCall(WordDocumentSaveAs, "d:\\text.doc");
    

    }
    @
    Big thanks for any help.

    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