PHPOffice/PhpSpreadsheet

2018年07月14日
保存 excel 图像 表格数据

https://github.com/PHPOffice/PhpSpreadsheet
https://stackoverflow.com/search?q=getDrawingCollection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use PhpOffice\PhpSpreadsheet\IOFactory;
use Illuminate\Support\Facades\Storage;

// laravel
$path = storage_path('app/1.xlsx');

$xlsx = IOFactory::load($path)->getActiveSheet();

// 保存图像
$imgs = [];
$imgData = $xlsx->getDrawingCollection();

foreach ($imgData as $value) {
$content = fopen($value->getPath(),'r');
$name = str_random(40).'.'.$value->getExtension();
$info = Storage::put($name, $content);
$imgs[] = $name;
}

// 获取数据
$datas = [];
$i = 0;
foreach ($xlsx->toArray() as $value) {
$datas[] = $value;
$datas['img'] = $imgs[$i];

$i++;
}