PDA

View Full Version : Getting Microsoft Word Object to SaveAs



jvwebb
13th August 2008, 07:31
I am working with QAxObjects to access Microsoft Word and can open and manipulate files but am struggling to get the SaveAs method to work. Does anyone out there have a working example they would be prepared to share?

Thank you

jpn
14th August 2008, 21:13
I suppose not that many people on this forum are using ActiveQt since it's only part of commercial Qt/Win. But perhaps we can help if you attach the generated C++ header (dumpcpp (http://doc.trolltech.com/4.4/activeqt-dumpcpp.html)) and paste some code what you've tried so far.

bst
15th August 2008, 15:19
Hi,

this seems to work here.

HTH, Bernd
--

#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;
}

jvwebb
2nd September 2008, 19:27
Thanks for the help. As a further complication I needed to save in Word's filtered html format. The following code seems to work.


//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);