Commit aea71009 authored by clone's avatar clone

1

parent 633ddafa
<?php
namespace app\index\untils;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/8/16
* Time: 15:49
*/
class ImportExcelUntil
{
public function importExcel($file_path)
{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$spreadsheet = "";
try{
$spreadsheet = $reader->load($file_path);
}catch (\Exception $exception){
return "找不到文件路径";
}
$sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow(); // 最大行数
$highestColumn = $sheet->getHighestColumn(); // 最大列数
$highestColumn = "AB";
// 把下标变成数字,如A-Z分别对应1-26,AA对应27,AB对应28,以此类推
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
/* if($highestRow <= 2){ // 因为students.xlsx表格数据是从第三行开始的
exit('Excel没有任何数据');
}*/
$data = array();
for ($row = 0; $row <= $highestRow; $row++) {
$tempData['name'] = $sheet->getCellByColumnAndRow(1, $row)->getValue();
$tempData['chinese'] = $sheet->getCellByColumnAndRow(2, $row)->getValue();
$tempData['math'] = $sheet->getCellByColumnAndRow(3, $row)->getValue();
$tempData['English'] = $sheet->getCellByColumnAndRow(4, $row)->getValue();
$data[] = $tempData;
}
dump($data);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment