html 中table边框设置成Excel那样的边框
2008年07月24日 星期四 16:46
<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF"
cellspacing="0" align="center">
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(); }