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

|M| 300分求:怎么将一个我用Repeater输出的Table转为Execl导出 多谢

2011-12-20 
|M| 300分求:如何将一个我用Repeater输出的Table转为Execl导出 谢谢急tablewidth 99% cellpadding 0

|M| 300分求:如何将一个我用Repeater输出的Table转为Execl导出 谢谢 急
<table   width= "99% "   cellpadding= "0 "   cellspacing= "0 "   style= "border-collapse:   collapse "   bordercolor= "black "   border= "1 ">                                                                                
        <tr>
                <td   colspan= "3 ">
                        <b   class= "font5 "> 苹果批发 </b>
                </td>
        </tr>
        <tr>
                <td   width= "10% "   align= "center ">
                        批发号 </td>
                <td   width= "15% "   align= "center ">
                        批发时间 </td>
                <td   width= "10% "   align= "center ">
                        总价格 </td>
        </tr>                                                                                
        <tr>
                <td   width= "10% "   align= "center ">
                      0001 </td>
                <td   width= "15% "   align= "center ">
                        2007-05-24 </td>
                <td   width= "10% "   align= "center ">
                        1200.00 </td>
        </tr>
<tr>
                <td   width= "10% "   align= "center ">
                      0002 </td>
                <td   width= "15% "   align= "center ">
                        2007-05-24 </td>
                <td   width= "10% "   align= "center ">
                        1100.00 </td>
        </tr>


<tr>
<td   colspan= "2 "   align= "center "> 合计 </td> <td   align= "center "> 2300.00 </td>
</tr>
<tr>
                <td   colspan= "3 ">
                        <b   class= "font5 "> 小黄瓜批发 </b>
                </td>
        </tr>
        <tr>
                <td   width= "10% "   align= "center ">
                        批发号 </td>
                <td   width= "15% "   align= "center ">
                        批发时间 </td>
                <td   width= "10% "   align= "center ">
                        总价格 </td>
        </tr>                                                                                
        <tr>
                <td   width= "10% "   align= "center ">
                      1001 </td>
                <td   width= "15% "   align= "center ">
                        2007-05-23 </td>
                <td   width= "10% "   align= "center ">
                        800.00 </td>
        </tr>
<tr>
                <td   width= "10% "   align= "center ">
                      1002 </td>
                <td   width= "15% "   align= "center ">
                        2007-05-24 </td>
                <td   width= "10% "   align= "center ">
                        700.00 </td>
        </tr>
<tr>
<td   colspan= "2 "   align= "center "> 合计 </td> <td   align= "center "> 1500.00 </td>
</tr>
</table>
上面是生成的Table怎么把他转为Excel输出
谢谢

[解决办法]
不会,帮你顶顶
------解决方案--------------------


Response.AddHeader( "Content-Disposition ", "attachment; filename= "+Server.UrlPathEncode( "充值报表输出 "+DateTime.Now.ToShortDateString()+ ".csv "));
Response.ContentType = "application/octet-stream ";
Response.Write( "\r\n查询条件:日期范围: "+tbx_StartDate.Text+ "- "+tbx_EndDate.Text+ " 过滤条件: "+SearchSort.SelectedValue+ "包含内容: "+PayCardSubject.Text+ "\r\n\r\n ");
Response.Write( "编号,卡号,密码,面值,充值用户,充值IP,充值日期\r\n ");
DataTable dt=new DataTable();
dt=GetData();
dt.Columns.Add( "PayCardSort2 ",typeof(string));
int PayValueCount=0;
for (int i=0;i <dt.Rows.Count;i++)
{

PayValueCount+=Convert.ToInt32(dt.Rows[i][ "PayValue "].ToString());
Response.Write(dt.Rows[i][ "PayCardId "].ToString()+ ", "+dt.Rows[i][ "PayCardNumber "].ToString()+ ", "+dt.Rows[i][ "PayCardPassWord "].ToString()+ ", "+dt.Rows[i][ "PayValue "].ToString()+ ", "+dt.Rows[i][ "PaymentUserName "].ToString()+ ", "+dt.Rows[i][ "PaymentIp "].ToString()+ ", "+dt.Rows[i][ "CreateDate "].ToString()+ "\r\n ");

}
Response.Write( "\r\n总计:¥ "+PayValueCount.ToString()+ ".00元 ");
Response.End();
[解决办法]
public static void ExportExcel(ref System.Web.UI.WebControls.Repeater rp, string strFileName){//DataTable dt = (DataTable)this.Session[ "GridToExcel "];//if (dt==null) return;strFileName= System.Web.HttpUtility.UrlEncode(strFileName,System.Text.Encoding.UTF8); //dtgList.DataSource = DataClass.ExecuteDataTable(dtgList.strSQL).DefaultView;//dtgList.EnableViewState =false;System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.Buffer = true; System.Web.HttpContext.Current.Response.Charset = "gb2312 ";System.Web.HttpContext.Current.Response.AppendHeader( "Content-Disposition ", "online; filename= " + strFileName + ".xls ");System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding( "gb2312 ");System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel ";//System.Web.HttpContext.Current.EnableViewState = false;System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo( "zh-CN ",true);System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);//oHtmlTextWriter.Write( " <table width= '100% ' border= '1 '> ");rp.RenderControl(oHtmlTextWriter); //oHtmlTextWriter.Write( " </table> ");rp = null;System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString().Replace( " <td ", " <td STYLE= 'MSO-NUMBER-FORMAT:\\@ ' "));System.Web.HttpContext.Current.Response.Buffer = false; System.Web.HttpContext.Current.Response.End();}
[解决办法]
我刚好也遇到这个问题,帮楼主顶!
[解决办法]
|M| 开头的怎么会这么多分开贴,不明白!

[解决办法]
没弄过,帮顶,

热点排行