我正在使用我的代码
将DataTable导出到excel文件中public void ExportGridToExcel(DataTable dataTable)
{
string str = "";
foreach(DataColumn col in dataTable.Columns)
{
str += col.ColumnName + "\t";
}
foreach(DataRow row in dataTable.Rows)
{
str += "\n";
foreach (DataColumn col in dataTable.Columns)
{
str += row[col.ColumnName] + "\t";
}
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Report.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Write(str);
Response.End();
}
它将数据导出到excel中,除了我的一个列数据打印为######之类的
RandomValue Name CreatedDate
0010A DISPLAY BANNER IF AF #######
0010B BANNER ON DRIVER PAG #######
0018B NEW CRE BUTTON #######
0020B NEW INFO SIDEBAR #######
0021A NOT IQ EXPERIENCE #######
但如果我要在excel中扩展第三列,那么它会正确显示值。有没有办法让我以编程方式解决这个问题?