In this post, we want to discuss the way to export image to excel using c# html output. Before we get started, if you want to know about Software Development Life Cycle, please go through the following article: What is SDLC? What is SDLC model overview?
Export data from an asp.net page to an Excel file and I’m basically just outputting HTML to the XLS file where I want to embed an image. The image file has to be in binary form in the content.
I have to get images in StringWriter and use System.Text.Encoding.ASCII.GetBytes(stringwriter string) in an array of bytes. then write these as outputStream.Write(byte_array, 0, byte_array.Length); where outputstream is HttpContext Response outputstream.
1 2 3 4 5 6 |
string filePath = Server.MapPath(lblReportLogo.Text); System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(filePath); string imagepath = string.Format("<img src='{0}' width='{1}' height='{2}'/>", filePath, 100, 40); String headerTable = @"<div style='text-align:center'>"+ imagepath +"</div>"; Response.Write(headerTable); imgPhoto.Dispose(); |
Leave a Comment