View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Getting pasted image reference

Why an arbitrary name, use a name that tells what the shape is. i.e.
"Acme_Co_logo" or "Photo_of_me". Then you know what you are working with.

"Urotsukidoji" wrote:


Hi,

it will be easy (I think).

I'm creating an Excel worksheet from a C# application. When I want to
insert an image in a cell of the worksheet, I use this code:


Code:
--------------------

Excel.WorkSheet ws = (...);
Excel.Range logo = ws.get_Range("A1","F10");
logo.Merge(false);
logo.Select();
Image img = Image.FromFile("../images/logo.gif");
Clipboard.SetDataObject(img,false);
ws.Paste(logo,"../images/logo.gif");

--------------------


After inserting the image, and if the image has less width than the
cell, I want to align the image to the right. The image doesn't seem to
answer to cell's horizontal or vertical alignment, so I managed to do it
that way:


Code:
--------------------

Excel.Shape shape = ws.Shapes.Item("Picture 1");
if ((shape != null)&&(shape.Width < (double)logo.Width)) {
shape.IncrementLeft((float)((double)logo.Width - shape.Width));
}

--------------------


The problem I had is, if there's already any picture in the worksheet,
obviously the one pasted will not be called "Picture 1". I always can
use the Shapes.Count to get the index of the last picture inserted and
get the correct name, but it seems dirty. So the question is, how would
you do it? Maybe is a way to set an arbitrary name to the shape when
pasting?

Thanks in advance!


--
Urotsukidoji
------------------------------------------------------------------------
Urotsukidoji's Profile: http://www.officehelp.in/member.php?userid=5154
View this thread: http://www.officehelp.in/showthread.php?t=1266051

Posted from - http://www.officehelp.in