Hi,
I had a gridview with images,while i export the grid view to excel all the images are embeded into excel in the open mode.
if i try to save the exported data the images are missing.Please help me how to achieve this.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Master BillaPosted Oct 22, 2009, 4:31 AM
use this code to this, just copy and paste to ur button click.
private void Excel_Export()
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
//Apply text style to each Row
row.Attributes.Add("class", "textmode");
}
GridView1.RenderControl(hw);
//style to format numbers to string
string style = @"";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
thank you
Amit ChoudharyPosted Oct 22, 2009, 2:57 AM
RPosted Oct 22, 2009, 1:58 AM
Thanks for the reply.
My idea is to upload a grid with images into excel,so i can achieve this by just rendering the Grid into Streamwriter.By this approch images are getting referenced by their url's, so if user opens the exported excel it is fine and if he saves it also works untill the connectivity between the user machine and the server is avail.
Thanks
Rakesh
Amit ChoudharyPosted Oct 21, 2009, 5:54 AM
Export the html page With images into excel:
string GridName="Demo"
HttpContext.Current.Response.ContentType ="application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" & GridName & ".xls");
HttpContext.Current.Response.Charset = "";
System.IO.StringWriter tw=new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw =new System.Web.UI.HtmlTextWriter(tw);
Page.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
Don't forget Mark the answer