首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

excel出力 乱码有关问题

2012-03-30 
excel出力 乱码问题HTML code%@ Page LanguageC# AutoEventWireuptrue CodeFileGridview_downloa

excel出力 乱码问题

HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Gridview_download.aspx.cs" Inherits="Gridview_download" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><meta http-equiv="content-type" content="application/ms-excel; charset=UTF-8"/><head runat="server">    <title>文件download之Excel出力</title>    <script type="text/javascript" src='<%=ResolveUrl("~/js/lib/jquery.js") %>'></script>    <script type="text/javascript" language="javascript">         // イメージを変更する       function changeImage(id)       {              if(document.getElementById(id).getAttribute("src",2) == "../Resource/1.png")           {           document.getElementById(id).src = "../Resource/0.png";           $('#'+id + " ~ input").val("0");                   }           else           {           document.getElementById(id).src = "../Resource/1.png";           $('#'+id + " ~ input").val("1");           }      }        function setHeader()         {            var t = document.getElementById("<%=GridView1.ClientID%>");            var t2 = t.cloneNode(true);            for(i = t2.rows.length -1;i > 0;i--){              t2.deleteRow(i);             }             t.deleteRow(0);             t2.style.width="377px";            t2.rows[0].cells[2].style.width="137px";            document.getElementById("div_head").appendChild(t2);         }    </script></head><body>    <form id="form1" runat="server">        <div style="height: 310px; width: 400; position: relative; left: 0px; top: 0px;">            &nbsp;&nbsp;&nbsp;&nbsp;            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="一览下载" /><br />            <br />            <div id="div_head" style="width: 377;">            </div>            <div id="div_info" style="overflow-y: scroll; height: 180px; width: 381px;">                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="360px"                    BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"                    CellPadding="0" ForeColor="Black" GridLines="Vertical">                    <Columns>                        <asp:BoundField DataField="NAME" HeaderText="姓名">                            <HeaderStyle HorizontalAlign="Center" Height="40px" Width="120px" />                            <ItemStyle HorizontalAlign="Center" Height="35px" Width="120px" />                        </asp:BoundField>                        <asp:BoundField HeaderText="团队编号" DataField="TEAM">                            <HeaderStyle HorizontalAlign="Center" Height="40px" Width="120px" />                            <ItemStyle HorizontalAlign="Center" Height="35px" Width="120px" />                        </asp:BoundField>                        <asp:TemplateField>                            <HeaderTemplate>                                &nbsp;所属团队                            </HeaderTemplate>                            <ItemTemplate>                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"TEAM").ToString() == "1"?"~/Resource/1.png":"~/Resource/0.png" %>'                                    onclick="changeImage(this.id);" Style="cursor: pointer; border-bottom: solid 1px black;                                    padding-bottom: 2px;" />                                <asp:HiddenField ID="HiddenField1" runat="server" />                            </ItemTemplate>                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="40px" Width="120px" />                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="35px" Width="120px" />                        </asp:TemplateField>                    </Columns>                    <HeaderStyle BackColor="LightGray" Height="40px" Font-Bold="True" ForeColor="Black" />                    <RowStyle BackColor="#CDE4EA" />                    <FooterStyle BackColor="#CCCC99" />                    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />                    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />                    <AlternatingRowStyle BackColor="White" />                </asp:GridView>            </div>        </div>    </form></body></html> 



[解决办法]
Response.Charset = "Shift_JIS";
试试呢,不一定对啊。。
[解决办法]
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/>");
 StringWriter sw = new StringWriter(sb);

热点排行