失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php使用PHPexcel类读取excel文件(循环读取每个单元格的数据)

php使用PHPexcel类读取excel文件(循环读取每个单元格的数据)

时间:2023-07-29 12:08:20

相关推荐

php使用PHPexcel类读取excel文件(循环读取每个单元格的数据)

error_reporting(E_ALL);

date_default_timezone_set('Asia/ShangHai');

include_once('Classes/PHPExcel/IOFactory.php');//包含类文件

$filename = "test.xls";//要读取的excel文件

if (!file_exists($filename)) {

exit("not found.\n");

}

$reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-工作簿)

$PHPExcel = $reader->load($filename); // 载入excel文件

$sheet = $PHPExcel->getSheet(0); // 读取第一個工作表

$highestRow = $sheet->getHighestRow(); // 取得总行数

$highestColumm = $sheet->getHighestColumn(); // 取得总列数

/** 循环读取每个单元格的数据 */

$dataset=array();

for ($row = 1; $row <= $highestRow; $row++){//行数是以第1行开始

for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始

$dataset[$row][] = $sheet->getCell($column.$row)->getValue();

echo $column.$row.":".$sheet->getCell($column.$row)->getValue()."<br />";

}

}

如果觉得《php使用PHPexcel类读取excel文件(循环读取每个单元格的数据)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。