62,271
社区成员
发帖
与我相关
我的任务
分享
public static void HtmlExportFile(HttpResponse response, ArrayList Controls, string Coding, string FileName, string style)
{
HtmlExportFile(response, Controls, Coding, FileName, "application/ms-excel", style);//application/ms-excel;application/octet-stream;application/ms-word
}
public static void HtmlExportFile(HttpResponse response, ArrayList Controls, string Coding, string FileName, string FileType, string style)
{
response.Clear();
response.ClearHeaders();
response.ClearContent();
response.AddHeader("content-disposition", "attachment;filename=" + FileName);
//Response.Charset = Coding;
response.ContentType = FileType; //"application/octet-stream";
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringWrite = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
Control temp = null;
for (int i = 0; i < Controls.Count; i++)
{
temp = Controls[i] as Control;
temp.RenderControl(htmlWrite);
}
//response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.Write(style);
response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");// GetEncoding(Coding);// GetEncoding("GB2312");//.UTF8;// GetEncoding("UTF-8");
response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
response.Write(stringWrite.ToString());
response.Flush();
response.Close();
response.End();
}