我做了一个导出EXCEL的按钮,代码如下,有两个问题。1.导出的EXCEL是2003版的,用office2003打开是正常的,但是用office2010打开就乱码,直接在office2003复制黏贴到office2010的新建文档里面也是乱码,有没有办法解决,正常来说2003的文件在2010打开是没问题的。他的提示是写着“单元格数据太大”,考虑到有的用户可能只装2003或只装2007或只装2010,所以导出的文件要做到全兼容才行.2.导出的文字字体是Arial Unicode MS,这个有没有办法改,改成宋体之类,当然这个不是很关键,导出来后自己手动改也可以,关键是上面那个问题。后台代码:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;using System.Drawing;using System.IO;using System.Text;public partial class test : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Export("application/ms-excel", "bijiben.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); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { }}
1 回答
- 1 回答
- 0 关注
- 275 浏览
添加回答
举报
0/150
提交
取消