html에서table 테두리를 Excel 같은 테두리로 설정합니다.

5147 단어 Excel
html에서table 테두리를 Excel 같은 테두리로 설정합니다.
2008년 07월 24일 목요일 16:46
cellspacing="0"align="center">
열:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ystj.aspx.cs" Inherits="ydl_ystj" %>

<!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">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
         <div id="divtj" runat="server">
         <table width="100%" border="1" cellpadding="0" bordercolorlight="#000" bordercolordark="#000"
cellspacing="0" align="center" frame="below" >
          <tr>
           <th colspan="5" style="font-size:xx-large; text-align:center;" >
             <font >    fdafd </font>
           </th>
          </tr>
          
            <asp:Repeater ID="rpt_xmxxinfo" runat="server">
                <HeaderTemplate>
                                <tr >
                    <th></th>
                        <th  >
                            fdsfdsf
                        </th>
                        <th   >
                            fdsf
                        </th>
                        <th   >
                            dfsdaf
                        </th>
                        <th  >
                          fdsafsdfd
                        </th>
                    </tr>

                </HeaderTemplate>
                <ItemTemplate>

                    <tr>
                    <td>
                    <%# Container.ItemIndex + 1%>
                    </td>
                        <td>
                            <%#Eval("11")%>
                        </td>
                        <td >
                            <%#Eval("111")%>
                        </td>
                        <td>
                            <%#Eval("dh")%>
                        </td>
                        <td>
                            <%#Eval("d111h")%>
                        </td>
                    </tr>

                </ItemTemplate>
                <FooterTemplate>
                
                </FooterTemplate>
            </asp:Repeater>
              </table>
            </div>
    
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    </form>
</body>
</html>

C# 코드:
 protected void Button1_Click(object sender, EventArgs e)
    {

        string fileName = "dfdfdfds";
        System.IO.StringWriter tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
        tbystj.RenderControl(hw);


        System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;

        Response.Write(tbystj.ToString());
        Response.Clear();
        Response.Charset = "gb2312";
        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName) + ".xls");
        Response.Write("<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"></head><body>");
        string output = tw.ToString();
        if (true)
        {
            
            output = Regex.Replace(output, @"<\s*/?\s*a[^>]*>", "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            output = Regex.Replace(output, @"<\s*/?\s*img[^>]*>", "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
        }
        Response.Write(output);
        Response.Write("</body></html>");
        Response.End();
        hw.Close();
        hw.Flush();
        tw.Close();
        tw.Flush();
    }

좋은 웹페이지 즐겨찾기