如何在不安装Office/Excel的情况下将Excel XML/Xml Spreadsheet 2003转为.xlsx格式
需求:解析Excel XML(Xml Spreadsheet 2003)格式文件
- 输入文件为单个XML文件,由Excel的「Xml Spreadsheet 2003」(俗称「Excel XML」格式)生成,其命名空间如下:
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
(文末附示例文件)
可使用的开发环境:.NET、JVM或Python,这些环境有大量Excel操作第三方库,但目前除Excel本身外,似乎无工具能实现该格式的解析转换。
额外限制:不能依赖Excel,即运行代码的操作系统几乎不会安装Excel。
补充说明:已查阅大量同类问题的帖子,均无有效解决方案——要么提到的第三方包不支持该格式,要么建议改用其他格式生成输入文件,但后者不可行。
示例文件
<?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"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author></Author> <LastAuthor></LastAuthor> <Created>2022-12-15T10:58:05Z</Created> <Version>16.00</Version> </DocumentProperties> <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"> <AllowPNG/> </OfficeDocumentSettings> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>5556</WindowHeight> <WindowWidth>17256</WindowWidth> <WindowTopX>32767</WindowTopX> <WindowTopY>32767</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Bottom"/> <Borders/> <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/> <Interior/> <NumberFormat/> <Protection/> </Style> </Styles> <Worksheet ss:Name="Sheet1"> <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="14.4"> </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <PageSetup> <Header x:Margin="0.3"/> <Footer x:Margin="0.3"/> <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/> </PageSetup> <Selected/> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook>
内容的提问来源于stack exchange,提问作者MrD at KookerellaLtd
相关产品推荐
相关产品推荐

