3 回答
TA贡献1859条经验 获得超6个赞
正如@FabriceFabiyi在他的评论中提到的,阅读后:
关于绘图的PhpSpreadseet文档。
关于file_get_contents的PHP 文档。
关于file_set_contents的PHP 文档。
这对我有用:
$image = file_get_contents('https://website.com/path/to/image');
$imageName = 'a_nice_image_name';
//You can save the image wherever you want
//I would highly recommand using a temporary directory
$temp_image=tempnam(sys_get_temp_dir(), $imageName);
file_put_contents($temp_image, $image);
// And then PhpSpreadsheet acts just like it would do with a local image
$drawing->setPath($temp_image);
$drawing->setHeight(36);
$drawing->setWorksheet($sheet);
$drawing->setCoordinates('B15');
有关 PHP 文档中临时目录的更多信息:
TA贡献1770条经验 获得超3个赞
有一个示例如何将图像添加到您的 excel 导出中:
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Paid');
$drawing->setDescription('Paid');
$drawing->setPath('/images/image-1.png'); // put your path and image here
$drawing->setHeight(30);
$drawing->setCoordinates('A5');
$drawing->setOffsetX(110);
$drawing->setRotation(25);
$drawing->getShadow()->setVisible(true);
$drawing->getShadow()->setDirection(45);
$drawing->setWorksheet($spreadsheet->getActiveSheet());
TA贡献1784条经验 获得超2个赞
根据示例和文档,指定图像的坐标可能会有所帮助
$objDrawing->setCoordinates('A3');
请注意,图像不在单元格/列/行中,而是覆盖在与该单元格/列/行相同的位置的主工作表上
- 3 回答
- 0 关注
- 260 浏览
添加回答
举报