代码如下:
DataTable dt = DBAccess.GetDataTable("Test.GetJobsData", null);
if (dt.Rows.Count > 0)
{
StringBuilder sb = new StringBuilder();
for (int j = 0; j < dt.Columns.Count - 1; j++)
{
sb.Append(dt.Columns[j].ColumnName).Append("\t");
}
sb.Append(dt.Columns[dt.Columns.Count - 1].ColumnName).Append("\n");
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count - 1; j++)
{
sb.Append(dt.Rows[i][j].ToString()).Append("\t");
}
sb.Append(dt.Rows[i][dt.Columns.Count - 1].ToString()).Append("\n");
}
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;filename=a.xls");
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.ContentType = "application/vnd.ms-excel";
Response.Write(sb.ToString());
Response.End();
导出来后,有些行的列不在同一行了,在另外一行了,要怎么解决,是不是与文本内容有关
看下中间是不是有制表符,制表符会引起这个问题。
.Append("\n") 这是什么鬼?
换行啊