现在我用它来导出转发器(带有多个嵌套转发器)excel:
protected void ExportToExcel(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=finance.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); rptMinistry.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }
但这不是我想要的.相反,它在excel文件中给我html(虽然数据在那里)这是我得到的(每行是excel表中的一个单元格):
LOR In Development MOD Air Force Hellfire (AGM-114) Follow On 10-Mar-08 $50,000,000.00 $0.00 LOR In Development MOD Air Force Precision Strike Mi-17 (block 20) 17-May-08 $20,100,000.00 $0.00
等等...现在数据是正确的,但我怎样才能让它在电子表格中正确显示?
您需要将所有这些都包含在表标记中.Excel可以理解HTML表结构.
尝试:
Response.Write("