php7.4 下使用phpExcel


前言

  php7.4后不支持 array{} 这种形式数组取值

  参考官方文档:7.4 版本的向后不兼容更改,非数组的数组样式访问,现在,尝试将 null,bool,int,float 或 resource 类型的值用作数组 ( 例如 $null[“key”] ) 会产生一个通知。

  修改后的PHPExcel链接:https://pan.baidu.com/s/1s7EtMKhS1rvhdurCYY5yIg  提取码:vx32

//简单使用例子:
//引入类库
include "../phpExce/Classes/PHPExcel/IOFactory.php";
//$inputFileName = mb_convert_encoding('账号名单.xlsx','GBK','UTF-8');
$inputFileName = 'test.xlsx';
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    echo "读取失败";
}

$sheet = $objPHPExcel->getSheet(0);// 0即第一个表
$highestRow = $sheet->getHighestRow();// 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数

// 获取excel文件的数据,$row=2代表从第二行开始获取数据
for ($row = 2; $row <= $highestRow+1; $row++){
    // rowData是一行的数据,遍历出来就是一列数据,字母A代表遍历所有列的数据,字母B开始就是单独遍历那一列的数据,我这里填写的C就是获取C列的数据
    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
    print_r(mb_convert_encoding($rowData,'GBK','UTF-8'));
}

 

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM