我做了一個(gè)導(dǎo)出EXCEL的按鈕,代碼如下,有兩個(gè)問(wèn)題。1.導(dǎo)出的EXCEL是2003版的,用office2003打開是正常的,但是用office2010打開就亂碼,直接在office2003復(fù)制黏貼到office2010的新建文檔里面也是亂碼,有沒(méi)有辦法解決,正常來(lái)說(shuō)2003的文件在2010打開是沒(méi)問(wèn)題的。他的提示是寫著“單元格數(shù)據(jù)太大”,考慮到有的用戶可能只裝2003或只裝2007或只裝2010,所以導(dǎo)出的文件要做到全兼容才行.2.導(dǎo)出的文字字體是Arial Unicode MS,這個(gè)有沒(méi)有辦法改,改成宋體之類,當(dāng)然這個(gè)不是很關(guān)鍵,導(dǎo)出來(lái)后自己手動(dòng)改也可以,關(guān)鍵是上面那個(gè)問(wèn)題。后臺(tái)代碼: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)? {? }}
導(dǎo)出EXCEL按鈕的問(wèn)題
ibeautiful
2018-12-06 15:17:10