0
我希望将我的数据表导出为excel。导出为Excel字符串列转换为日期
我有具有价值像2/5 1/5 ... 导出后这个数据到Excel它看起来02.May 01.May(日期格式)
我怎么能导出此列列,以便excel将其视为字符串而不是将其转换为日期。
这是我ExportToExcel方法
protected void ExportToExcel()
{
DataTable dt = new DataTable();
dt = Session["aaa"] as DataTable;
if (dt.Rows.Count > 0)
{
string filename = "DownloadMobileNoExcel.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;
dgGrid.DataBind();
//Get the HTML for the control.
dgGrid.RenderControl(hw);
//Write the HTML back to the browser.
//Response.ContentType = application/vnd.ms-excel;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
请看这里:http://aspsnippets.com/Articles/Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-VBNet.aspx - 它基本上使用一个textmode css类来将列格式设置为文本格式。 –