大家好,又见面了,我是你们的朋友全栈君。
JS 将数据生成Excel(XML) 并保存为.xls文件,已封装可以直接使用
简单写法:
<?xml version="1.0" encoding="UTF-8"?>
<?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="tt">
<Table>
<Row>
<Cell><Data ss:Type="String">Hello!World!</Data></Cell>
<Cell><Data ss:Type="Number">123</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
注意 ss:Type=“String” 里面的类型需要首字母大写。
复杂写法,需要包含字体,字号,颜色…
<?xml version="1.0" encoding="UTF-8"?>
<?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">
<Title>Excel表格</Title>
<LastAuthor>bigtall</LastAuthor>
</DocumentProperties>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/>
</Style>
</Styles>
<Worksheet ss:Name="tt">
<Table>
<Row>
<Cell ss:MergeAcross="6" ><Data ss:Type="String">Hello!World!</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/171962.html原文链接:https://javaforall.cn