- To join in Pro file
CONFIG + = Qaxcontainer 2. Main.cpp
[CPP]View PlainCopy
- #include <QApplication>
- #include <QAxWidget>
- #include <QAxObject>
- int main (int argc, char* argv[])
- {
- Qapplication app (argc, argv);
- Qaxwidget *word=New Qaxwidget ("Word.Application", 0, QT::MSWINDOWSOWNDC);
- Word->setproperty ("Visible", true);
- //Get all work documents
- Qaxobject * documents = Word->querysubobject ("documents");
- //Create a new document as a template in file Template.doc
- Documents->dynamiccall ("Add (QString)", Qstring::fromlocal8bit ("D:/doc/template.doc"));
- //Get the currently active document
- Qaxobject *document=word->querysubobject ("ActiveDocument");
- //Get a label with the text name in the document
- Qaxobject*bookmark_text=document->querysubobject ("Bookmarks (qvariant)","text");
- //Check tab to insert character inserttext into label position
- if (!bookmark_text->isnull ()) {
- Bookmark_text->dynamiccall ("select (void)");
- Bookmark_text->querysubobject ("Range")->setproperty ("text","InsertText");
- }
- //Save the file as Docbyqt.doc, close the work document, exit the application
- Document->dynamiccall ("SaveAs qstring&", QString ("D:/doc/docbyqt.doc"));
- Document->dynamiccall ("Close (Boolean)", false);
- Word->dynamiccall ("Quit ()");
- return app.exec ();
- }
http://blog.csdn.net/zbc415766331/article/details/36396159
On the web about QT operation Word is too little information, and finally can be inserted in the Word table in the place to insert a label in the picture.
1. Add in Pro
CONFIG + = Qaxcontainer
2.main.cpp
[CPP]View PlainCopy
- #include <QApplication>
- #include <QAxWidget>
- #include <QAxObject>
- int main (int argc, char* argv[])
- {
- Qapplication app (argc, argv);
- Qaxwidget *word=New Qaxwidget ("Word.Application", 0, QT::MSWINDOWSOWNDC);
- Word->setproperty ("Visible", true);
- //Get all work documents
- Qaxobject * documents = Word->querysubobject ("documents");
- //Create a new document as a template in file Template.doc
- Documents->dynamiccall ("Add (QString)", Qstring::fromlocal8bit ("D:/doc/template.doc"));
- //Get the currently active document
- Qaxobject *document=word->querysubobject ("ActiveDocument");
- //Get a label with the text name in the document
- Qaxobject*bookmark_text=document->querysubobject ("Bookmarks (qvariant)","text");
- //Check tab to insert character inserttext into label position
- if (!bookmark_text->isnull ()) {
- Bookmark_text->dynamiccall ("select (void)");
- Bookmark_text->querysubobject ("Range")->setproperty ("text","InsertText");
- }
- //Get a label named pic in the document
- Qaxobject*bookmark_pic=document->querysubobject ("Bookmarks (qvariant)","pic");
- //Check the label to insert the picture into the label position
- if (!bookmark_pic->isnull ())
- {
- Bookmark_pic->dynamiccall ("select (void)");
- Qaxobject *range;
- Range = Bookmark_pic->querysubobject ("range");
- qvariant tmp = Range->asvariant ();
- qlist<qvariant>qlist;
- Qlist<<qvariant ("d:/1.png");
- Qlist<<qvariant (false);
- Qlist<<qvariant (true);
- qlist<<tmp;
- Qaxobject *inlineshapes = Document->querysubobject ("InlineShapes");
- Inlineshapes->dynamiccall ("addpicture (const qstring&, Qvariant, Qvariant, Qvariant)", qlist);
- }
- //Save the file as Docbyqt.doc, close the work document, exit the application
- Document->dynamiccall ("SaveAs qstring&", QString ("D:/doc/docbyqt.doc"));
- Document->dynamiccall ("Close (Boolean)", false);
- Word->dynamiccall ("Quit ()");
- return app.exec ();
- }
AddPicture Microsoft Official Note: http://msdn.microsoft.com/en-us/library/office/aa171535 (v=office.11). aspx
http://blog.csdn.net/zbc415766331/article/details/36659993
HRESULT R;
r = CoInitialize (0);
R =coinitializeex (0, coinit_multithreaded);
M_word = new Qaxwidget ("Word.Application", widgets, QT::MSWINDOWSOWNDC);
M_word = new Qaxobject ("Word.Application");
if (M_word = = NULL) return true;
M_word->setproperty ("Visible", false); Set to Hidden
Qaxobject * documents = M_word->querysubobject ("Documents"); Get documents for all work
Http://www.qtcn.org/bbs/read-htm-tid-60802.html
Qt inserts text into Word (using Qaxwidget and Qaxobject)