I am trying to create an excel file from datagrid in my asp.net page using the below code.I am able to create the excel file.But the created excel file does not has the cell borders.Without the cell borders,it looks like a word document.
我正在尝试使用下面的代码在我的asp.net页面中从datagrid创建一个excel文件。我能够创建excel文件。但是创建的excel文件没有单元格边框。没有单元格边框,它看起来像一个word文档。
My code is
我的代码是
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=asas.xls");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(dgShipping);
dgShipping.AllowPaging = false;
DisplayRecords();
dgShipping.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
dgShipping.AllowPaging = true;
Any workarounds for this ? Thanks for help
这有什么变通方法吗?感谢帮助
1 个解决方案
#1
1
Add the following 2 Lines
after "RenderControl" Line. It will resolve your issue and grid lines will be added.
在“RenderControl”行之后添加以下2行。它将解决您的问题,并将添加网格线。
string style = @"<style> TABLE { border: 1px solid red; } TD { border: 1px solid red; } </style> ";
Response.Write(style);
Change the color and line thickness as per your requirements.
根据您的要求更改颜色和线条粗细。
#1
1
Add the following 2 Lines
after "RenderControl" Line. It will resolve your issue and grid lines will be added.
在“RenderControl”行之后添加以下2行。它将解决您的问题,并将添加网格线。
string style = @"<style> TABLE { border: 1px solid red; } TD { border: 1px solid red; } </style> ";
Response.Write(style);
Change the color and line thickness as per your requirements.
根据您的要求更改颜色和线条粗细。