gpt4 book ai didi

php - 将文件夹中的图像包含在 Excel 中

转载 作者:行者123 更新时间:2023-11-29 07:28:29 25 4
gpt4 key购买 nike

我需要将 windows 文件夹中的图像添加到 excel 工作表,以便每个图像都放在包含文件名的行条目的前面。

类似这样的东西-(文件名与该行中的 id 列条目相同) enter image description here

我可以使用哪种代码/语言来执行此操作?

我在 Mysql 中也有这个数据库,是否可以使用 php 在 excel 中包含图像。

非常感谢

最佳答案

假设您在项目中包含了 phpExcel 库,

include 'PHPExcel.php';
// you create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("Yassine CHABLI");
$objPHPExcel->getProperties()->setLastModifiedBy("Yassine CHABLI");
$objPHPExcel->getProperties()->setTitle("make whatever you want");
$objPHPExcel->getProperties()->setSubject("whatever you want");
$objPHPExcel->getProperties()->setDescription("including images test (example)");
// Add some data
$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setTitle('image example');

$Image = imagecreatefromjpeg('yassine.jpg');

$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('image');
$objDrawing->setDescription('image');
$objDrawing->setImageResource($Image);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

更多信息,请访问以下链接:

https://packagist.org/packages/phpoffice/phpexcel

notice: That will create an “xlsx” formatted file because it uses 2007 excel classes. if you want “xls” format just try with 2005 class and do not forget to change the file format to “xls” while using 2005.

关于php - 将文件夹中的图像包含在 Excel 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52697874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com