XML您尝试使用的是Office 2003 SpreadsheetML. 参考是XML 电子表格参考。
如果您查看“XML Spreadsheet Tag Hierarchy”,您将看到名称空间ss总是在那里添加前缀。所以它不是默认的命名空间。默认命名空间是html. 所以Font, B,Sup标签不以命名空间为前缀。
但在当前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>