把Web Control导出为Excel或Word
来源:互联网 发布:矩阵的卷积运算 编辑:程序博客网 时间:2024/05/22 05:00
/// <summary>
/// 将Web控件导出
/// </summary>
/// <param name="source">控件实例</param>
/// <param name="type">类型:Excel或Word</param>
public void ExpertControl(System.Web.UI.Control source, DocumentType type)
{
//设置Http的头信息,编码格式
if (type == DocumentType.Excel)
{
//Excel
Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
Response.ContentType = "application/ms-excel";
}
else if (type == DocumentType.Word)
{
//Word
Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
Response.ContentType = "application/ms-word";
}
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
//关闭控件的视图状态
source.Page.EnableViewState =false;
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
source.RenderControl(htmlWriter);
//输出
Response.Write(writer.ToString());
Response.End();
}
//文档类型
public enum DocumentType
{
Word,
Excel
}
调用方法:
ExpertControl(this, DocumentType.Word);
这是将整个页面导出为Word
- 把Web Control导出为Excel或Word
- table导出为word或excel
- WEB页面导出为EXCEL,Word
- javascript实现WEB页面导出为EXCEL或WORD文档的方法
- word或excel导出
- 直接把table内容导出到word或excel
- 怎么把数据导出到Excel(或Word)
- 将数据导出为Excel或Word的公共类!
- 将数据导出为Excel或Word的公共类!
- 将页面内容导出为excel或word
- Repeater控件中的数据导出为Excel或Word文件
- ASP导出为Word或Excel的最简单方法
- C# word或者excel保存或导出为PDF
- Asp.net中把DataTable或DataGrid导出为Excel
- Asp.net中把DataTable或DataGrid导出为Excel
- 导出Excel或word文档
- WEB页面导出为EXCEL/word文档的方法
- WEB页面导出为WORD,EXCEL文档的方法
- 自己动手写操作系统
- 对于大文件的文件内定位
- 磁盘格式化的编程实现
- 在WINDOWS里用VC后台不显示提示信息格式化磁盘
- 航行
- 把Web Control导出为Excel或Word
- HyperSnap-DX 终极抓图技术大揭秘
- try
- 从命令行模式运行Windows管理工具。
- 让Video Render停下来
- 第一个转身的就是天使-转
- Tomcat启动分析
- Tomcat启动脚本catalina.sh
- Tomcat的类载入器