<?php /** * excel表格內容在網頁中顯示 * * 首先須要下載PHPExcel 工具包 * 網址: http://phpexcel.codeplex.com/releases/view/119187 * * @copyright 2007-2012 Xiaoqiang. * @author Xiaoqiang.Wu <jamblues@gmail.com> * @version 1.01 */ header("Content-type: text/html; charset=utf-8"); error_reporting(E_ALL); set_time_limit(0);//設置不超時 @ini_set('memory_limit', '512M');//設置PHP能使用的內存大小 date_default_timezone_set('Asia/ShangHai'); /** PHPExcel_IOFactory */ require_once './PHPExcel/IOFactory.php'; $filename = 'test2.xls'; // Check prerequisites if (!file_exists($filename)) { exit("not found 31excel5.xls.\n"); } $reader = PHPExcel_IOFactory::createReader('Excel5'); //設置以Excel5格式(Excel97-2003工做簿) $PHPExcel = $reader->load($filename); // 載入excel文件 $sheet = $PHPExcel->getSheet(0); // 讀取第一個工做表 $highestRow = $sheet->getHighestRow(); // 取得總行數 $highestColumm = $sheet->getHighestColumn(); // 取得總列數 $str = ''; $str .= '<table border="1" cellspacing="0" bordercolor="#eeeeee" cellpadding="5" width="100%">'; //按照excel表格格式輸出A-Z列 $str .= '<tr>'; $str .= '<td></td>'; for($column = 'A'; $column <= $highestColumm; $column++) { $str .= '<td>' .$column. '</td>'; } $str .= '</tr>'; //按照excel表格的格式從1開始累計 for ($row = 1; $row <= $highestRow; $row++){//行數是以第1行開始 $str .= '<tr>'; $str .= '<td>' .$row. '</td>'; //輸出excel表格的內容 for($column = 'A'; $column <= $highestColumm; $column++){ $str .= '<td>' .$sheet->getCell($column.$row)->getValue(). '</td>'; } $str .= '</tr>'; } $str .= '<table>'; echo $str; ?>