-
- /**
- *
- * @copyright 2007-2012 xiaoqiang.
- * @author xiaoqiang.wu
- * @version 1.01
- */
-
- 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 the letter column to a 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 from row 1
- for ($column = 0; $column < $highestcolumm; $column++) {//The number of columns It starts with column 0
- $columnname = phpexcel_cell::stringfromcolumnindex($column);
- echo $columnname.$row.":".$sheet->getcellbycolumnandrow($column, $row)->getvalue() ."
";
- }
- }
- ?>
Copy code
Example 2, a streamlined method for phpexcel to read excel files.
-
- /**
- *
- * @copyright 2007-2012 xiaoqiang.
- * @author xiaoqiang.wu
- * @version 1.01
- */
-
- 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 is based on row 1 Start
- 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
The above are the methods and examples of phpexcel reading files. To download the latest version of phpexcel, please visit the phpexcel official website address: http://phpexcel.codeplex.com/
|