Response.Clear(); System.IO.StringWriter tw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); Response.ContentType = "application/msexcel"; //Response.AddHeader("Content-disposition", "attachment;filename=MyFiles.xls"); Response.AddHeader("Content-disposition", string.Format("attachment;filename=MyFiles.xls; Gridlines=true")); using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Table table = new Table(); // include the gridline settings table.GridLines = gv.GridLines; // add the header row to the table if (gv.HeaderRow != null) { table.Rows.Add(gv.HeaderRow); } foreach (GridViewRow row in gv.Rows) { table.Rows.Add(row); } table.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End(); } }
Table table = new Table(); table.BorderStyle = BorderStyle.Solid; table.BorderWidth=new Unit(1); table.BorderColor = System.Drawing.Color.Black; table.GridLines = GridLines.Both;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)