php生成excel ExcelWriterXML

一个用php生成excel的类库,生成的格式为xml,非常简单并且好用!Set of classes for PHP that allow Excel XML files to be generated dynamically. Nearly a full implementation of the MS XML architecture. Requires PHP 5+ Does not require any XML libraries.

2009-05-14 10:39:55

生成的excel是xml格式,用office2003/2007,openoffice全都能打开。
这个类库共有三个文件:
ExcelWriterXML.php Class for generating the initial Excel XML document
ExcelWriterXML_Sheet.php Class for generating sheets within the Excel document
ExcelWriterXML_Style.php Style class for generating Excel styles

生成excel过程简要描述:

$xml = new ExcelWriterXML; //生成一个xml的excel
$xml->docAuthor('Robert F Greer'); //写入作者

$format = $xml->addStyle('StyleHeader'); //生成一个样式
$format->fontBold(); //字体加粗
$format->alignRotate(45); //旋转45度
$sheet = $xml->addSheet('My Sheet'); //加入一张表

$sheet->writeString(1,1,'Header','StyleHeader'); //以StyleHeader的样式在第一行第一列写入文字
$sheet->writeString(2,1,'Test String','StyleHeader');//以StyleHeader的样式在第二行第一列写入文字

$xml->sendHeaders();//输出http header
$xml->writeData();//写出xml


这个类库不能设置页边距,如果想改的话,只能自己修改类库,或在输出出来的xml上修改

附上页边距修改的xml:

<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0"/>
<Footer x:Margin="0"/>
<PageMargins x:Bottom="0.19685039370078741" x:Left="0.94488188976377963" x:Right="0.94488188976377963" x:Top="0.19685039370078741"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<Scale>86</Scale>
<HorizontalResolution>-3</HorizontalResolution>
<VerticalResolution>0</VerticalResolution>
</Print>
</WorksheetOptions>


下载地址:http://excelwriterxml.sourceforge.net/

徜徉于这片废土的我们.....应当去哪里追寻更好的自己?