Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing Project in shopping cart.if user select an item ,i want to send
Item Image ,Item Code, Item Name as excel attachment.
Firstly i add all these datas in gridview and I use following code.

C#
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridview .RenderControl(htw);

System.Text.Encoding enc = System.Text.Encoding.ASCII;
byte[] myByteArray = enc.GetBytes(sw.ToString());
System.IO.MemoryStream memAtt = new System.IO.MemoryStream(myByteArray, false);
mail.Attachments.Add(new Attachment(memAtt, "product.xls"));


It working fine but,The attachment excel display details except item image.is there any way to display image in attached excel sheet.
Posted
Updated 21-Jun-12 23:20pm
v2

1 solution

try like this
C#
//generating excel
  Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=NAVEEN.xls");
        Response.Charset = "";

        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        GridView1.RenderControl(htmlWrite);
        Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
        Response.Write(stringWrite.ToString());
        Response.End();

or
see this link similar discussion
http://forums.asp.net/t/1639973.aspx[^]
 
Share this answer
 
v3
Comments
Deepthy.P.M 22-Jun-12 7:17am    
using this your code image not saved in excel.any other solution
vangapally Naveen Kumar 22-Jun-12 8:46am    
See Following links you will get some idea
http://forums.asp.net/p/1089950/1649165.aspx
http://www.codeproject.com/Articles/8405/Placing-images-in-Excel-using-automation
Deepthy.P.M 27-Jul-12 0:32am    
i use openoffice dll .My problem solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900