PHP reads the contents of an Excel table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.