资讯详情

首页  >  CPA考试  > 资讯详情

把Web Control导出为Excel或Word

2025-12-25 来源:快学会计网

导读:/// /// 将Web控件导出/// /// 控件实例/// 类型:Excel或wordpublic void ExpertControl(System.Web.UI.Control source, DocumentType type){ //设置Http的头信息,编码格式 if (type == DocumentType.Excel) { //Excel Response.Append

 /// /// 将Web控件导出/// /// 控件实例/// 类型:Excel或wordpublic 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

相关资讯
物业代为收取的水电费可以开具增值税专用发票吗
怎么可以减少银行承兑汇票贴现成本
我公司是小规模纳税人提供四项服务的销售额占全部销售额的比重超过50%,可以适用加计抵减政策吗
怎么处理收到的转账支票呢
怎么处理现金清偿债务

点击长按保存图片,微信识别

扫码立即领取资料

咨询