//put a box and set: star out put QMessageBox::warning(this,"Start","Start Output",QMessageBox::Yes); //create new doc application QAxObject* word = newQAxObject(); bool flag = word->setControl("Word.Application"); if(!flag){ flag = word->setControl("kwps.Application"); if(!flag) return; }
//QAxWidget* word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC); //set unvisible word->setProperty("Visible",false); word->setProperty("DisplayAlerts",false); //get all document QAxObject* documents = word->querySubObject("Documents"); //use document2.dot template to create a new document documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("C:/Users/****/Desktop/4444.docx")); //get active document QAxObject* document = word->querySubObject("ActiveDocument");
//get bookmark which name is 测试 in this document QAxObject* bookmark_test = document->querySubObject("BookMarks(QVariant)","测试"); //select target bookmark and set value if(!bookmark_test->isNull()){ QString sText = ui->pcEdit->text(); qDebug()<<sText; bookmark_test->dynamicCall("Select(void)"); bookmark_test->querySubObject("Range")->setProperty("Text",sText); } // insert table // int row = 14; // int col = 0; int tableIndex = 4; QAxObject* tables = document->querySubObject("Tables"); if(nullptr == tables) return; QAxObject* selection = word->querySubObject("Selection"); if(nullptr == selection) return; QAxObject* range = selection->querySubObject("Range"); if(nullptr == range) return;