日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

asp.net 导出word excel 当前上下文中不存在名称“Encoding”报错问题

發(fā)布時間:2023/12/9 asp.net 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 asp.net 导出word excel 当前上下文中不存在名称“Encoding”报错问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
======web頁面=============
<%@?Page?Language="C#"?EnableEventValidation="false"?AutoEventWireup="true"?CodeBehind="CheapMaterialManageSet.aspx.cs"?Inherits="AssetsManager.DeskWeb.BaseDOC.CheapMaterialManageSet"?%>

using System.IO;
using System.Data.OleDb;
using System.Text;?
using?......
?//excel導(dǎo)出
????????protected?void?ExcelExprot_ServerClick(object?sender,?ImageClickEventArgs?e)
????????
{
????????????Export(
"application/ms-excel",?"低耗標(biāo)準(zhǔn)庫.xls");
????????}

????????
private?void?Export(string?FileType,?string?FileName)
????????
{
????????????Response.Charset?
=?"GB2312";
????????????Response.ContentEncoding?
=?System.Text.Encoding.UTF7;
????????????
//輸出標(biāo)題
????????????Response.AppendHeader("Content-Disposition",?"attachment;filename="?+?HttpUtility.UrlEncode(FileName,?Encoding.UTF8).ToString());
????????????Response.ContentType?
=?FileType;??//文件的類型
????????????this.EnableViewState?=?false;
????????????StringWriter?tw?
=?new?StringWriter();
????????????HtmlTextWriter?hw?
=?new?HtmlTextWriter(tw);
????????????
this.GVCheapMaterialLib.RenderControl(hw);
????????????Response.Write(tw.ToString());
????????????Response.End();
????????}

????????
//如果沒有下面方法會報錯類型“GridView”的控件“GridView1”必須放在具有?runat=server?的窗體標(biāo)記內(nèi)
????????public?override?void?VerifyRenderingInServerForm(System.Web.UI.Control?control)
????????
{
????????}

????????
//導(dǎo)出到word
????????protected?void?WordExport_ServerClick(object?sender,?ImageClickEventArgs?e)
????????
{
????????????Response.Clear();
????????????Response.Buffer?
=?true;
????????????Response.Charset?
=?"GB2312";
????????????
//filename??輸出的文件名是什么?
????????????Response.AppendHeader("Content-Disposition",?"attachment;filename="?+?HttpUtility.UrlEncode("低耗標(biāo)準(zhǔn)庫.doc",?Encoding.UTF8).ToString());
????????????Response.ContentEncoding?
=?System.Text.Encoding.UTF7;
????????????Response.ContentType?
=?"application/ms-word";//設(shè)置輸出文件類型為word文件。?
????????????System.IO.StringWriter?oStringWriter?=?new?System.IO.StringWriter();
????????????System.Web.UI.HtmlTextWriter?oHtmlTextWriter?
=?new?System.Web.UI.HtmlTextWriter(oStringWriter);
????????????
this.GVCheapMaterialLib.RenderControl(oHtmlTextWriter);
????????????Response.Output.Write(oStringWriter.ToString());
????????????Response.Flush();
????????????Response.End();
????????}
??????

轉(zhuǎn)載于:https://www.cnblogs.com/wj-wangjun/archive/2007/11/22/968268.html

總結(jié)

以上是生活随笔為你收集整理的asp.net 导出word excel 当前上下文中不存在名称“Encoding”报错问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。