我正在生成 excel 文件,它在本地主机中工作正常,但在 IIS 中不工作。我有一个模型从我打开弹出窗口的地方弹出,使用window.open
方法是编写以下代码以生成 excel 文件。
public void GenerateExcelFile(DataTable dt)
{
Response.Clear();
Response.Buffer = true;
string filename = "abc.xls";
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView gv = new GridView();
gv.AutoGenerateColumns = true;
gv.DataSource = dt;
gv.DataBind();
gv.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
请帮我解决问题。