qt Get Office file content
You need to get the file contents of the Word file. Online for a long time, most of them are excel. And word is very few. So record here, convenient for everyone to check and use their own.
The qt version used is 5.4.2 .
Here's a code description:
First include in the. Pro file
QT + = Axcontainer
Need to add the following header file
#include <QAxWidget>
#include <QAxObject>
The detailed code is as follows
Void qt_word (Qstring filepath) {//Specifies the path to open the file //qstring filepath = "D:/doc/local.doc"; //create qaxwidget objects that have objects for word Qaxwidget *word=new qaxwidget ("Word.Application", &NBSP;0,&NBSP;QT::MSWINDOWSOWNDC); //Sets whether word is visible, set to false here. This will not see Word's program word->setproperty ("Visible", false); // Find its properties through the Word object,document qaxobject * documents = word-> Querysubobject ("Documents"); //open the file to get the contents of the file through document documents- >dynamiccall ("Open (QString)", FilePath);// documents->dynamiccall ("Open (QString)", Qstring::fromlocal8bit ("D:/doc/local.doc")); //gets the document of the current activity Qaxobject *document = word->querysubobject ("ActiveDocument"); //from whenGet paragraphs qaxobject *paragraphs = document-> in the document of the former activity Querysubobject ("paragraphs"); //loop input each paragraph for (int ipar = 1; ipar <= paragraphs->property ("Count"). ToInt (); ipar++) { QAxObject *lines = Paragraphs->querysubobject ("Item (qvariant)", ipar); Qaxobject *line = lines->querysubobject ("Range"); qstring str = line->property ("Text"). ToString (); line->clear (); delete line; lines->clear (); delete lines; &nbsP; str = str.trimmed (); qdebug () < <str; } //Close document document-> Dynamiccall ("close (Boolean)", false);// document->dynamiccall (" close (Boolean) ", false); //exit word word-> Dynamiccall ("Quit ()");}
Because the internal organization of Word is not very clear. So it was a little bit of groping out.
At present, only the word2003 have been tested. More than 2007 versions are not yet available. Hope to have a clear word within the organization of friends can point.
Reference from: http://it-ua.info/news/2015/08/10/parsing-dokumenta-word-na-kartinki-abo-storya-pro-pereddiplomnih-budn.html
2016-04-24 19:21:44
This article is from the "Do Your best" blog, so be sure to keep this source http://qiaopeng688.blog.51cto.com/3572484/1767288
QT Get Office file content