zoukankan      html  css  js  c++  java
  • Office 2007 打开 C# VS2005 导出的Excel时报错:单元格数据太大 Office 2003打开正常 的解决办法

    经测试,有可能是这个问题:

    导出Excel的代码:

        private void ExportToExcel()
        {
            Response.Clear();
            System.Web.HttpContext curContext 
    = System.Web.HttpContext.Current;
            Response.AddHeader(
    "content-disposition""attachment;filename=Test.xls");
            
    //Response.Charset = "UTF-8";//设置字符集
            
    //curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;//设置编码集
            Response.Charset = "utf-8";
            Response.ContentEncoding 
    = System.Text.Encoding.GetEncoding("GB2312");
            
    //Response.ContentType = "application/vnd.xls";
            Response.ContentType = "application/ms-excel";
            
    //ms-excel
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite 
    = new HtmlTextWriter(stringWrite);
            
    //写到Excel的数据不用分页
          
            GridView1.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
    //向客户端写数据
            Response.End();

            GridView1.AllowSorting 
    = true;
            
    //恢复分页       
        }

     如果将 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

    设置成 UTF7则会出现题目中的问题 导致打开是乱码,改成GB2312就正常。

    ////////////////////////////////
    ////////Sixi. Let it be.../////
    //////////////////////////////

  • 相关阅读:
    hibernate对应关系详解(转)
    mybatis genertor两种使用方式(文件+项目)
    YII2 union 不同数据结构时 解决方案
    Yii2 分表后 使用 union all 分页实现代码
    Beyond Compare 4.2.10手动破解
    Xshell 6+Xftp 6官方下载免费版
    Navicat Premium
    yii2的Console定时任务创建
    内嵌多个youtube视频并展现该频道所有视频列表
    video.js 动态获取URL 并播放youtube视频
  • 原文地址:https://www.cnblogs.com/sixiweb/p/2141346.html
Copyright © 2011-2022 走看看