gpt4 book ai didi

xml - 使用 XML 格式化 Excel 单元格

转载 作者:数据小太阳 更新时间:2023-10-29 02:23:23 27 4
gpt4 key购买 nike

我想以编程方式生成 Excel (Salesforce Apex),类似于下面的屏幕截图。单元格的数量、单元格的背景颜色将在运行时决定,因此使用编程方式。 enter image description here

为了实现这一点,我尝试为 Cell > Data 应用内联样式,但似乎我们不能在那里应用内联样式。例如,使用 ss:StyleID="s66" 将样式应用于第一个 Cell。但是对于第二个 Cell,它不能以这种方式处理内联样式。在我的要求中,因为我无法预先定义我需要一些动态方式的样式。谁能确认这是否不可能或提供任何指导?

<Row>

<Cell ss:StyleID="s66"><Data ss:Type="String">Test Sheet1</Data></Cell>
<Cell ><Data ss:Type="String"><Font ss:Color="#FF0000">Sample Text</Font></Data></Cell>

</Row>

最佳答案

您尝试使用的 XMLOffice 2003 SpreadsheetML。引用是 XML Spreadsheet Reference .

如果您查看“XML 电子表格标记层次结构”,您会发现 namespace ss 始终以前缀表示。所以它不是默认的命名空间。默认命名空间是 html。所以 FontBSup 标签没有命名空间前缀。

但在当前的 Excel 版本中,如果保存为 Office 2003 SpreadsheetML,则默认命名空间设置为 xmlns="urn:schemas-microsoft-com: office:spreadsheet"ss。因此,如果要使用 html 标签,它们必须以 html 为前缀。

例子:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<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">

<Worksheet ss:Name="Tabelle1">
<Table>
<Row>
<Cell><Data ss:Type="String"><html:Font x:Color="#FF0000">Test</html:Font></Data></Cell>
<Cell><Data ss:Type="String"><html:B>E = m c <html:Sup>2</html:Sup></html:B></Data></Cell>
</Row>
</Table>
</Worksheet>

</Workbook>

另一种选择是将默认命名空间更改为 xmlns="http://www.w3.org/TR/REC-html40",即 html。然后 html 标签不需要以 html 为前缀,但 ss 标签必须。

例子:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<ss:Workbook xmlns="http://www.w3.org/TR/REC-html40"
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">

<ss:Worksheet ss:Name="Tabelle1">
<ss:Table>
<ss:Row>
<ss:Cell><ss:Data ss:Type="String"><Font x:Color="#FF0000">Test</Font></Data></Cell>
<ss:Cell><ss:Data ss:Type="String"><B>E = m c <Sup>2</Sup></B></Data></Cell>
</ss:Row>
</ss:Table>
</ss:Worksheet>

</ss:Workbook>

关于xml - 使用 XML 格式化 Excel 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49249052/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com