欢迎光临
我们一直在努力

Asp.Net页面输出到EXCEL-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

其实,利用asp.net输出指定内容的word、excel、txt、htm等类型的文档很容易的。主要分为三步来完成。

一、定义文档类型、字符编码  

   response.clear();

   response.buffer= true;

   response.charset="utf-8";  

   //下面这行很重要, attachment 参数表示作为附件下载,您可以改成 online在线打开

   //filename=fileflow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc    .xls    .txt   .htm  

   response.appendheader("content-disposition","attachment;filename=fileflow.xls");

   response.contentencoding=system.text.encoding.getencoding("utf-8");  

   //response.contenttype指定文件类型 可以为application/ms-excel    application/ms-word    application/ms-txt    application/ms-html    或其他浏览器可直接支持文档 

   response.contenttype = "application/ms-excel";

   this.enableviewstate = false;  

  二、定义一个输入流  

   system.io.stringwriter ostringwriter = new system.io.stringwriter();

   system.web.ui.htmltextwriter ohtmltextwriter = new system.web.ui.htmltextwriter(ostringwriter);  

  三、将目标数据绑定到输入流输出  

   this.rendercontrol(ohtmltextwriter);   

   //this 表示输出本页,你也可以绑定datagrid,或其他支持obj.rendercontrol()属性的控件  

   response.write(ostringwriter.tostring());

   response.end();  

  总结:本例程在microsoft visual studio .net 2003平台下测试通过,适用于c#和vb,当采用vb的时候将 this 关键字改成 me 。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Asp.Net页面输出到EXCEL-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章