首先是用composer安装phpoffice/phpspreadsheet 具体代码 //读取数据 private function readYewuExcel(){ $reader = IOFactory::createReader("Xlsx"); $reader-setReadDataOnly(TRUE); $spreadsheet = $reader-load('yewu.xlsx'); //载入exc
首先是用composer安装phpoffice/phpspreadsheet
具体代码
//读取数据
private function readYewuExcel(){
$reader = IOFactory::createReader("Xlsx");
$reader->setReadDataOnly(TRUE);
$spreadsheet = $reader->load('yewu.xlsx'); //载入excel表格 路径和文件名
$spreadsheet->setActiveSheetIndex(0);//指定excel的sheet 0是第一个
$worksheet = $spreadsheet->getActiveSheet();
$highestRow = $worksheet->getHighestRow(); // 总行数
$highestColumn = $worksheet->getHighestColumn(); // 总列数 没用到
$highestColumnIndex = Coordinate::columnIndexFromString($highestColumn); //没用到
$lines = $highestRow;
if ($lines <= 0) {
exit('Excel表格中没有数据');
}
$yewulist = [];
for ($row = 2; $row <= $highestRow; ++$row) {//因为第一行是标题,所以从第二行开始,所以是row=2
//getCellByColumnAndRow(列数,行数)//获取单元格内容
$name = $worksheet->getCellByColumnAndRow(1, $row)->getValue(); //业务名称
$content = $worksheet->getCellByColumnAndRow(2, $row)->getValue(); //客户详情
$btime = $worksheet->getCellByColumnAndRow(4, $row)->getValue(); //开始时间
$etime = $worksheet->getCellByColumnAndRow(5, $row)->getValue(); //结束时间
$gongyingshang = $worksheet->getCellByColumnAndRow(8, $row)->getValue(); //供应商
$yewulist[] = [
'name'=>$name,
'content'=>$content,
'create_time'=>$btime,
//......
];
}
return $yewulist;
}
【转自:美国高防站群服务器 http://www.558idc.com/mggfzq.html 复制请保留原URL】