我已经有一个 excel 文档,我想使用 php 将图像插入到该 excel 中。

有可能这样做吗?如何实现它(代码)?

谢谢,

最佳答案

$fileType = 'Excel2007';
$fileName = 'test.xlsx';

// Load the workbook
$objPHPExcelReader = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objPHPExcelReader->load($fileName);

// Add an image to the worksheet
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('My Image');
$objDrawing->setDescription('The Image that I am inserting');
$objDrawing->setPath('./images/myImage.png');
$objDrawing->setCoordinates('B2');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

// Save the workbook
$objPHPExcelWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,$fileType);
$objPHPExcelWriter->save($fileName);

关于PHP代码可以将图像插入到excel文件中并在MS Excel中正确打开吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11337142/

10-11 08:04