您的位置:首页 > Web前端 > HTML

利用获取页面html,导出excel

2007-12-19 14:55 417 查看
public void CreateExcelxxbb(string FileName) //

{

WebRequest mywebrq;

WebResponse mywebresp;

StreamReader sr;

string strexcel = this.sqltoexcelxx();

string strurl = Request.Url.ToString();

strurl = strurl.Substring(0, strurl.LastIndexOf("/") + 1);

strurl = strurl + "fel_yzbb.aspx?str=" + strexcel + "&stid=" + this.drpstname.SelectedValue.Trim() + "&reid=" + this.rbtrole.SelectedValue.Trim();

//int n = strurl.LastIndexOf("/");

//strurl = strurl.Substring(0, n - 5);

mywebrq = WebRequest.Create(strurl);

mywebresp = mywebrq.GetResponse();

sr = new StreamReader(mywebresp.GetResponseStream());

HttpResponse resp;

resp = Page.Response;

resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);

string str = sr.ReadToEnd();

str = str.Substring(str.IndexOf("<div>"));

str = str.Substring(0, str.LastIndexOf("</div>") + 6);

//str = str.Substring(str.IndexOf("<!--biaojikaishi-->")+19);

//str = str.Substring(0, str.IndexOf("<!--biaojijieshu-->"));

resp.Write(str);

//写缓冲区中的数据到HTTP头文件中

resp.End();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: