如何将数据导出到带有图像的gridview到excel / pdf? [英] How to export the data to gridview with image to excel/pdf?
本文介绍了如何将数据导出到带有图像的gridview到excel / pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数据导出到网格视图,图像为excel / pdf。在数据表中,我使用Image Path从DB绑定图像名称(比如〜/ Smart_PDF / FileStore / Extract_Images / 28082017093350image.jpg)
我有什么试过:
I want to export the data to Grid view with image to excel/pdf. In the data table I am binding Image name from DB with Image Path(say ~/Smart_PDF/FileStore/Extract_Images/28082017093350image.jpg)
What I have tried:
<pre> System.Data.DataTable dt = new System.Data.DataTable();
string strHead = string.Empty;
string FileName = string.Empty;
if (dsCustomerDetailsPDF.Tables[0].Rows.Count > 0)
{
dt = dsCustomerDetailsPDF.Tables[0];
if (dt.Rows[0]["FileType"].ToString() == "KYC")
{
strHead = "Customer KYC Template";
FileName = "Customer_KYC_Template";
}
string[] existingcol = { "CustomerImage", "CreatedDate", "MODE", "CurrentStatusId", "OriginalFileName", "FileType", "UploadedBy", "UploadedDate" };
foreach (string colName in existingcol)
{
dt.Columns.Remove(colName);
}
grdExport.DataSource = dt;
grdExport.DataBind();
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + FileName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
grdExport.RenderControl(htmlWrite);
StringBuilder strbn = new StringBuilder();
strbn.Append("<div style='text-align:center;font-weight:bold;background-color:White; width:100%;font-size:large'> " + strHead + "</div>");
strbn.Append(stringWrite.ToString());
string style = @"<style> td { mso-number-format:\@;} </style>";
Response.Write(style);
Response.Write(strbn.ToString());
Response.Flush();
Response.End();
推荐答案
检查这个将图像导出到Excel,PDF,Word [ ^ ]
这篇关于如何将数据导出到带有图像的gridview到excel / pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文