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

======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导出
        protected void ExcelExprot_ServerClick(object sender, ImageClickEventArgs e)
        
{
            Export(
"application/ms-excel""低耗标准库.xls");
        }

        
private void Export(string FileType, string FileName)
        
{
            Response.Charset 
= "GB2312";
            Response.ContentEncoding 
= System.Text.Encoding.UTF7;
            
//输出标题
            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 的窗体标记内
        public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
        
{
        }

        
//导出到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("低耗标准库.doc", Encoding.UTF8).ToString());
            Response.ContentEncoding 
= System.Text.Encoding.UTF7;
            Response.ContentType 
= "application/ms-word";//设置输出文件类型为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();
        }
      
posted @ 2007-11-22 10:45  wj-conquer  阅读(1494)  评论(0编辑  收藏  举报