I need to export some data from an asp.net page in order to succeed, so I mainly use the table to create the custom headers I need, and then the GridView. All data is displayed correctly when exporting to excel, but when I added the logo image in html, it does not appear in the Excel file when exporting.
Since I need to export it to Excel 2007 or later, I know that I can use the Open XML material from Microsoft to export data, the problem is that I already have everything that is done for the code, and I would like to know this another way to do this, and not do it all over again with Open XML.
If there is no way to do this without using Open XML, can someone show me how I can export data to it? I tried once, but I did not have much success. = /
By the way, I am using C #.
Thanks in advance!
I updated the code and now it looks like this, but I still do not see the image ... = /
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
frmPlanoAcao.RenderControl(htmlWrite);
StringWriter w = new StringWriter();
HtmlTextWriter t = new HtmlTextWriter(w);
imgLogo.RenderControl(t);
var byte_array = System.Text.Encoding.ASCII.GetBytes(w.ToString());
Response.Write(stringWrite.ToString());
this.EnableViewState = false;
Response.Clear();
Response.Buffer = false;
Response.Charset = "ISO-8859-1";
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1252);
Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", "plano_acao.xls"));
Response.ContentType = "application/vnd.ms-excel";
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
Response.Write(getExcelStyling());
Response.OutputStream.Write(byte_array, 0, byte_array.Length);
Response.Write(stringWrite.ToString());
Response.Write("</body>");
Response.Write("</html>");
Response.End();
source
share