phpExcel 網址:http://phpexcel.codeplex.com/
底下原始碼, 假設將 phpExcel 放在 httpd 所設定的 $DocumentRoot/phpExcel 下面
另外,tag <> 內的空格須自行刪除,加空格目的是避免此 blog 會當成tag 來解釋, 而影響 php 原始碼的閱讀性,
< ?php
require_once './phpExcel/Classes/PHPExcel.php';
require_once './phpEXCEL/Classes/PHPExcel/IOFactory.php';
header("Content-Type: text/html; charset=big5");
$file="sample.xls";
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '< table border="1">';
foreach ( $objWorksheet->getRowIterator() as $row )
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
echo '< tr>';
foreach ($cellIterator as $cell)
{
echo '< td>';
echo iconv('utf-8','big5', $cell->getValue() . ' ');
echo '< /td>';
}
echo '< /tr>';
}
echo '< /table>';
?>