想知道是否有人可以提供帮助。我有一个 .ashx 文件,它创建了一个填充有 C# DataGrid 的 excel 文档。这一切都很好,唯一的问题是当我打开 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());
}
}