2 Replies - 2573 Views - Last Post: 03 February 2013 - 12:36 AM Rate Topic: -----

#1 arny1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 24-July 09

Export grdiview to excel problem

Posted 24 July 2009 - 02:37 AM

Hi There,

I had this post before,but I have some problems when I add a header for specific charcter set,and also add some additional data,

here is my code;
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=aname.xls");
string header = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title></title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1254\" />\n<style>\n</style>\n</head>\n<body>\n";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
Response.Charset = "windows-1254"; //ISO-8859-9  windows-1254
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
gvMaster.AllowPaging = false;
gvMaster.RenderControl(hw);

//write the output
Response.Output.Write(header.ToString());
Response.Output.Write("Some title\n");
Response.Output.Write("\n");

//to write current date and time
System.DateTime tDate1 = System.DateTime.Now;
Response.Output.Write(tDate1);
Response.Output.Write("\n");
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();



The problem is when I add header next Line is not working and the Title and system time are all in one row,

My question is how can I write the gridview to specific row in output excel or how can I add some line on top of gridview and also how can I add some style to title?

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Export grdiview to excel problem

#2 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: Export grdiview to excel problem

Posted 24 July 2009 - 07:21 AM

Well first you will need to define, for yourself, what Excel version are you going to support with the export format? Once figure out the minimal Excel Version you want the export format to support, you then need to find the Excel.DLL file for all the versions from minimum Excel on up. You can usually find them in the Program Files/Microsoft Office directory and if not there go here and you should be able to get it from that package.

Once you get all that fun stuff, then all you need to do is attach to the DLL to open up its member namespaces, methods, classes, and structures.

now you have the tools necessary to do what you are trying to do. Next i would suggest going here, for VB, or here, for C#, or here, for C++.

They are really easy to follow guides usually....you may have think and deduce some parts but as a whole the instructures that you get from most of the sites you search through google, will give you just about 90% of what you need and the rest usually can be obtained through MSDN.
Was This Post Helpful? 0
  • +
  • -

#3 softwareskill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-February 13

Re: Export grdiview to excel problem

Posted 03 February 2013 - 12:36 AM

Here you can see, how to Export all the rows of Gridview, ncluding the header row to excel in c# as well as vb http://www.freedotne...el-spreadsheet/

You need to specifically export each row of gridview including header row. here's information on Export Gridview to excel in c# as well as vb http://www.freedotne...el-spreadsheet/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1