Qt inserts text into Word (using Qaxwidget and Qaxobject)

Source: Internet
Author: User

    1. To join in Pro file
CONFIG + = Qaxcontainer 2. Main.cpp [CPP]View PlainCopy
  1. #include <QApplication>
  2. #include <QAxWidget>
  3. #include <QAxObject>
  4. int main (int argc, char* argv[])
  5. {
  6. Qapplication app (argc, argv);
  7. Qaxwidget *word=New Qaxwidget ("Word.Application", 0, QT::MSWINDOWSOWNDC);
  8. Word->setproperty ("Visible", true);
  9. //Get all work documents
  10. Qaxobject * documents = Word->querysubobject ("documents");
  11. //Create a new document as a template in file Template.doc
  12. Documents->dynamiccall ("Add (QString)", Qstring::fromlocal8bit ("D:/doc/template.doc"));
  13. //Get the currently active document
  14. Qaxobject *document=word->querysubobject ("ActiveDocument");
  15. //Get a label with the text name in the document
  16. Qaxobject*bookmark_text=document->querysubobject ("Bookmarks (qvariant)","text");
  17. //Check tab to insert character inserttext into label position
  18. if (!bookmark_text->isnull ()) {
  19. Bookmark_text->dynamiccall ("select (void)");
  20. Bookmark_text->querysubobject ("Range")->setproperty ("text","InsertText");
  21. }
  22. //Save the file as Docbyqt.doc, close the work document, exit the application
  23. Document->dynamiccall ("SaveAs qstring&", QString ("D:/doc/docbyqt.doc"));
  24. Document->dynamiccall ("Close (Boolean)", false);
  25. Word->dynamiccall ("Quit ()");
  26. return app.exec ();
  27. }

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  
  1. #include <QApplication>
  2. #include <QAxWidget>
  3. #include <QAxObject>
  4. int main (int argc, char* argv[])
  5. {
  6. Qapplication app (argc, argv);
  7. Qaxwidget *word=New Qaxwidget ("Word.Application", 0, QT::MSWINDOWSOWNDC);
  8. Word->setproperty ("Visible", true);
  9. //Get all work documents
  10. Qaxobject * documents = Word->querysubobject ("documents");
  11. //Create a new document as a template in file Template.doc
  12. Documents->dynamiccall ("Add (QString)", Qstring::fromlocal8bit ("D:/doc/template.doc"));
  13. //Get the currently active document
  14. Qaxobject *document=word->querysubobject ("ActiveDocument");
  15. //Get a label with the text name in the document
  16. Qaxobject*bookmark_text=document->querysubobject ("Bookmarks (qvariant)","text");
  17. //Check tab to insert character inserttext into label position
  18. if (!bookmark_text->isnull ()) {
  19. Bookmark_text->dynamiccall ("select (void)");
  20. Bookmark_text->querysubobject ("Range")->setproperty ("text","InsertText");
  21. }
  22. //Get a label named pic in the document
  23. Qaxobject*bookmark_pic=document->querysubobject ("Bookmarks (qvariant)","pic");
  24. //Check the label to insert the picture into the label position
  25. if (!bookmark_pic->isnull ())
  26. {
  27. Bookmark_pic->dynamiccall ("select (void)");
  28. Qaxobject *range;
  29. Range = Bookmark_pic->querysubobject ("range");
  30. qvariant tmp = Range->asvariant ();
  31. qlist<qvariant>qlist;
  32. Qlist<<qvariant ("d:/1.png");
  33. Qlist<<qvariant (false);
  34. Qlist<<qvariant (true);
  35. qlist<<tmp;
  36. Qaxobject *inlineshapes = Document->querysubobject ("InlineShapes");
  37. Inlineshapes->dynamiccall ("addpicture (const qstring&, Qvariant, Qvariant, Qvariant)", qlist);
  38. }
  39. //Save the file as Docbyqt.doc, close the work document, exit the application
  40. Document->dynamiccall ("SaveAs qstring&", QString ("D:/doc/docbyqt.doc"));
  41. Document->dynamiccall ("Close (Boolean)", false);
  42. Word->dynamiccall ("Quit ()");
  43. return app.exec ();
  44. }

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.