Word formate中未显示网格视图的内容 [英] Contents of Grid View are not displaying in Ms Word formate
本文介绍了Word formate中未显示网格视图的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么GridView的数据未显示在ms Word文档中
我的CS代码在下面给出
Why data of GridView are not displaying in ms word document
My cs code is given below
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.ClearContent();
Response.Clear();
Response.Charset = "";
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.doc"));
Response.ContentType = "application/ms-word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
gvdetails.AllowPaging = false;
gvdetails.DataBind();
dg.HeaderStyle.Font.Bold = true;
dg.HeaderStyle.Font.Size = 10;
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
推荐答案
尝试一下,
Try this,
Response.Clear();
HtmlForm form = new HtmlForm();
string attachment = "attachment;filename=Customers.doc";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-word";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(gvdetails);
this.Controls.Add(form);
form.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
这篇关于Word formate中未显示网格视图的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文