Inserting an Image into Excel from a C# ASP.Net web application RRS feed

  • Question

  • I use Visual Studio 2008, C#, and here a Web interface.

    I create an Excel application with Excel 2010.

    I am developing an ASP.NET application that obtains data from a SQL Server DB and creates an Excel workbook and sheets and populates the worksheet. This works just fine. I need to insert 2 logos at the top of the form. Currently I merge the first 8 columns into one cell, then the next several cells into a single cell, and finally the remaining cells into a 3rd cell. I need to put the logos, 1 each, into the 1st and 3rd merged cells at the top in row 1. I have used this code before:

    Excel.Pictures thePic = oSheet.Pictures(Type.Missing) as Excel.Pictures;

    thePic.Insert(Server.MapPath("~/Images/Shape.png"), Type.Missing).Select(oSheet.Cells[1, 2] as Excel.Range);

    This will grab the picture, but it will not insert it into a particular cell or set of cells, it always goes to Sheet1([1,1]).

    So, I have read a lot online but am unable to figure out the way to accomplish what I want. I have read that it is best to read the picture/image file into the clipboard and then paste it, but cannot pull it into the clipboard. I would really appreciate any assistance I could get. I need to finish this program up and move on. Many thanks for your time and any assistance rendered.

    Noel Zike

    • Moved by Sabah ShariqMVP Monday, May 28, 2018 3:05 PM Moved From Visual C#
    Monday, May 28, 2018 1:32 PM

All replies

  • Dieter,

    Your ASP.Net application is a Javascript solution which runs in the browser. Already a long time do all browsers protect that there is any action on the client computer (beside cookies) without save actions from the client. 

    Therefore if your intention is to put that image in an excel file on the client computer forget it. 


    Monday, May 28, 2018 3:01 PM
  • Hi Dieter Wels,

    This is Visual C# forum. As your issue is related to Web, please ask your question into ASP.Net forum for getting quick response. I am moving your thread to off-topic.


    Your understanding and cooperation will be grateful.

    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Monday, May 28, 2018 3:04 PM