/// <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
分享到:
相关推荐
mfc listcontrol导出保存为excel类
DataGrid导出EXCEL的几个方法(WebControl)DataGrid导出EXCEL的几个方法(WebControl)DataGrid导出EXCEL的几个方法(WebControl)DataGrid导出EXCEL的几个方法(WebControl)
此程序简单易懂,可操作性强,不仅支持将数据导入到excel中,还支持List控件表头含有括号的操作,如单位(元)。
Listcontrol导出excel示例程序,基于对话框的
MFC ListControl与Excel 数据导入导出Demo IDE:VS2010
DataGrid导出EXCEL的几个方法(WebControl).rar
VS2013 C++用list control 导入导出EXCEL2010/2003文件,导入(只做了简单插入,文件导入listcontrol后面上传),导出自定义路径和文件名,导出数据后自动获取文件名显示文件,对新手来说,网上的代码一个小错误都要...
listcontrol控件数据导出到excel
IEWebControl.exe 控件IE浏览器控件
这是我在网上找的List Constrol 列表中的数据导出到Excel表格中的程序。而后我自己添加了将Excel表格中的数据导入到List Control中的功能。
VS2010(C++)MFC应用程序,List Control控件中数据导出到Excel VS2010,XP,Excel2003
1、生成默认的基本对话框工程,工程名为ProjectX。 2、添加DataGrid1控件:Ctrl+W打开类向导,工程->增加到工程...9、双击导出Excel按钮,添加单击响应函数及功能代码。 注意:如何获取DataGrig1的行数(记录集的数量)
基于DevExpress的SpreadsheetControl实现对Excel的打开、预览、保存、另存为、打印示例代码下载
8、"导出Excel"按钮关联类型为CColorButton的变量(Vaiable Type:CColorButton):m_btn1 9、右键点击ProjectX resources->引入:文件类型选择所有文件,依次引入5个按钮位图,程序将自动添加5个位图资源,然后设置...
webcontrol,学习的内容,自用,勿下
自定义控件Button源码(WebControl) 自定义控件Button源码(WebControl) 自定义控件Button源码(WebControl)
一个非常不错的服务器控件源码 WebControl 一个非常不错的服务器控件源码 WebControl
自定义控件(HelloWorld)源码(WebControl) 自定义控件(HelloWorld)源码(WebControl) 自定义控件(HelloWorld)源码(WebControl)