Saving an image using actxserver

8 views (last 30 days)
Stephanie
Stephanie on 1 Jul 2013
Hi,
I made a GUI in guide that produces graphs and then gives the user an option to make a report that contains all of the important information for the graphs and an image of the graph into a word document. I am using fprintf to insert the text into the word file and then using actxserver to insert the image. Everything works fine until I try to save the document after the image has been inserted. The file will save, but the image won't show up. I have tried to save the file with another extension (.docx instead of .doc) and the file corrupts so you can't open it.
Here is my code for inserting the image and saving and closing the file:
FileSpec = fullfile(FileLocation,FileName);
%copy to clipboard
print -dmeta
% open MS-Word
Word = actxserver('Word.Application');
set(Word,'Visible',1)
%open the document
doc = invoke(Word.Documents,'Open',FileSpec);
% paste figure from clipboard
Word.Selection.Paste
%crop the image
doc.InlineShapes.Item(1).PictureFormat.CropBottom = 280;
doc.InlineShapes.Item(1).PictureFormat.CropRight = 560;
doc.InlineShapes.Item(1).PictureFormat.CropTop = 85;
doc.InlineShapes.Item(1).Height=270;
doc.InlineShapes.Item(1).Width=400;
invoke (doc, 'Save')
%invoke (doc, 'SaveAs', [FileSpec 'x'])
invoke(Word, 'Quit');
delete(Word);
How can I save the file and with the image included?
Thanks!

Answers (2)

Ker
Ker on 18 Sep 2013
Hi,Stephanie
If you have existing .docx in the directory to save to. invoke (doc, 'Save'); should work just fine; otherwise,if you will need to use invoke (doc, 'SaveAs', FileSpec) % for file with .docx extension invoke (doc, 'SaveAs', FileSpec, 1) %for file with .doc extension
Hope this help!

Image Analyst
Image Analyst on 18 Sep 2013
Where are you pasting it? I don't see any code where you set the cursor location. Is it supposed to go just as the very first thing in the file?

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!