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 關注
- 296 瀏覽
添加回答
舉報