PHPExcel: read Excel from LAMP
Posted on 22. Oct, 2009 by oshua in PHP
PHPExcel (http://www.phpexcel.net) is a set of classes to read and write Excel effectively, but it is even much more than just that. Among the many features available in it, PHPExcel can
- Set spreadsheet meta data (author, title, description, …)
- Add worksheets to spreadsheet
- Add data and formulas to individual cells
- Merge cells
- Protect ranges of cells with a password
- Support formatting
- Support hyperlinks
I was impressed by how easy it was to read an Excel file with PHPExcel. Here is a sample:
<?php
error_reporting(E_ALL);
require_once 'Classes/PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("test.xls");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>
There are many interesting things that can be done with PHPExcel, like an application that allows users to download a personalized calculation sheet for accounting or finance purposes or exporting tables from databases adding formats and hyperlinks for a better understanding of their content.
But the best is yet to come. There is some work already done in communicating with Google Docs, adding chart support and there is a sister project to read/generate Power Point files from PHP

[转贴] Read excel from LAMP – Sense's Blog
Oct 9th, 2010
[...] 转贴自:http://www.oshuamoreno.com/2009/10/phpexcel-read-excel-from-lamp/ [...]