PHP代码可以将图像插入excel文件并在MS Excel中正确打开? [英] PHP code can insert image to excel file and open it correctly in MS Excel?

查看:365
本文介绍了PHP代码可以将图像插入excel文件并在MS Excel中正确打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I already have a document of excel and I want to use php to insert an image to that excel.

是否可以这样做?如何实现它(代码)?

Is it possible to do that? How to implement it (code)?

谢谢,

推荐答案

$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中正确打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆