1,文件信息:
<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?>
2,正文部分应包含在<Workbook></Workbook>之间:
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:v="urn:schemas-microsoft-com:vml" 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"> …………………… </Workbook>
3, 文档属性选项应包含在Workbook标识中,并处于Worksheet范围之外:
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author>DuDu</Author> <LastAuthor>DuDu</LastAuthor> <LastPrinted>2012-08-31T06:18:54Z</LastPrinted> <Created>2012-08-31T06:21:45Z</Created> <LastSaved>2012-08-31T06:18:51Z</LastSaved> <Version>14.00</Version> </DocumentProperties>
4,ExcelWorkbook 记录了一些环境变量:
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>7830</WindowHeight> <WindowWidth>19395</WindowWidth> <WindowTopX>600</WindowTopX> <WindowTopY>90</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook>
5,在Worksheet之外可以定义多个Style,所有Style应位于<Styles></Styles>之间,这些Style在书写各单元格的时候会用到:
<Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Center"/> <Borders/> <Font ss:FontName="宋体" x:CharSet="134" ss:Size="11" ss:Color="#000000"/> <Interior/> <NumberFormat/> <Protection/> </Style> <Style ss:ID="m83836928"> <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/> <Borders> <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#000000"/> <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#000000"/> <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#000000"/> <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#000000"/> </Borders> <Font ss:FontName="宋体" x:CharSet="134" ss:Color="#000000"/> </Style> </Styles>
6,Worksheet标识之间定义了一个工作表,一个文件可以定义多个Worksheet:
<Worksheet> <xsl:attribute name="ss:Name">出库单<xsl:value-of select="Delivery/erpOutNo"/></xsl:attribute> <Table ss:ExpandedColumnCount="8" x:FullColumns="1" x:FullRows="1" ss:StyleID="s15" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="13.5"> ………………………… </Worksheet>
7,Worksheet之内有个Tables,定义了表的内容:
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1"> …… </Table>
注意:注意每行的列数和总的行数应该和<Table>中定义的一致,不然Excel导出后会报错“文件损坏”
8,每一个<Row></Row>之间定义的就是表格一行的内容,每个<Cell></Cell>则对应一个单元格,注意每行的列数和总的行数应该和<Table>中定义的一致:
<Row ss:AutoFitHeight="0" ss:Height="63.75"> <Cell ss:StyleID="s63"><Data ss:Type="String">A1</Data></Cell> <Cell ss:StyleID="s63"><Data ss:Type="String">B1</Data></Cell> </Row>
10,Table定义完之后,还可以用<>定义一些设置:
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <PageSetup> <Header x:Margin="0.19"/> <Footer x:Margin="0.51"/> <PageMargins x:Bottom="0.51" x:Left="0.17" x:Right="0.17" x:Top="0.28000000000000003"/> </PageSetup> <Print> <ValidPrinterInfo/> <PaperSizeIndex>256</PaperSizeIndex> <VerticalResolution>0</VerticalResolution> </Print> <Selected/> <DoNotDisplayGridlines/> <Panes> <Pane> <Number>3</Number> <ActiveRow>8</ActiveRow> <ActiveCol>2</ActiveCol> </Pane> </Panes> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions>