<?PHP/** * Excel table content appears in Web page * * First download phpexcel toolkit * URL: http://phpexcel.codeplex.com/releases/view/119187 * * @copyright 200 7-2012 Xiaoqiang. * @author Xiaoqiang.wu <[email protected]> * @version 1.01*/ Header("content-type:text/html; Charset=utf-8 ");error_reporting(E_all);Set_time_limit(0);//setting does not time out@Ini_set(' Memory_limit ', ' 512M ');//set the amount of memory that PHP can useDate_default_timezone_set (' Asia/shanghai ');/** Phpexcel_iofactory*/require_once'./phpexcel/iofactory.php ';$filename= ' Test2.xls '; //Check Prerequisitesif(!file_exists($filename)) { Exit("Not Found 31excel5.xls.\n");} $reader= Phpexcel_iofactory::createreader (' Excel5 ');//set in EXCEL5 format (excel97-2003 workbook)$PHPExcel=$reader->load ($filename);//Loading Excel Files$sheet=$PHPExcel->getsheet (0);//read the first worksheet$highestRow=$sheet->gethighestrow ();//total number of rows obtained$highestColumm=$sheet->gethighestcolumn ();//total number of columns obtained$str= ' ';$str. = ' <table border= ' 1 "cellspacing=" 0 "bordercolor=" #eeeeee "cellpadding=" 5 "width=" 100% "> ';//output A-z column in Excel table format$str. = ' <tr> '; $str. = ' <td></td> '; for($column= ' A ';$column<=$highestColumm;$column++){ $str. = ' <td> '.$column. ' </td> ';}$str. = ' </tr> ';//follow Excel table format starting from 1 for($row= 1;$row<=$highestRow;$row++){//The number of rows starts at line 1th $str. = ' <tr> '; $str. = ' <td> '.$row. ' </td> '; //output the contents of an Excel table for($column= ' A ';$column<=$highestColumm;$column++){ $str. = ' <td> '.$sheet->getcell ($column.$row)->getvalue (). ' </td> '; } $str. = ' </tr> ';}$str. = ' <table> ';Echo $str; ?>
PHP reads the contents of an Excel table