首页 > 解决方案 > 使用 phpspreedsheet 将图像链接到单元格

问题描述

我正在使用此代码在列和单元格中添加图像。

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img);
imagecopyresampled($image_p, $image, 0, 0 , 0 , 0, $width, $height, $width_orig, $height_orig);
$draw->setName($itmref[$key]);
$draw->setResizeProportional(false);
$draw->setImageResource($image_p);
$draw->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
$draw->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
$draw->setCoordinates('B'.$i);
$draw->setWorksheet($this->_spreadsheet->getActiveSheet());

问题是它们没有链接到单元格,因此如果用户过滤或排序 Excel 文件,图像将保留在其位置。

在 VBA 中,参数为:

Selection.Placement = xlMoveAndSize

但我在 PhpSpreedSheet 中找不到匹配项。

标签: phpexcelphpspreadsheet

解决方案


推荐阅读