Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Getting pasted image reference


Hi,

it will be easy (I think).

I'm creating an Excel worksheet from a C# application. When I want t
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 th
cell, I want to align the image to the right. The image doesn't seem t
answer to cell's horizontal or vertical alignment, so I managed to do i
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 ca
use the Shapes.Count to get the index of the last picture inserted an
get the correct name, but it seems dirty. So the question is, how woul
you do it? Maybe is a way to set an arbitrary name to the shape whe
pasting?

Thanks in advance

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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Getting pasted image reference


Thanks for your response!

What you say is what I was referring with "an arbitrary name". Th
problem is I don't know how to set the name of the shape when pastin
the image; that's it, when pasting excel automatically names the shap
as "Picture XXX" and I want to change that.

JLGWhiz;3977592 Wrote:
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 workin
with.

"Urotsukidoji" wrote:


Hi,

it will be easy (I think).

I'm creating an Excel worksheet from a C# application. When I wan

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 see

to
answer to cell's horizontal or vertical alignment, so I managed to d

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 th

worksheet,
obviously the one pasted will not be called "Picture 1". I alway

can
use the Shapes.Count to get the index of the last picture inserte

and
get the correct name, but it seems dirty. So the question is, ho

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



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

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Getting pasted image reference

This will give you the name of the last picture added to the sheet.

With ActiveSheet.Pictures
MsgBox .Item(.Count).Name
End With

Note that Pictures actually includes other OLEObjects on the sheet also.
(I still have to see a good explanation of
Pictures/OLEObjects/Shapes/DrawingObjects, despite Peter T's best effort at
explaining.)

NickHK

"Urotsukidoji" wrote in message
...

Thanks for your response!

What you say is what I was referring with "an arbitrary name". The
problem is I don't know how to set the name of the shape when pasting
the image; that's it, when pasting excel automatically names the shape
as "Picture XXX" and I want to change that.

JLGWhiz;3977592 Wrote:
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




--
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell reference update when copied and pasted Dave Excel Worksheet Functions 1 April 5th 06 08:52 PM
Get a reference to the last object pasted quartz[_2_] Excel Programming 6 January 13th 05 04:15 PM
moving excel objects pasted as an image in Powerpoint Iker Excel Programming 1 September 24th 04 04:39 AM
Reference an image in another sheet Pete Csiszar[_2_] Excel Programming 3 February 1st 04 05:04 AM
reference an ole image control's .Picture filename? bdcrisp[_22_] Excel Programming 3 January 3rd 04 04:41 PM


All times are GMT +1. The time now is 02:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"