Qt调用word 例子
Getting Microsoft Word Object to SaveAs
-
#include <QtGui>
-
#include <QAxObject>
-
#include <QAxWidget>
-
-
int main(int argc, char **argv)
-
{
-
QApplication a(argc, argv);
-
-
QAxWidget word("Word.Application");
-
word.setProperty("Visible", true);
-
QAxObject * documents = word.querySubObject("Documents");
-
documents->dynamicCall("Add (void)");
-
QAxObject * document = word.querySubObject("ActiveDocument");
-
-
document->dynamicCall("SaveAs (const QString&)", QString("e:/test/docbyqt.doc"));
-
document->dynamicCall("Close (boolean)", false);
-
word.dynamicCall("Quit (void)");
-
return 0;
-
}
Getting Microsoft Word Object to SaveAs
-
//Start Word
-
my_app = new QAxObject("Word.Application", this);
-
QAxObject* my_docs = my_app->querySubObject("Documents");
-
-
//Open newDocName
-
QVariant filename(newDocName);
-
QVariant confirmconversions(false);
-
QVariant readonly(false);
-
QVariant addtorecentfiles(false);
-
QVariant passworddocument("");
-
QVariant passwordtemplate("");
-
QVariant revert(false);
-
QAxObject* doc = my_docs->querySubObject("Open(const QVariant&, const QVariant&,const QVariant&, const QVariant&, const QVariant&, const QVariant&,const QVariant&)", filename,confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert);
-
-
//Pull out active document object
-
QAxObject* active_doc = my_app->querySubObject("ActiveDocument");
-
-
QVariant newFileName(fileNameString);
-
QVariant fileFormat(10); //Saving as filtered html
-
QVariant LockComments(false);
-
QVariant Password("");
-
QVariant recent(true);
-
QVariant writePassword("");
-
QVariant ReadOnlyRecommended(false);
-
-
active_doc->querySubObject("SaveAs(const QVariant&, const QVariant&,const QVariant&, const QVariant&, const QVariant&, const QVariant&,const QVariant&)", newFileName, fileFormat, LockComments, Password, recent, writePassword, ReadOnlyRecommended);