By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,438 Members | 1,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,438 IT Pros & Developers. It's quick & easy.

export gridview images to excel

P: 3

I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The problem is, the image won't display unless I'm connected to the Internet or if I use a relative path and have the image stored relative to the excel file. Is it possible to "embed" the image from the gridview into the excel workbook so I could give the excel workbook to anyone without needing connection to the Internet or having the images locally. I'd like it all to be one excel file.

This is the code I'm using to create the excel workbook.

Expand|Select|Wrap|Line Numbers
  1.         Response.Clear();
  2.         Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
  3.         Response.Charset = "";
  4.         Response.Cache.SetCacheability(HttpCacheability.NoCache);
  5.         Response.ContentType = "application/excel";
  6.         System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  7.         System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  8.         this.GridView1.RenderControl(htmlWrite);
  9.         Response.Write(stringWrite.ToString());
  10.         Response.End();
I'm open to any other suggestions that might work to get basically an image and some data into an excel workbook from a mysql database. I'm using ASP.NET C#

Jul 31 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 3,405
moved to .NET forum. hopefully you will get better responses here.

Aug 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.