Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to add an image to an Excel spreadsheet Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
08-Jan-03
Category
OLE
Language
Delphi 6.x
Views
129
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I try to embed an image (jpg or bmp) into a spreadsheet. It will go in the top left 
of the spreadsheet - like a letterhead, sort of. I've seen the methods that use 
late binding, but the code I'm modifying use the early binding object 
TExcelApplication (the instance is called ExcelApplication1). The following doesn't 
compile:

ExcelApplication1.ActiveSheet.Pictures.Insert('c:\translogo.bmp')

I get the error "undeclared identifier: Pictures". Any suggestions?

Answer:

If WS is your worksheet:

1   { ... }
2   WS.Shapes.AddPicture('C:\Pictures\Small.Bmp', EmptyParam, EmptyParam, 10, 160,
3     EmptyParam, EmptyParam);


or

4   { ... }
5   var
6     Pics: Excel2000.Pictures; {or whichever Excel}
7     Pic: Excel2000.Picture;
8     Pic: Excel2000.Shape;
9     Left, Top: integer;
10  { ... }
11  Pics := (WS.Pictures(EmptyParam, 0) as Pictures);
12  Pic := Pics.Insert('C:\Pictures\Small.Bmp', EmptyParam);
13  Pic.Top := WS.Range['D4', 'D4'].Top;
14  Pic.Left := WS.Range['D4', 'D4'].Left;
15  { ... }


EmptyParam a special variant (declared in Variants.pas in D6+). However in later 
versions of Delphi some conversions cause problems. This should work:

16  uses
17    OfficeXP;
18  
19  { ... }
20  WS.Shapes.AddPicture('H:\Pictures\Game\Hills.bmp', msoFalse, msoTrue, 10, 160, 100,
21    100);


But you may have to use a TBitmap to find out how large the picture should be.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC