下载附加的excel文件后,将Gridview导出到Excel网格线未显示 [英] Export Gridview to Excel gridline not showing after download attached excel file
本文介绍了下载附加的excel文件后,将Gridview导出到Excel网格线未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我正在使用下载附加excel文件的代码。
下载后这个excel文件excel的Gridline自动为false 。
表示Excel网格线未显示。
我的代码: -
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 =真正的跨度>));
使用(StringWriter sw = new StringWriter())
{
使用(HtmlTextWriter htw = new HtmlTextWriter(sw))
{
Table table = new Table();
// 包括网格线设置
table.GridLines = gv.GridLines;
// 将标题行添加到表中
< span class =code-keyword> 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();
}
}
请帮助
解决方案
< blockquote> //试试这个
Table table = new Table();
table.BorderStyle = BorderStyle.Solid;
table.BorderWidth = new Unit(1);
table.BorderColor = System.Drawing.Color.Black;
table.GridLines = GridLines.Both;
//你也可以直接渲染GridView
Hello
I am using a code for download attached excel file.
After download this excel file Gridline of excel is automatically false.
Means Excel gridline not showing.
my code:-
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();
}
}
please help
解决方案
//Try this
Table table = new Table(); table.BorderStyle = BorderStyle.Solid; table.BorderWidth=new Unit(1); table.BorderColor = System.Drawing.Color.Black; table.GridLines = GridLines.Both;
//You can also render the GridView directly
这篇关于下载附加的excel文件后,将Gridview导出到Excel网格线未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文