【发布时间】:2016-01-29 04:13:26
【问题描述】:
我的网站上有一个网页,允许我从该页面下载图表并将其添加到 Excel 工作表中。但是,在图表的位置显示了一个带有“当前无法显示此图像”字样的红色 x 按钮。我在网上尝试了很多解决方案,但都显示了相同的结果。
这是我的代码:
protected void ExcelDl_Click(object sender, EventArgs e) {
string tmpChartName = "test2.jpg";
string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;
Chart1.SaveImage(imgPath);
string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=test.xls;");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
string headerTable = @"<Table><tr><td><img src='" + imgPath2 + @"' \></td></tr></Table>";
Response.Write(headerTable);
Response.Write(sw.ToString());
Response.End();
}
我们将不胜感激任何形式的帮助。另外,请注意我已经在我的 Web.config 中添加了所需的代码。
【问题讨论】:
标签: c# asp.net excel export-to-excel bar-chart