Qt调用word 例子

Qt调用word 例子

Getting Microsoft Word Object to SaveAs

  1. #include <QtGui>
  2. #include <QAxObject>
  3. #include <QAxWidget>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. QApplication a(argc, argv);
  8.  
  9. QAxWidget word("Word.Application");
  10. word.setProperty("Visible", true);
  11. QAxObject * documents = word.querySubObject("Documents");
  12. documents->dynamicCall("Add (void)");
  13. QAxObject * document = word.querySubObject("ActiveDocument");
  14.  
  15. document->dynamicCall("SaveAs (const QString&)", QString("e:/test/docbyqt.doc"));
  16. document->dynamicCall("Close (boolean)", false);
  17. word.dynamicCall("Quit (void)");
  18. return 0;
  19. }

Getting Microsoft Word Object to SaveAs

  1. //Start Word
  2. my_app = new QAxObject("Word.Application", this);
  3. QAxObject* my_docs = my_app->querySubObject("Documents");
  4.  
  5. //Open newDocName
  6. QVariant filename(newDocName);
  7. QVariant confirmconversions(false);
  8. QVariant readonly(false);
  9. QVariant addtorecentfiles(false);
  10. QVariant passworddocument("");
  11. QVariant passwordtemplate("");
  12. QVariant revert(false);
  13. 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);
  14.  
  15. //Pull out active document object
  16. QAxObject* active_doc = my_app->querySubObject("ActiveDocument");
  17.  
  18. QVariant newFileName(fileNameString);
  19. QVariant fileFormat(10); //Saving as filtered html
  20. QVariant LockComments(false);
  21. QVariant Password("");
  22. QVariant recent(true);
  23. QVariant writePassword("");
  24. QVariant ReadOnlyRecommended(false);
  25.  
  26. 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);
上一篇:AppCompat Toolbar控件去掉阴影设置高度


下一篇:linux查看某个端口被占用