您好,登錄后才能下訂單哦!
protected void ExportExcel(DataTable dt)
{
HttpResponse Response;
Response = System.Web.HttpContext.Current.Response;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.AppendHeader("Content-Disposition", "attachment;filename=Integral Summary.xlsx");
Response.AppendHeader("Content-Type", "application/ms-excel");
StringBuilder colHeaders = new StringBuilder();
StringBuilder lis_item = new StringBuilder();
DataRow[] myRow = dt.Select();
int cl = dt.Columns.Count;
for (int i = 0; i < cl; i++)//獲取標題列名稱
{
colHeaders.Append(dt.Columns[i].ColumnName + "\t");
}
colHeaders.Append("\n");
Response.Output.Write(colHeaders);
colHeaders.Clear();
foreach (DataRow row in myRow)//每行內容
{
for (int j = 0; j < cl; j++)//獲取每列內容
{
if (j == (cl - 1))//最後列內容換行
{
lis_item.Append(row[j].ToString() + "\n");
}
else
{
lis_item.Append(" " + row[j].ToString() + "\t");
}
}
Response.Output.Write(lis_item);
lis_item.Clear();
}
Response.Output.Flush();
Response.End();
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。