DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jun 2006

    Question C# & COM & Excel: How to Insert Image into cell

    I've mananged to successfully use COM to open up Microsoft Excel and insert an image for each row of data based on the filename retrieved from my database.

    I am using code found below, which I found on Google:
     string filename = "C:\\PHOTOS\\" + reader["photo_no"] + ".JPG";
                   FileInfo fi = new FileInfo(filename);  
                   if (fi.Exists){
                        m_oSheet.Shapes.AddPicture(filename, Microsoft.Office.Core.MsoTriState.msoFalse,
                       Microsoft.Office.Core.MsoTriState.msoCTrue, 1, 200, 40, 50);
    The problem is that the AddPicture funtion uses X,Y coordinates to place the picture. So it's hard and messy to place the picture exactly in the cell that you want.

    Is there is a function where I can place the picture right into the exact cell by using the range function?

    Edit: I would like to point out there ideally I would like to use this code:

    ThisWorkBook = ThisApplication.Workbooks.Open(_stFileName,missing,missing,5,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing); 
    Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1]; 
    Excel.Range oRange = (Excel.Range)ThisSheet.Cells[10,1]; 
    Image oImage = Image.FromFile(_stLOGO); 
    But, the problem with this code is that YOU CANNOT SPECIFIY the image size. So if your original JPG is 1000x1000 then that's how big it'll look once you pasted into Excel.

    Thanks again. Hope this helps a few others out there.
    Last edited by mav8; 06-29-2006 at 03:31 AM.

Similar Threads

  1. how to clone database using mysql
    By zarien in forum Database
    Replies: 1
    Last Post: 05-17-2006, 03:27 AM
  2. Replies: 1
    Last Post: 01-26-2006, 10:54 PM
  3. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  4. SQL Tutorial (Answer Q's & post your reply)
    By bigbastard4 in forum Database
    Replies: 2
    Last Post: 05-16-2001, 06:24 PM
  5. Replies: 0
    Last Post: 04-06-2000, 06:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.