本方法使用PHPEXCEL插件读取excel文件转化为数组了,后期还有没有完成的我们可以把转换成数组之后再保存到mysql数据库这个就非常的方便了,代码如下:
- <?php
-
-
-
-
- function importExcel($file)
- {
- require_once 'PHPExcel.php';
- require_once 'PHPExcel/IOFactory.php';
- require_once 'PHPExcel/Reader/Excel5.php';
- $objReader = PHPExcel_IOFactory::createReader('Excel5');
- $objPHPExcel = $objReader->load($file);
- $sheet = $objPHPExcel->getSheet(0);
- $highestRow = $sheet->getHighestRow();
- $highestColumn = $sheet->getHighestColumn();
- $objWorksheet = $objPHPExcel->getActiveSheet();
-
- $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
- $excelData = array();
- for ($row = 1; $row <= $highestRow; $row++) {
- for ($col = 0; $col < $highestColumnIndex; $col++) {
- $excelData[$row][] =(string)$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
- }
- }
- return $excelData;
- }
-
- importExcel('test.xsl');
-
- ?>
|