【问题标题】:Transforming Data from One Excel Template to Another Excel Template?将数据从一个 Excel 模板转换为另一个 Excel 模板?
【发布时间】:2012-08-11 07:04:20
【问题描述】:

我想从一个 Excel 模板(由客户提供)中获取数据,然后将其转换为我自己的内部 Excel 模板。

我基本上希望能够编写一个转换 (XSLT),从客户端的 Excel 模板中调用字段名称,然后通过某种映射过程将值导入我自己的模板中的相应字段。

有没有办法做到这一点? 例如,客户端可能具有以下列: 名 姓 地址 电话号码

但是,我的模板可能只有 名 姓 电话号码

我希望转换只是自动从客户端 Excel 模板中的三个相应字段中提取值。

这可能吗?如果是这样,我在看什么样的流程?

注意:Excel 模板是指格式良好的 Excel 文件,其中包含字段和单元格值。

【问题讨论】:

    标签: excel xslt transformation


    【解决方案1】:

    是的,这是我看到的过程:

    1) 从您的 Excel 电子表格创建一个 XML 数据和架构文件。见this reference.

    2) 将 XML 模式导入客户端 Excel 电子表格。见this reference.

    3) 也将客户端 Excel 电子表格导出到 XML 数据文件。

    4) 一举对两个文档进行转换,基本上:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:exsl="http://exslt.org/common">
    
      <xsl:variable name="mine"   select="document(/path/to/your.xml)"/>
      <xsl:variable name="client" select="document(/path/to/client.xml)"/>
    
      <xsl:variable name="both">
        <both>
          <xsl:copy-of select="exsl:node-set($mine)/>
          <xsl:copy-of select="exsl:node-set($client)/>
        </both>
      </xsl:variable>
    
      <xsl:template match="exsl:node-set($both)/whatever>
        <xsl:apply-templates/>
      </xsl:template>
    
      <!-- More templates here to do what you will with all the data,
           whether it be copying, sorting first, or etc. -->
    </xsl:stylesheet>
    

    5) 将结果导入 Excel 文档。

    这很简单,我有一段时间没有这样做了,所以从那时起,Excel 中的一些特定步骤可能会随着版本的不同而发生变化。最后一步需要在转换之外完成,因为 XSLT 是非破坏性的(不会修改输入源文档,而只会输出新的结果文档。

    另外,它使用 XSLT 扩展函数 exsl:node-set()。根据您使用的工具,即 IE,您可能需要将其切换到 MSXSL 扩展版本。

    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    

    msxsl:node-set()
    

    分别。

    【讨论】:

    • 太棒了。谢谢你。我迫不及待想试试这个!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多