我想用 xls 生成一个 excel .xls 文件。我已经想出了如何生成文件。只有在 MS Excel 中打开文件时,才会出现以下错误。
文件已损坏,无法打开。
这是输出;
enterFile: Order_2013.xls
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"><Styles><Style xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:ID="Default" ss:Name="Normal"><Alignment ss:Vertical="Bottom"/><Borders/><Font/><Interior/><NumberFormat/><Protection/></Style><Style xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:ID="s21"><Font ss:Size="22" ss:Bold="1"/></Style><Style xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:ID="s22"><Font ss:Size="14" ss:Bold="1"/></Style><Style xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:ID="s23"><Font ss:Size="12" ss:Bold="1"/></Style><Style xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:ID="s24"><Font ss:Size="10" ss:Bold="1"/></Style></Styles><Worksheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:Name="order"><Table><Column ss:AutoFitWidth="0" ss:Width="85"/><Column ss:AutoFitWidth="0" ss:Width="115"/><Column ss:AutoFitWidth="0" ss:Width="115"/><Column ss:AutoFitWidth="0" ss:Width="160"/><Column ss:AutoFitWidth="0" ss:Width="115"/><Column ss:AutoFitWidth="0" ss:Width="85"/><Column ss:AutoFitWidth="0" ss:Width="85"/><Column ss:AutoFitWidth="0" ss:Width="160"/><Row ss:AutoFitHeight="0" ss:Height="27.75"><Cell ss:StyleID="s21"><Data ss:Type="String">Example Spreadsheet</Data></Cell></Row><Row ss:AutoFitHeight="0" ss:Height="18"><Cell ss:StyleID="s22"><Data ss:Type="String">Vuurvlinderronde 15</Data></Cell></Row><Row><Cell><Data ss:Type="String">
test
</Data></Cell></Row><Row xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" ss:AutoFitHeight="0" ss:Height="18"><Cell ss:StyleID="s23"><Data ss:Type="String">
Collumn 1
</Data></Cell></Row><Row xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><Cell ss:StyleID="s24"><Data ss:Type="String">
Collumn 2
</Data></Cell><Cell ss:StyleID="s24"><Data ss:Type="String">
Collumn 3
</Data></Cell><Cell ss:StyleID="s24"><Data ss:Type="String">
Collumn 4
</Data></Cell><Cell ss:StyleID="s24"><Data ss:Type="String">
Collumn 5
</Data></Cell></Row></Table></Worksheet></Workbook> code here
这是 xsl 样式表
<?xml version="1.0" encoding="ISO-8859-1"?>
<?mso-application progid="Excel.Sheet"?>
<files>
<file filename="Order_%Y%.xls">
<xsl:stylesheet version="1.0"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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">
<xsl:template match="/">
<xsl:for-each select="orders/order">
<Workbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
<Style ss:ID="s21">
<Font ss:Size="22" ss:Bold="1" />
</Style>
<Style ss:ID="s22">
<Font ss:Size="14" ss:Bold="1" />
</Style>
<Style ss:ID="s23">
<Font ss:Size="12" ss:Bold="1" />
</Style>
<Style ss:ID="s24">
<Font ss:Size="10" ss:Bold="1" />
</Style>
</Styles>
<Worksheet ss:Name="order">
<Table>
<Column ss:AutoFitWidth="0" ss:Width="85" />
<Column ss:AutoFitWidth="0" ss:Width="115" />
<Column ss:AutoFitWidth="0" ss:Width="115" />
<Column ss:AutoFitWidth="0" ss:Width="160" />
<Column ss:AutoFitWidth="0" ss:Width="115" />
<Column ss:AutoFitWidth="0" ss:Width="85" />
<Column ss:AutoFitWidth="0" ss:Width="85" />
<Column ss:AutoFitWidth="0" ss:Width="160" />
<Row ss:AutoFitHeight="0" ss:Height="27.75">
<Cell ss:StyleID="s21">
<Data ss:Type="String">Voorbeeld</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="18">
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="shipping/street" />
</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="String">
test
</Data>
</Cell>
</Row>
<xsl:call-template name="orders" />
</Table>
</Worksheet>
</Workbook>
</xsl:for-each>
</xsl:template>
<xsl:template name="orders">
<Row ss:AutoFitHeight="0" ss:Height="18">
<Cell ss:StyleID="s23">
<Data ss:Type="String">
Collumn 1
</Data>
</Cell>
</Row>
<Row>
<Cell ss:StyleID="s24">
<Data ss:Type="String">
Collumn 2
</Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String">
Collumn 3
</Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String">
Collumn 4
</Data>
</Cell>
<Cell ss:StyleID="s24">
<Data ss:Type="String">
Collumn 5
</Data>
</Cell>
</Row>
<xsl:for-each
select="orders/order">
<Row>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="order_id" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="order_id" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="order_id" />
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="order_id" />
</Data>
</Cell>
</Row>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</file>
</files>
我希望有人能指出我正确的解决方案。
提前致谢!
Ĵ