在某次开发中,突然有了需要使用php导入excel图片的功能,所以特意研究了下.
准备工作
首先,我们创建一个表格:
phpexcel库导入
在很久之前,我们导入excel使用的库是phpexcel库:composer require PHPOffice/Phpexcel
代码如下:<?php
include "./vendor/autoload.php";
//获取xlsx文件数据
function getExcel($file)
{
$reader = PHPExcel_IOFactory::load($file);//简易方式加载文件
$resule = $reader->getSheet(0)->toArray(null, false, false, true);//获取首个工作簿信息并转为数组
//过滤空白行
foreach ($resule as $key => $vo) {
if (count(array_unique($vo)) == 1) {
unset($resule[$key]);
}
}
array_walk_recursive($resule, function (&$nod) {
$nod === null ? ($nod = '&#