所见即所得的导出到excel的方法
来源:互联网 发布:the eric python ide 编辑:程序博客网 时间:2024/04/30 02:54
因为Excel可以打开html文件,所以我们可以把html文件的内容输出到一个xls文件里,这样就实现了所见即所得的输出。
public void outputExcel()
{
string printUrl = "要输出的报表文件.aspx”; // 此文件就是一个输出数据表格的网页,可以是html也可以是aspx
string printText = GetterUtil.GetUrlContent(printUrl);
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment; filename=输出文件名.xls");
Response.Write(printText);
Response.End();
}
public static string GetUrlContent(string printUrl)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(printUrl);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
StringBuilder ret = new StringBuilder();
int bufferLengh = 8 * 1024; // 16K
char[] buf = new char[bufferLengh];
int len = sr.Read(buf, 0, bufferLengh);
while (len > 0)
{
ret.Append(new string(buf, 0, len));
len = sr.Read(buf, 0, bufferLengh);
}
return ret.ToString();
}
- 所见即所得的导出到excel的方法
- 所见即所得的导出到excel的方法
- ehlib导出EXCEL 所见即所得
- gridview数据源导出到EXCEL的方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- 数据导出到Excel的方法C#
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- <转>ListView导出到Excel的方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的几个方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- DataGridView导出到Excel的三个方法
- Resharper进阶:简要介绍
- 十个习惯让你精通新的开发技术
- .net学习路线
- 英文名:Yuma
- GridView当数据源为空时如何实现显示表头
- 所见即所得的导出到excel的方法
- 数据绑定控件加入序号
- IbatisNet maps中select,insert,update中动态字段
- Ilist 转换成 DataSet
- Ilist导出Excel数据
- 'asp 获取网页地址及参数
- Iframe自适应其加载的内容高度
- .net中如何用webconfig文件单独对某个文件夹验证?
- 在asp.net使用web.config身份验证