XSL:1.0
我有一个 XSL 脚本,它将公式输入到 Excel 单元格中,该单元格将由公式动态填充。单元格的内容只是数字(特别是小时)。我的目标是将这个新单元格设置为自定义类别格式并输入“[h]”。例如:格式=“[h]”
XSL:
<Cell ss:StyleID="cell_data" ss:Formula="=SUM(R[0]C[+1]-R[0]C[-2])">
</Cell>
我尝试添加 ss:Format
与 ss:Type="Number"
通过 <Data>
对此标签,但似乎无效。
风格是:
<Style ss:ID="cell_data">
<Font ss:Color="#000000" ss:FontName="Calibri"/>
<Interior ss:Color="#FFCC99" ss:Pattern="Solid"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
任何有关如何更改此单元格的建议都会非常有帮助。
最佳答案
要将数字单元格的格式更改为“常规”以外的格式,您可以执行以下操作。
1)添加样式或修改当前样式:
<Style ss:ID="NumberFormatS">
<NumberFormat ss:Format="[h]" />
</Style>
<NumberFormat ss:Format="[h]" />
将强制单元格将其类型更改为自定义 [h]。如果我输入 [h]:mm,它会将自定义类型更改为该值。
最后一部分只是将单元格调用设置为样式值:
<Cell ss:StyleID="NumberFormatS" ss:Formula="=SUM(R[0]C[+1]-R[0]C[-2])">
</Cell>
调用单元格后,单元格格式将交换为样式指定的格式。
关于xml - 向 Excel 单元格添加格式设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17110155/