利用HttpContext 导出数据(word、excel)
来源:互联网 发布:最强搜图软件 编辑:程序博客网 时间:2024/05/14 07:28
#region 导出数据,调用该方法后自动返回可下载的文件流
/// <summary>
/// 导出数据
/// </summary>
/// <param name="fileContent">文件内容</param>
/// <param name="fileType">文件类型</param>
public static void ExportData(StringBuilder fileContent, string fileType)
{
// 当前对话
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
// 设置编码和附件格式
switch (fileType)
{
case "doc":
curContext.Response.ContentType = "application/msword";
break;
case "xls":
curContext.Response.ContentType = "application/vnd.ms-excel";
break;
default:
curContext.Response.ContentType = "application/msword";
break;
}
curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
curContext.Response.Charset = "utf-8";
// IO用于导出并返回文件
System.IO.StringWriter strWriter = new System.IO.StringWriter(fileContent);
// 返回客户端
curContext.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />" + strWriter.ToString());
curContext.Response.End();
}
#endregion
- 利用HttpContext 导出数据(word、excel)
- 利用poi导出word excel
- 数据 导出到Word 、excel
- Silverlight 数据导出(Excel,word)
- 导出数据到Excel/Word
- JavaScript利用ActiveX导出Excel,Word
- 利用模板导出word里面生成excel
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- 数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- C#数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- C#数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- 数据导出到Excel(或Word)源代码大全
- 深入分析 Java I/O 的工作机制
- web.config中的HttpHandler
- Linux启动检测磁盘失败
- learn English well is necessary
- 批处理:将Ping结果前加上时间并把结果保存为txt文件
- 利用HttpContext 导出数据(word、excel)
- java 十进制转换成二进制数
- JSF,Hibernate,Spring的整合与杂谈
- busybox配置telnetd的问题
- shell脚本学习-11(cut命令学习)
- truncate 本质是什么
- 乐天派
- java 对分查找
- grep 或 egrep 或awk 过滤两个或多个关键词|使用grep匹配“与”或者“或”模式