黑马程序员之ASP.NET学习笔记:将数据导出到Word或Excel
2012-11-19 22:17
363 查看
-------------------------------------2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!-------------------------------
ASP.NET(C#)将数据导出到Word或Excel
命名空间:
using System.IO;
using System.Text;
将DataGrid的数据导出到Excel
string excelname="excel文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname +".xls");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
将DataGrid的数据导出到Word
string excelname="word文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-winword";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname +".doc");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
---------------------------------------------------
2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------
ASP.NET(C#)将数据导出到Word或Excel
命名空间:
using System.IO;
using System.Text;
将DataGrid的数据导出到Excel
string excelname="excel文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname +".xls");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
将DataGrid的数据导出到Word
string excelname="word文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-winword";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname +".doc");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
---------------------------------------------------
2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------
相关文章推荐
- ASP.NET(C#)将数据导出到Word或Excel
- asp.net中将DataGrid数据导出到excel或word文件中
- asp.net 生成导出word表单 ,导出excel; dataTable生成xls文件,返回前台下载;asp.net启动excel错误 80070005;excel-xls columnName 不能改变; 读写excel的开源利器NPOI; 设置excel Cell的数据类型;
- 将ASP.NET页面内的数据导出到Excel或Word中
- 【黑马程序员】数据导出至Excel(学习笔记)
- asp.net中将DataGrid数据导出到excel或word文件中
- 黑马程序员之ADO.NET学习笔记:ADO.NET数据导入导出
- asp.net_GridView导出数据到Excel/Word
- asp.net中将DataGrid数据导出到excel或word文件中
- 从数据库导出数据到word、excel、.txt _asp.net技巧
- 将ASP.NET页面内的数据导出到Excel 或 Word中 (转)
- 黑马程序员之ASP.NET学习笔记:showModalDialog和showModelessDialog数据传递技巧
- ASP.NET(C#)将数据导出到Word或Excel
- asp.net从数据库导出数据到word、excel、txt文本文件
- 将ASP.NET页面内的数据导出到Excel或Word中
- 在ASP.NET中将GridView数据导出到Word、Excel
- asp.net从数据库导出数据到word、excel、txt文本文件
- asp.net实现导出DataTable数据到Word或者Excel的方法
- 将ASP.NET页面内的数据导出到Excel 或 Word中
- asp.net中Word/Excel的导出数据制作(懒人发掘)