Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

绿色网站无广告
会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux编程 > 数据库管理 > » 正文

EXT.NET(十四)导出EXCEL

来源: david_520042 分享至:

 在运用EXT.NET过程中尝试了很多导出EXCEL的结果都失败了。

干脆就用DEMO中的案列吧。建立一个EXCEL.XSL

<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">
      <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="*[position() = 1]/*">
            <Cell>
              <Data ss:Type="String">
                <xsl:value-of select="local-name()" />
              </Data>
            </Cell>
          </xsl:for-each>
        </Row>
        <xsl:apply-templates/>
      </Table>
    </Worksheet>
  </xsl:template>


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


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


</xsl:stylesheet>


JS:

        <script type="text/javascript">
            var template = '<span style="color:{0};">{1}</span>';

            var change = function (value) {
                return String.format(template, (value > 0) ? 'green' : 'red', value);
            }

            var pctChange = function (value) {
                return String.format(template, (value > 0) ? 'green' : 'red', value + '%');
            }
            var exportData = function (format) {
                var store = GridPanel1.store;
                store.directEventConfig.isUpload = true;

                var records = store.reader.readRecords(store.proxy.data).records,

                values = [];

                for (i = 0; i < records.length; i++) {
                    var obj = {}, dataR;

                    if (store.reader.meta.id) {
                        obj[store.reader.meta.id] = records[i].id;
                    }

                    dataR = Ext.apply(obj, records[i].data);

                    if (!Ext.isEmptyObj(dataR)) {
                        values.push(dataR);
                    }
                }

                store.submitData(values);

                store.directEventConfig.isUpload = false;
            };

        </script>

后台代码:

    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        string format = "yyyyMMddhhss";
        string name = "PO_Planning" + System.DateTime.Now.ToString(format) + ".xls"; 

        XmlNode xml = e.Xml;

        this.Response.Clear();
        this.Response.ContentType = "application/vnd.ms-excel";
        this.Response.AddHeader("Content-Disposition", "attachment; filename="+name);
        XslCompiledTransform xtExcel = new XslCompiledTransform();
        xtExcel.Load(Server.MapPath("Excel.xsl"));
         xtExcel.Transform(xml, null, Response.OutputStream);

        this.Response.End();
    }

调用:

                        <ext:Button ID="btnxls" runat="server" Text="导出Excel" Icon="PageExcel">
                            <Listeners>
                                <Click Handler="exportData('xls');" />
                            </Listeners>
                        </ext:Button>




 


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史