本文介绍了导出到Excel后图像不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 下面是我如何将页面导出到excel文件的代码,但导出后不会显示excel中的图像。 图像位于服务器目录/image/logo.jpg,下载excel(内部下载文件夹)后,图像找到C:\ Users \ user \的路径下载\ image.\\logo.jpg,如何在excel文件中包含图像? StringWriter strWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter); Response.Clear(); Response.Buffer = true ; Response.AddHeader( content-disposition, attachment; filename = MyFile.xls); Response.Charset = ; Response.ContentType = application / vnd.ms-excel; i也尝试导出为pdf,但失败了,提到pdf文件已损坏。任何建议?代码如下 Response.AddHeader( content-处置, attachment; filename = MyFile.pdf); Response.ContentType = application / pdf; 更新: i尝试了几种方法,都返回相同的结果。 excel文件显示:< img src = http:// localhost:49524 / logo.jpg /> 而不是图像文件本身.. 解决方案 Hii i认为它可以帮到你...... 使用Reporting Services报告生成将DataGridView导出为Excel / PDF /图像文件 [ ^ ] 乐于助人。 试试这个: Response.Clear(); Response.AddHeader( content-disposition, attachment; filename = filename.xls); Response.Charset = ; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = application / vnd.ms-excel; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); DataGrid.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); string tag = < img src = imagepath& filename />; Response.Write(tag); Response.End(); 如果你试试那个,谷歌也可以给你很多建议将图像导出到Asp.net中的Excel [ ^ ]。 --Amit below is the code how i export the page to excel file, but the image inside excel is not display after export.the image is at server directory, /image/logo.jpg , after i download the excel(inside download folder), the image find the path from "C:\Users\user\Downloads\image\logo.jpg" , how can i include the image inside the excel file?StringWriter strWriter = new StringWriter();HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);Response.Clear();Response.Buffer = true;Response.AddHeader("content-disposition", "attachment;filename=MyFile.xls");Response.Charset = "";Response.ContentType = "application/vnd.ms-excel";i also tried to export to pdf, but failed, mention that the pdf file is corrupted. any advice? code as belowResponse.AddHeader("content-disposition", "attachment;filename=MyFile.pdf");Response.ContentType = "application/pdf";UPDATE:i tried few approaches, all return the same result.the excel file display: <img src="http://localhost:49524/logo.jpg"/> instead of the image file itself.. 解决方案 Hiii think it may helps you....Exporting a DataGridView to an Excel/PDF/image file by using Reporting Services report generation[^]Happy to Help.Try this:Response.Clear();Response.AddHeader("content-disposition", "attachment;filename=filename.xls");Response.Charset = "";Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.ContentType = "application/vnd.ms-excel";System.IO.StringWriter stringWrite = new System.IO.StringWriter();HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);DataGrid.RenderControl(htmlWrite);Response.Write(stringWrite.ToString());string tag = "<img src="imagepath & filename" />";Response.Write(tag);Response.End();And also Google can give you lots of tips if you''ll try that Export image To Excel in Asp.net[^].--Amit 这篇关于导出到Excel后图像不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 13:32