美文网首页
C# .Response.Write 导出报表修改文本格式

C# .Response.Write 导出报表修改文本格式

作者: LH_0811 | 来源:发表于2016-12-14 13:50 被阅读77次
    base.Response.Clear();
                    base.Response.ContentEncoding = Encoding.UTF8;
                  
                    base.Response.ContentType = "Application/ms-excel";
                    
                    
                    base.Response.AppendHeader("Content-Disposition", "attachment;filename=\"Export_" + DateTime.Now.ToString("yyyymmddhhmm") + "_" + base.RandKey(4) + ".xls\"");
                    if ((table != null) && (table.Rows.Count > 0))
                    {
                        base.Response.Write("<table border=\"0\" style=\"text-align:left;font-size:10pt\" cellpadding=\"0\" cellspacing=\"0\">");
                        base.Response.Write("<tr height\"50\"><td style=\"text-align:center;font-size:16pt;\" colspan=\"11\"><b>订单列表</b></td></tr>");
                        base.Response.Write("<tr><td colspan=\"11\"></td></tr>");
                        base.Response.Write("</table>");
                        
                        base.Response.Write("<table border=\"1px\" style=\"text-align:left;font-size:10pt\" cellpadding=\"0\" cellspacing=\"0\">");
    
                        base.Response.Write("<tr bgcolor=\"c0c0c0\">");
                        base.Response.Write("<td width=\"100\"><b>交易时间<b></td>");
                        base.Response.Write("<td width=\"200\"><b>订单号</b></td>");
                        base.Response.Write("<td width=\"100\"><b>商户号</b></td>");
                        base.Response.Write("<td width=\"100\"><b>商户简称<b></td>");
                        base.Response.Write("<td width=\"100\"><b>终端号<b></td>");
                        base.Response.Write("<td width=\"100\"><b>交易类型<b></td>");
                        base.Response.Write("<td width=\"100\"><b>交易状态<b></td>");
                        base.Response.Write("<td width=\"100\"><b>交易金额<b></td>");
    
                        base.Response.Write("<td width=\"100\"><b>结算金额<b></td>");
                        base.Response.Write("<td width=\"100\"><b>执行费率(%)<b></td>");
    
                        base.Response.Write("<td width=\"100\"><b>手续费</b></td>");
    
                        base.Response.Write("<td width=\"100\"><b>收款行</b></td>");
                        base.Response.Write("<td width=\"100\"><b>支行名行</b></td>");
                        base.Response.Write("<td width=\"100\"><b>联行号</b></td>");
                        base.Response.Write("<td width=\"100\"><b>收款帐户</b></td>");
                        base.Response.Write("<td width=\"100\"><b>收款人</b></td>");
    
                        base.Response.Write("<td width=\"100\"><b>支付卡号<b></td>");
                        base.Response.Write("<td width=\"100\"><b>卡片类型<b></td>");
                        base.Response.Write("<td width=\"100\"><b>是否T0商户<b></td>");
                        base.Response.Write("<td width=\"100\"><b>结算时间<b></td>");
                        base.Response.Write("</tr>");
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            DataRow row = table.Rows[i];
                            //根据mainId 获取到商户的信息
                            DataSet posuserDS = BasePage.BindAgeData("SELECT  * FROM [posplat].[dbo].[PosUser] where mainid = '" + row["mainid"].ToString() + "'");
                            DataTableCollection posusertables = posuserDS.Tables;
                            
                            if (posuserDS.Tables.Count == 1)
                            {
                                DataTable theTable = posusertables[0];
                                DataRowCollection therows = theTable.Rows;
                                DataRow therow = therows[0];
                                
                                string combankname1 = therow["combankname1"].ToString(); //商户银行卡开户行名称
                                string zhihangming = therow["combanksort2"].ToString();//支行名
                                string lianhanghao = therow["combank2"].ToString();//联行号
                                string combankcarnum1 = therow["combankcarnum1"].ToString();//银行卡号
                                string combankcarname1 = therow["combankcarname1"].ToString();//shou kuan ren
                                string isT0 = therow["postdayid"].ToString().Equals("6") ? "是" : "否"; //是否T0代付
    
                                base.Response.Write("<tr>");
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", BasePage.TimeStr(row["addtime"].ToString())));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["systr"].ToString()));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["mainid"].ToString()));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["niname"].ToString()));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["serid"].ToString()));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", this.GetTradeType(row["tradesort"].ToString())));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\" >{TEXT}</td>".Replace("{TEXT}", BasePage.PosTradeState(row["tradestate"].ToString())));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["total"].ToString()));
                                
                                double jiesuanJinEr = Convert.ToDouble(row["total"]) - Convert.ToDouble(row["tax"]);
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", jiesuanJinEr.ToString()));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["rate"].ToString()));
    
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["tax"].ToString()));
    
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", combankname1));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", zhihangming));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", lianhanghao));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", combankcarnum1));
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", combankcarname1));
    
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", BasePage.CardDis(row["carnum"].ToString())));//支付卡号
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", row["carorg"].ToString()));//支付卡号
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", isT0));//是否T0代付
                                base.Response.Write("<td style=\"vnd.ms-excel.numberformat:@\">{TEXT}</td>".Replace("{TEXT}", BasePage.TimeStr(row["jiesuantime"].ToString())));//结算时间
    
                                base.Response.Write("</tr>");
    
                            }
                            else
                            {
                                MessageBox.Show(this, "导出失败,获取商户信息失败!");
                                return;
                            }
                            
    
                          
                        }
                        base.Response.Write("</table>");
                        base.Response.Write("<table border=\"0\" style=\"text-align:left;font-size:10pt\" cellpadding=\"0\" cellspacing=\"0\">");
                       
                        base.Response.Write("<tr><td colspan=\"11\"></td></tr>");
                        base.Response.Write("<tr>");
                        base.Response.Write("<td colspan=\"7\"> </td>");
                        base.Response.Write("<td><b>导出时间:<b></td>");
                        base.Response.Write("<td> {PrintTime}</td>".Replace("{PrintTime}", DateTime.Now.ToString()));
                        base.Response.Write("<td> </td>");
                        base.Response.Write("<td> </td>");
                        base.Response.Write("</tr>");
                        base.Response.Write("</table>");
                    }
                    base.Response.Flush();
                    base.Response.Close();
                    base.Response.End();
                }
    

    相关文章

      网友评论

          本文标题:C# .Response.Write 导出报表修改文本格式

          本文链接:https://www.haomeiwen.com/subject/glpimttx.html