想知道是否有人可以提供帮助。我有一个.ashx文件,它创建一个excel文档,其中填充了C#DataGrid。这一切都很好,唯一的问题是当我打开excel文档时,自动网格线被关闭。有没有办法启用它们?
提前致谢, 空气
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.Charset = "";
response.ContentEncoding = System.Text.Encoding.Default;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"dataImportTemplate.xls\"");
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[0];
dg.ShowHeader = false;
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
}
}
答案 0 :(得分:0)