【问题标题】:Does ss:AutoFitHeight work for text?ss:AutoFitHeight 是否适用于文本?
【发布时间】:2014-05-29 18:23:37
【问题描述】:

我有一个 XML 文件,我保存为 .xls 以便在 Excel 中处理:

<results>
    <result>
        <companyName>Fnatic</companyName>
        <serviceID>1045</serviceID>
        <startDate>01-01-2014 00:00:00</startDate>
        <endDate>01-02-2014 00:00:00</endDate>
        <hours>1</hours>
        <description>Couple of paragraphs of text. Like 3 of them.</description>
    </result>
    ... more results
</results>

我使用 Excel XML 来定义 XML 数据的结构和样式。剩下要做的就是使“描述”单元格(即合并的列集)自动调整高度以适应其中的文本量。 ss:Row 似乎有 ss:AutoFitHeight。但是当我使用它们时,生成的.xls 文件没有发生任何变化。 ss:AutoFitHeight 是否不适用于文本,就像 ss:AutoFitWidth 不适用于 ss:Column 中的文本?

... rest of typical declarations

<xsl:template match="results">  

    <Styles>
        <Style ss:ID="Default" ss:Name="Normal">
          <Alignment ss:Vertical="Top" />
          <Borders />
          <Font />
          <Interior />
          <NumberFormat />
          <Protection />
        </Style>
        <Style ss:ID="s1">
          <Font ss:Size="10" ss:Bold="1" />
          <Interior ss:Color="#cef2ce" ss:Pattern="Solid" />
          <Alignment ss:Horizontal="Right" ss:Vertical="Top" />
        </Style>
        <Style ss:ID="s2">
          <Interior ss:Color="#C0C0C0" ss:Pattern="Solid" />
        </Style>
      </Styles>


      <Worksheet ss:Name="Worksheet">
            <Table x:FullColumns="1" x:FullRows="1">
            <Column ss:Width="77" />
            <Column ss:Width="65" />
            <Column ss:Width="246" />
            <Column ss:Width="26" />
            <xsl:apply-templates select="result" />
            <Row><!-- Last Row -->
                <Cell ss:Index="3"><Data ss:Type="String">Total:</Data></Cell>
                <Cell ss:Formula="=SUM(R[-{count(result)}]C:R[-1]C)">
                    <Data ss:Type="Number"></Data>
                </Cell>
            </Row>
        </Table>
    </Worksheet>
</xsl:template>

<xsl:template match="result">
    <Row>
        <xsl:apply-templates select="serviceID" />
        <xsl:apply-templates select="hours" />
    </Row>
    <Row ss:AutoFitHeight="1">
        <xsl:apply-templates select="description" />
    </Row>
</xsl:template>

<xsl:template match="serviceID">
    <Cell ss:StyleID="s1">
        <Data ss:Type="String">Service ID:</Data>
    </Cell>
    <Cell ss:StyleID="s2">
        <Data ss:Type="Number">
            <xsl:value-of select="."/>
        </Data>
    </Cell>
</xsl:template>

<xsl:template match="description">
    <Cell ss:StyleID="s1">
        <Data ss:Type="String">Description:</Data>
    </Cell>
    <Cell ss:MergeAcross="2">
        <Data ss:Type="String">
            <xsl:value-of select="."/>
        </Data>
    </Cell>
</xsl:template>
<xsl:template match="hours">
    <Cell ss:StyleID="s1">
        <Data ss:Type="String">Hours:</Data>
    </Cell>
    <Cell ss:StyleID="s2">
        <Data ss:Type="Number">
            <xsl:value-of select="."/>
        </Data>
    </Cell>
</xsl:template>

【问题讨论】:

标签: xml excel xslt xls


【解决方案1】:

删除列属性上的默认行高是违反直觉的,并且似乎与规范相矛盾(https://msdn.microsoft.com/en-us/library/office/aa140066(v=office.10).aspx#odc_xmlss_ss:row),但它有帮助。

【讨论】:

    猜你喜欢
    • 2018-11-13
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 2010-12-29
    • 1970-01-01
    相关资源
    最近更新 更多