将包含图像的页面导出到 Excel
我的页面包含 2 个 gridview 和 2 个 mschart。 我想将此页面导出到 Excel。 为此,我将这些控件放入面板中并编写以下代码:
Response.Clear();
Response.ContentType = "application/vnd.msexcel";
Response.AddHeader("content-disposition", "attachment; filename=rapor.xls");
Response.ContentEncoding = System.Text.Encoding.Default;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
panel1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
当此代码运行时,除了图表之外,一切正常。 他们并不是来表现出色的。 我该怎么做?
I have page which contains 2 gridview and 2 mschart. ı want to export this page to excel. For this purpose I took these controls into a panel and write this code:
Response.Clear();
Response.ContentType = "application/vnd.msexcel";
Response.AddHeader("content-disposition", "attachment; filename=rapor.xls");
Response.ContentEncoding = System.Text.Encoding.Default;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
panel1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
When this code run, everything is ok except charts. They aren't coming to excel. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是 100% 确定,但我猜图表被写入内存以显示在页面上,因此它们在请求后消失。
HTML 不允许在代码中嵌入图像,您必须引用外部文件。
选项:
Not 100% sure, but I guess that the charts are written to memory to display on the page, so they vanish after the request.
HTML does not allow an image to be embedded in the code, you have to reference a external file.
Options:
尝试以下代码。 我已经在
本地 IIS
上进行了测试,它工作正常,并且在网格数据顶部包含诸如标题图像/徽标
之类的图像。 您必须将图表作为图像包含在内。您可以根据您的要求调整图像的高度和宽度。
标记需要相同的高度和宽度设置。
Try the following code. I have tested at
local IIS
, it is working properly and including the image likeHeader Image/Logo
on top of the grid data. you have to include your chart as images.you can adjust your image's height and width as per your requirement. Same height and width setting will be required for the
<TD>
tag.