按照导出gridview的方法,倒出来的文档是这样的:
<span id="Label1">112233444</span>如果我要去掉<span id="Label1"></span>的标记,只要112233444,怎么实现呢?谢谢大家我的类的代码: /// grid转word
/// </summary>
/// <param name="pa">页面HttpResponse输入</param>
/// <param name="gridview">传入需要生成excel的gridview</param>
/// <param name="filename">生成的文件名</param>
/// <param name="path">生成的地址</param>
public static void toword(System.Web.HttpResponse pa, System.Web.UI.WebControls.Label Label1, string filename, string path)
{
System.Web.HttpResponse httpresponse = pa;
httpresponse.AppendHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); //filename="*.doc";
httpresponse.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
httpresponse.ContentType = "application/msword";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Label1.RenderControl(hw); string filepath = path + filename;
System.IO.StreamWriter sw = System.IO.File.CreateText(filepath);
sw.Write(tw.ToString());
sw.Close(); httpresponse.End();
}
<span id="Label1">112233444</span>如果我要去掉<span id="Label1"></span>的标记,只要112233444,怎么实现呢?谢谢大家我的类的代码: /// grid转word
/// </summary>
/// <param name="pa">页面HttpResponse输入</param>
/// <param name="gridview">传入需要生成excel的gridview</param>
/// <param name="filename">生成的文件名</param>
/// <param name="path">生成的地址</param>
public static void toword(System.Web.HttpResponse pa, System.Web.UI.WebControls.Label Label1, string filename, string path)
{
System.Web.HttpResponse httpresponse = pa;
httpresponse.AppendHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); //filename="*.doc";
httpresponse.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
httpresponse.ContentType = "application/msword";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Label1.RenderControl(hw); string filepath = path + filename;
System.IO.StreamWriter sw = System.IO.File.CreateText(filepath);
sw.Write(tw.ToString());
sw.Close(); httpresponse.End();
}
只要:
string a = Label.Text;
hw.Write(a);就可以了。
‘但是不知道这样没有又什么不好的后果如果我要保存里面的Html这样是不是就不行了?怎么保存里面的html呢?必须要用Label