ASP.NET中操作Word和Excel(二)
2007-03-04 20:05
393 查看
使用HttpContext对象,导出到word。这个比较通用,也可以导出到excel等。可将整个页面(Page),或者DataGrid,DataList等控件使用RenderControl()方法到word,提示用户选择下载存放地址。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.Charset = "UTF-8";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.ContentType = filetype;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
System.IO.StringWriter tw = new System.IO.StringWriter();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
gv.RenderControl(hw);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.Write(tw.ToString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.End();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.Charset = "UTF-8";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.ContentType = filetype;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
System.IO.StringWriter tw = new System.IO.StringWriter();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
gv.RenderControl(hw);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.Write(tw.ToString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
HttpContext.Current.Response.End();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- Asp.Net中Word,Excel等office com组件操作权限的问题
- Asp.Net中Word,Excel等office com组件操作权限的问题
- Asp.Net中Word,Excel等office com组件操作权限的问题
- Asp.Net中Word,Excel等office com组件操作权限的问题 ————转自rainpig2008
- asp.net Aspose.Word 利用邮件合并功能 操作word模板 生成word。asp.net NPOI 对excel进行操作,生成excel
- ASP.NET操作服务器端Word和Excel
- ASP.NET中操作Word和Excel(一)
- asp.net操作Excel总结
- ASP.NET中将数据输出到WORD、EXCEL、TXT、HTM
- ASP.Net调用Word,Excel组件服务之说明
- [Asp.net]常见word,excel,ppt,pdf在线预览方案,有图有真相,总有一款适合你!
- ASP.NET操作Excel(终极方法NPOI)
- ASP.NET操作Word的IIS权限设置
- ASP.NET中对EXCEL文件进行操作!
- asp.net中将DataGrid数据导出到excel或word文件中
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
- Asp.net操作Excel文件事例小结,基于ExtAspNet控件库
- asp.net 在IIS下操作Excel文件权限不足的解决方法
- asp.net操作word
- 在asp.net中操作excel如何关闭excel的进程