开发者

Insert Image in Excel through Matlab

I am using the function, Shapes.AddPicture to insert an image in an excel file.

I am calling the routine something like this :

leftPlacement=450;
topPlacement=20;
imgWidth=350;
imgHeight=300;

Shapes.AddPicture([pwd '\' img] ,0,1,leftPlacement,topPlacement,imgWidth,imgHeight);

This works fine. However, the image masks the data in the file. In order to change the position, leftPlacement, topPlacement, imgWidth imgHeight have to be changed manually.

I a开发者_开发技巧m wondering, if there is a better way to do it to transparently place the image in the empty cells.


Shapes are not attached to individual cells in the Excel Worksheet - they float above them and have their own coordinates. If you want to float them above a particular cell, you can get the coordinates of that cell and use those.

So if you want to float it above cell C9, try

left = xl.ActiveSheet.Range('C9').Left;
top = xl.ActiveSheet.Range('C9').Top;
xl.ActiveSheet.Shapes.AddPicture('myPicPath',0,1,left,top,myPicHeight,myPicWidth)

where xl is the variable containing your reference to the Excel application.

Note that if you subsequently resize, or otherwise move any of the cells, the position of the shape/image won't change - you'll need to reposition it again using the same method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜