3

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

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

谢谢,

4

1 回答 1

6
$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);
于 2012-07-05T11:32:16.030 回答