Crop MS Word Images using Matlab Activex control

2019-01-29 13:07发布

问题:

I am using MATLAB to paste and caption plots into Microsoft Word. I would like to also crop these images using the ActiveX control.

something like:

word = actxserver('Word.Application')

word.Visible = 1
op = invoke(word.Documents,'Add')

invoke(word.Selection,'Paste')

invoke(word.Selection,'CropBottom',CropAmount) <----- Except there is no function that will allow me to crop.

I am modifying the MATLAB File Exchange "save2word.m"

Thanks

回答1:

Consider this example:

%# create plot and copy to clipboard
plot(rand(10,1))
print -dmeta

%# open MS-Word
Word = actxserver('Word.Application');
Word.Visible = true;

%# create new document
doc = Word.Documents.Add;

%# paste figure from clipboard
Word.Selection.Paste

%# crop the image
doc.InlineShapes.Item(1).PictureFormat.CropBottom = 100;

%# save document, then close
doc.SaveAs2( fullfile(pwd,'file.docx') )
doc.Close(false)

%# quit and cleanup
Word.Quit
Word.delete