-
- error_reporting(E_ALL);
-
- date_default_timezone_set('Asia/ShangHai');
-
- /**PHPExcel_IOFactory*/
- require_once '../Classes/PHPExcel/IOFactory.php' ;
-
- // Check prerequisites
- if (!file_exists("31excel5.xls")) {
- exit("not found 31excel5.xls.n");
- }
-
- $reader = PHPExcel_IOFactory::createReader('Excel5' ); //Set to Excel5 format (Excel97-2003 workbook)
- $PHPExcel = $reader->load("31excel5.xls"); //Load excel file
- $sheet = $PHPExcel->getSheet( 0); // Read the first worksheet
- $highestRow = $sheet->getHighestRow(); // Get the total number of rows
- $highestColumm = $sheet->getHighestColumn(); // Get the total number of columns
- $highestColumm= PHPExcel_Cell::columnIndexFromString($colsNum); //Convert letter column to numeric column such as: AA becomes 27
-
- /**Loop to read the data of each cell*/
- for ($row = 1; $row <= $ highestRow; $row++){//The number of rows starts with row 1
- for ($column = 0; $column < $highestColumm; $column++) {//The number of columns starts with column 0
- $columnName = PHPExcel_Cell ::stringFromColumnIndex($column);
- echo $columnName.$row.":".$sheet->getCellByColumnAndRow($column, $row)->getValue()."
";
- }
- }
- ?>
Copy code
Example 2, Simplified method of reading excel files:
-
- error_reporting(E_ALL);
-
- date_default_timezone_set('Asia/ShangHai');
-
- /**PHPExcel_IOFactory*/
- require_once '../Classes/PHPExcel/IOFactory.php ';
-
- // Check prerequisites
- if (!file_exists("31excel5.xls")) {
- exit("not found 31excel5.xls.n");
- }
-
- $reader = PHPExcel_IOFactory::createReader('Excel5 '); //Set to Excel5 format (Excel97-2003 workbook)
- $PHPExcel = $reader->load("31excel5.xls"); //Load excel file
- $sheet = $PHPExcel->getSheet (0); // Read the first worksheet
- $highestRow = $sheet->getHighestRow(); // Get the total number of rows
- $highestColumm = $sheet->getHighestColumn(); // Get the total number of columns
-
- /**Loop to read the data of each cell*/
- for ($row = 1; $row <= $highestRow; $row++){//The number of rows starts with row 1
- for ($column = 'A'; $column <= $highestColumm; $column++) {//The number of columns starts with column A
- $dataset[] = $sheet->getCell($column.$row)->getValue();
- echo $ column.$row.":".$sheet->getCell($column.$row)->getValue()."
";
- }
- }
- ?>
Copy Code
|