用于读/写MS Excel文件的PHP库?

时间:2011-02-04 14:35:24

标签: php excel

是否有免费的PHP库来读取/写入excel文件?我不想使用XML(我认为你可以将excel文件读成XML,我不想这样做)。我还需要创建图表和其他好东西,因此将文件保存为csv也不起作用。

4 个答案:

答案 0 :(得分:4)

也许http://phpexcel.codeplex.com/正是您要找的?

答案 1 :(得分:0)

答案 2 :(得分:0)

你必须下载该库,然后使用下面的代码用图表读/写excel: -

  

http://phpexcel.codeplex.com/

<?php 
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
require_once '../Classes/PHPExcel/IOFactory.php';
require_once '../Classes/PHPExcel.php';
$excel2 = PHPExcel_IOFactory::createReader('Excel2007');

/*Enable chart read on excel*/
$excel2->setIncludeCharts(TRUE);
/*Enable chart read on excel*/

$excel2 = $excel2->load('excelname.xlsx'); // Empty Sheet

/*update cell data if you required */
$excel2->getActiveSheet()->setCellValue('B6', '2');
$excel2->getActiveSheet()->setCellValue('B7', '1');
$excel2->getActiveSheet()->setCellValue('B8', '3');
/*-----------------------------*/

$objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007');
/*Enable chart write on excel*/
$objWriter->setIncludeCharts(TRUE);
/*Enable chart write on excel*/
$objWriter->save('excelout.xlsx');
?>

答案 3 :(得分:0)

I would recommend to use MS-Excel Stream Handler PHP class, which is one of the top class library for that :)

There is a great article to explain how to read/write excel files through php code.