php-读取excel文件

2023-09-24 7 0

excel.php

<?php
$file = '1.xlsx';
if(!file_exists($file)){return "文件不存在";
}require_once "./PHPExcel/IOFactory.php";
//引入excel文件
$excel = PHPExcel_IOFactory::load($file);
//设置为默认表
$excel -> setActiveSheetIndex(0);
//获取表格数量
$sheetCount = $excel->getSheetCount();
//获取行数
$row = $excel->getActiveSheet()->getHighestRow();
//获取列数
$col = $excel->getActiveSheet()->getHighestColumn();
echo '表格数量:'.$sheetCount.';行数:'.$row.';列数:'.$col;$data = [];
for ($i=1;$i<=$row;$i++){for ($c = 'A';$c<=$col;$c++){$data[]=$excel->getActiveSheet()->getCell($c.$i)->getValue();}echo '<pre>';print_r($data);
}

效果图:在这里插入图片描述

代码编程
赞赏

相关文章

IOC容器——Unity 深度解析(一)
IOC容器——Unity
c#——标准Dispose模式的实现
c#——表达式树在LINQ动态查询
c#——ExpessionTree(表达式树)
c#—— Task.FromResult 的使用