To Excel(XML)

<xsl:stylesheet version="1.0"
    xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
 xmlns:user="urn:my-scripts"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" >


  <xsl:template match="/">
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:x="urn:schemas-microsoft-com:office:excel"
      xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:html="http://www.w3.org/TR/REC-html40">
      <Styles>
        <Style ss:ID="Default" ss:Name="Normal">
          <Alignment ss:Vertical="Center"/>
          <Borders/>
          <Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/>
          <Interior/>
          <NumberFormat/>
          <Protection/>
        </Style>
        <Style ss:ID="shead" ss:Name="Normal 3">
          <Alignment ss:Vertical="Center"/>
          <Borders>
            <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
            <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
            <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
            <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
          </Borders>
          <Font x:Family="Swiss"/>
          <Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>
        </Style>
        <Style ss:ID="sbody" ss:Name="Normal 4">
          <Alignment ss:Vertical="Center"/>
          <Borders>
            <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
            <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
            <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
            <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
             ss:Color="#333333"/>
          </Borders>
          <Font x:Family="Swiss"/>
          <Interior />
        </Style>
      </Styles>
      <xsl:apply-templates/>
    </Workbook>
  </xsl:template>


  <xsl:template match="/*">
    <Worksheet>
      <xsl:attribute name="ss:Name">
        <xsl:value-of select="local-name(/*/*)" />
      </xsl:attribute>
      <Table x:FullColumns="1" x:FullRows="1">
        <Row>
          <xsl:for-each select="/*/fields/*">
            <Cell ss:StyleID="shead">
              <Data ss:Type="String">
                <xsl:value-of select="local-name()" />
              </Data>
            </Cell>
          </xsl:for-each>
        </Row>
        <xsl:apply-templates select="/*/record"/>
      </Table>
    </Worksheet>
  </xsl:template>


  <xsl:template match="/*/record">
    <Row>
      <xsl:apply-templates/>
    </Row>
  </xsl:template>


  <xsl:template match="/*/*/*">
    <Cell ss:StyleID="sbody">
      <Data ss:Type="String">
        <xsl:value-of select="." />
      </Data>
    </Cell>
  </xsl:template>


</xsl:stylesheet>
 public string GetCallerGroupXML(string typ, string start, string end, string sHourStart, string sHourEnd, string[] str)
        {

            StringBuilder xmlData = new StringBuilder();
            StringBuilder strCat = new StringBuilder();
            StringBuilder a = new StringBuilder(), b = new StringBuilder();
            int index = 0;
            strCat.Append("<categories>");

            //根据查询条件获取统计的话务组或者工号
            //然后 根据该话务号来组成统计项,有多少个号  则在该时间段内有多少个项


            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == "0")
                    continue;
                string ss = str[i].ToString();
                a.Append("<dataset seriesname='" + str[i] + "应答'>");
                b.Append("<dataset seriesname='" + str[i] + "未应答' parentYAxis='S'>");
                SqlParameter[] para = new SqlParameter[] {
                    new SqlParameter("@pageIndex", -1),
                    new SqlParameter("@pageRow", 0),
                    new SqlParameter("@typ", typ),
                    new SqlParameter("@start", start),
                    new SqlParameter("@end", end),
                    new SqlParameter("@hourStart", sHourStart),
                    new SqlParameter("@hourEnd", sHourEnd),
                    new SqlParameter("@agentID", str[i]),
                    new SqlParameter("@rows", 0)
                };


                using (SqlDataReader rd = SqlHelper.ExecuteReader(SqlHelper.SysConnectionString, CommandType.StoredProcedure, "proc_CallGroup", para))
                {
                    while (rd.Read())
                    {
                        if (index == 0)
                        {
                            string tim = "";
                            if (typ == "h")
                                tim = rd[0].ToString() + "时";
                            else
                                tim = rd[0].ToString();
                            strCat.Append("<category label='" + tim + "' />");

                        }

                        a.Append("<set value='" + rd[1].ToString() + "' />");
                        b.Append("<set value='" + rd[2].ToString() + "' />");
                    }
                    rd.Close();
                }
                a.Append("</dataset>");
                b.Append("</dataset>");

                index++;
            }

            strCat.Append("</categories>");


            xmlData.Append(strCat);
            xmlData.Append(a);
            xmlData.Append(b);


            return xmlData.ToString();
        }

C#
        XmlDocument xmlDoc = seatExportManager.GetCallerGroup(types, start, end, sHourStart, sHourEnd, agents);
        this.Response.Clear();
        this.Response.ContentType = "application/vnd.ms-excel";
        this.Response.AddHeader("Content-Disposition", "attachment; filename=Stat.xls");
        XslCompiledTransform xtExcel = new XslCompiledTransform();
        xtExcel.Load(Server.MapPath("Excel.xsl"));
        xtExcel.Transform(xmlDoc, null, Response.OutputStream);
        this.Response.End();



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值