易截截图软件、单文件、免安装、纯绿色、仅160KB

asp.net导出excel的问题

VB.NET code:

private void ToExcel(Control ctl, string FileName)
{

HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;

HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}




导出为以上代码,一般使用也正常,但发现有时会出现乱码,昨天一个个测试发现导出这个人时,有乱码,查看.xls代码如下去掉“甫”字一切显示正常
求解决办法,或有其他能解决乱码的导出方法。
HTML code:

<table cellspacing="0" rules="all" bordercolor="Gainsboro" border="1" id="DataGrid1" style="border-color:Gainsboro;border-width:1px;border-style:solid;font-siz


相关问答:

asp.net 线程的问题? - .NET技术 / ASP.NET

前段时间碰到一道面试题如下:
test.aspx页面有如下代码:
 Response.Write(Test.GetDate());
Test类如下:
public class Test
{
  static string dt="";
  public static s ......

asp.net后台调用js方法 - .NET技术 / ASP.NET

<script type="text/javascript" src="js/Dialog.js"></script>
<script type="text/javascript">
  function zOpenD()
  {
  va ......

asp.net中可输入的下拉框的问题 - .NET技术 / ASP.NET

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Namespace CBDAspNet.WebControls.HTML
  ''' <summary>
  '' ......

在asp.net里面脚本出错 - .NET技术 / ASP.NET

function CheckOpwd(){//验证用户名
var pwd=document.all.txtOpwd;

var div1=document.getElementById("divPwd");

if (pwd.value=="")
{
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号