<?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; ?>