50,526
社区成员
发帖
与我相关
我的任务
分享
import com.spire.xls.*;
public class xmltoexcel {
public static void main(String[] args) {
Workbook wb = new Workbook();
wb.loadFromXml("test.xml");//加载xml
wb.saveToFile("xmltoExcel.xlsx",FileFormat.Version2013);//转为2013版xlsx格式的Excel
wb.saveToFile("xmltoExcel.xls",FileFormat.Version97to2003);//转为03版xls格式的Excel
}
}
xml文件如下:
转出来的效果:
<?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">
<Created>2009-12-18T14:44:09Z</Created>
<Version>12.00</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>10005</WindowHeight>
<WindowWidth>10005</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>135</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Font ss:FontName="Verdana" x:Family="Swiss"/>
</Style>
<Style ss:ID="s62">
<Font ss:FontName="Verdana" x:Family="Swiss"/>
</Style>
<Style ss:ID="s63">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>
</Style>
</Styles>
<Worksheet ss:Name="Average">
<Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="2" x:FullColumns="1"
x:FullRows="1" ss:StyleID="s62" ss:DefaultColumnWidth="54">
<Column ss:StyleID="s62" ss:AutoFitWidth="0" ss:Width="140.25"/>
<Column ss:StyleID="s62" ss:AutoFitWidth="0" ss:Width="99.75" ss:Span="3"/>
<Row>
<Cell ss:StyleID="s63"><Data ss:Type="String">col1</Data></Cell>
<Cell ss:StyleID="s63"><Data ss:Type="String">col2</Data></Cell>
<Cell ss:StyleID="s63"><Data ss:Type="String">col3</Data></Cell>
<Cell ss:StyleID="s63"><Data ss:Type="String">col4</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
<Cell><Data ss:Type="Number">3</Data></Cell>
<Cell><Data ss:Type="Number">4</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>