PDA

View Full Version : Insert picture into MS Word Document



UndeadDragon
3rd November 2012, 20:10
How can I insert picture into MS Word Document?
I tried this, but it didnt work:


QAxObject* WordApplication = new QAxObject("Word.Application");

QAxObject* WordDocuments = WordApplication->querySubObject("Documents()");
QAxObject* NewDocument = WordDocuments->querySubObject("Add()");
WordApplication->setProperty("Visible", true);

QAxObject* ActiveDocument = WordApplication->querySubObject("ActiveDocument()");

QAxObject *inlineShapes = ActiveDocument->querySubObject("InlineShapes()");
QAxObject *addPicture = inlineShapes->querySubObject("AddPicture(QString&)","./add.png");

ChrisW67
3rd November 2012, 22:50
It didn't work
Hardly descriptive is it? What did it do? Why do you think it didn't work? Error messages?

You are using a relative path to the file. Be very sure you know where the current work directory of the running application is.

UndeadDragon
4th November 2012, 00:28
Hardly descriptive is it? What did it do? Why do you think it didn't work? Error messages?

You are using a relative path to the file. Be very sure you know where the current work directory of the running application is.

Sorry, ofcouse (for my bad english too).
Now Word is runing with program, document creating and nothing more, pure empty list.
In other words works all except picture insert :) And no error messages.
Yes, in that I'm sure)

ChrisW67
4th November 2012, 03:07
AddPicture (http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.inlineshapes.addpict ure%28v=office.11%29.aspx) has four arguments, perhaps you need to provide null QVariants for the unspecified optional arguments. Cannot try it myself, have no Word.

UndeadDragon
4th November 2012, 10:54
AddPicture (http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.inlineshapes.addpict ure%28v=office.11%29.aspx) has four arguments, perhaps you need to provide null QVariants for the unspecified optional arguments. Cannot try it myself, have no Word.
Thank you for your trying to help me!
But this

QAxObject* WordApplication = new QAxObject("Word.Application");

QAxObject* WordDocuments = WordApplication->querySubObject("Documents()");

QAxObject* NewDocument = WordDocuments->querySubObject("Add()");

WordApplication->setProperty("Visible", true);

QAxObject* ActiveDocument = WordApplication->querySubObject("ActiveDocument()");

QAxObject *inlineShapes = ActiveDocument->querySubObject("InlineShapes()");

QAxObject *addPicture = inlineShapes->querySubObject("AddPicture(QString, QVariant, QVariant, QVariant)",
"D:\\Projects\\ApproximateView\\ApproximateView\\ad d.png",0,0,0);
Still dont wanna work :(