有gridview汇出word和excel
private void Export(GridView _gv, string filetype, string FileName)
{
if (filetype == "1")
{
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());//FileName.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/excel";//设置输出文件类型为excel文件。
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
_gv.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
else
{
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/word";//设置输出文件类型为Word文件。
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
_gv.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
}
有gridview汇出word和excel的更多相关文章
- 在ASP.NET中将GridView数据导出到Word、Excel
在ASP.NET中将GridView数据导出到Word.Excel asp.net,导出gridview数据到Word,Excel,PDF #region Export to Word, Exce ...
- C#导出Word或Excel文件总显示Html标记
原因:Word或Excel文件包含的GridView没有查询到数据.
- [Asp.net]常见word,excel,ppt,pdf在线预览方案,有图有真相,总有一款适合你!
引言 之前项目需要,查找了office文档在线预览的解决方案,顺便记录一下,方便以后查询. 方案一 直接在浏览器中打开Office文档在页面上的链接.会弹出如下窗口: 优点:主流浏览器都支持. 缺点: ...
- 基于DevExpress实现对PDF、Word、Excel文档的预览及操作处理
http://www.cnblogs.com/wuhuacong/p/4175266.html 在一般的管理系统模块里面,越来越多的设计到一些常用文档的上传保存操作,其中如PDF.Word.Excel ...
- ASP.NET中GridView数据导出到Excel
/// <summary> /// 导出按钮 /// </summary> /// <param name="sender"></para ...
- Asp.net实现直接在浏览器预览Word、Excel、PDF、Txt文件(附源码)
功能说明 输入文件路径,在浏览器输出文件预览信息,经测试极速(Chrome).IE9.Firefox通过 分类文件及代码说明 DemoFiles 存放可测试文件 Default.aspx 启动页 ...
- 如何通过WPS 2013 API 将Office(Word、Excel和PPT)文件转PDF文件
1. 描述 PDF 文件是一种便携文件格式,是由Adobe公司所开发的独特的跨平台文件格式.PDF文件以PostScript语言图象模型为基础,无论在哪种打印机上都可保证精确的颜色和准确的打印效果,即 ...
- Android遍历获取Office格式(Word,Excel,PPT,PDF)的文件并打开
此案例主要是模仿QQ加载WPS(Word,Excel,PPT)本地文件可打开查看,使用ListView加载,使用线程扫描SD卡下所有目录加载指定的Word,Excel,PPT等格式的文件,ListVi ...
- 一款免费支持PDF、word、excel、PPT、jpeg之间互转线上软件
偶然发现的一款免费支持PDF.word.excel.PPT.jpeg之间互转,支持合并pdf.加密解密PDF的线上软件,首先声明,不是广告党,我自己试用过,确实是目前我用过最好用的,如果有朋友有更好的 ...
随机推荐
- WebStorm 用法集合
1. 图片宽高提示.<img src="https://pic4.zhimg.com/8345475b687c83a71e0564419b0ac733_b.jpg" ...
- SQL执行一次INSERT INTO查询,插入多行记录
那如果我们想插入多行记录呢?可能你会想到多次运行INSERT语句即可,就像下面的php代码示例: INSERT INTO tbl_name (col1,col2) VALUES (,); 那如果我们想 ...
- golang学习之闭包
匿名函数不能够独立存在,但可以被赋值于某个变量,即保存函数的地址到变量中:fplus := func(x, y int) int { return x + y },然后通过变量名对函数进行调用:fpl ...
- Intellij IDEA 各种乱码解决方案 posted @ 2017-06-23 15:31:06
一次解决所有问题,只需做配置文件的修改即可 解决方案: 在 IntelliJ IDEA 2016.1\bin\idea64.exe.vmoptions Intell ...
- 读EntityFramework.DynamicFilters源码_心得_单元测试03
上个星期我们只是显示了一个示例,怎么在EF的框架内,注入我们拓展的动态过滤器 第一步:安装EntityFramework.DynamicFilters 第二步:重写OnModelCreating方法 ...
- csharp:Google TTS API text to speech
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Csharp:WebClient and WebRequest use http download file
//Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...
- Java函数调用总结
//思考:1.方法能不能写方法 2.为什么不能写 public static void main(String[] args) { public static void name(){}; } 方法中 ...
- 【转】Silverlight无法添加服务引用
引用地址:http://blog.sina.com.cn/s/blog_6e9c36f501017yzv.html 错误如下: 错误 7 自定义工具错误: 无法生成服务引用“ServiceRefere ...
- Java—IO流 字节流
IO流(输入流.输出流),又分为字节流.字符流. 流是磁盘或其它外围设备中存储的数据的源点或终点. 输入流:程序从输入流读取数据源.数据源包括外界(键盘.文件.网络…),即是将数据源读入到程序的通信通 ...