- 爱易网页
-
C#教程
- 小弟我引用别人的一个类,其中一个参数是System.Web.HttpResponse response,引用的时候如何声明?还有,麻烦大家帮小弟我看看这个类,小弟我有很多不
日期:2014-05-19 浏览次数:20922 次
我引用别人的一个类,其中一个参数是System.Web.HttpResponse response,引用的时候怎么声明?还有,麻烦大家帮我看看这个类,我有很多不
namespace FileTo
{
public class Class1
{
/// <summary>
/// grid转excel
/// </summary>
/// <param name= "pa "> 页面HttpResponse输入 </param>
/// <param name= "gridview "> 传入需要生成excel的gridview </param>
/// <param name= "filename "> 生成的文件名 </param>
/// <param name= "path "> 生成的地址 </param>
public static void export(System.Web.HttpResponse pa, System.Web.UI.WebControls.GridView gridview, string filename, string path)
{
System.Web.HttpResponse httpresponse = pa;
httpresponse.AppendHeader( "content-disposition ", "attachment;filename= " + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); //filename= "*.xls ";
httpresponse.ContentEncoding = System.Text.Encoding.GetEncoding( "gb2312 ");
httpresponse.ContentType = "application/ms-word ";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
gridview.RenderControl(hw);
string filepath = path + filename;
System.IO.StreamWriter sw = System.IO.File.CreateText(filepath);
sw.Write(tw.ToString());
sw.Close();
downfile(httpresponse, filename, filepath);
httpresponse.End();
}
/// <summary>