我使用VS2010上的ASP.NET Web工程中的工作,C#,我希望我的用戶獲得從表格報告excel文件輸出,我知道如何創建CSV文件,但我要去創建EXCEL文件,例如一個按鈕,當點擊該按鈕時,用戶可以使用EXCEL格式下載表格數據,另外我還會在excel中寫入一些unicode文本(波斯語,波斯語),我有什麼選擇?目前我使用下面的代碼來生成CSV文件:創建EXCEL在ASP.NET
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + "db" + ".csv");
Response.Charset = "";
Response.ContentType = "application/text";
StringBuilder sb = new StringBuilder();
sb.Clear();
//append new line
sb.Append("\r\n");
for (int i = 0; i < tblDatabase.Rows.Count; i++)
{
//add separator
for (int j = 0; j < tblDatabase.Rows[0].Cells.Count; j++)
sb.Append(Table3.Rows[i].Cells[j].Text + ",");
//append new line
sb.Append("\r\n");
}
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();
謝謝你,你的回答非常簡單而有效!我的文件格式是XLS,是用於office 2003嗎?當我嘗試使用office 2007打開它時,它向我提出了一個關於格式的問題,我應該將其擴展名更改爲XLSX嗎? –