我一直在尝试将存储过程导出为Excel工作表,但是datetime
类型的列不会在结果表中呈现
这是一个简化的代码示例
System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
string fileName = "";
using (dbentities ctx = new dbentities())
{
grid.DataSource = ctx.GetRecord().Select(x => new { x.RequestID, x.CreatedDate }).ToList();
grid.DataBind();
fileName = "";
using (StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath(fileName)))
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
grid.RenderControl(hw);
}
}
}