1

我有一种情况,我必须在不使用 Interop (MicroSoft) 的情况下将 gridview 和图表导出到同一个 excel 文件中。这是我的代码

string attachment = "attachment; filename=test.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);

// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
gvReport.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(gvReport);
frm.RenderControl(htw);

String imagepath = "<img src='" + Server.MapPath("../Image1.png") + "' />";

Response.Output.Write("\n<html>\n<body>");

Response.Output.Write("<table width='800' align='center' style='text-align:center'");
Response.Output.Write("<tr><td colspan='10' align='center'><div align='center' style='text-align:center'>" + imagepath + "</div></td></tr>");

Response.Output.Write("</table>");
Response.Output.Write("\n</body>\n</html>");

Response.Flush();
//Response.End();

Response.Write(sw.ToString());
Response.End();

我哪里错了?

4

0 回答 0