如果想要在导出的表格单元格加入图片,需要这样做。
① 使用PhpSpreadsheet导出
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require_once 'vendor/autoload.php';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
//将图片绘制到excel中
$drawing = new Drawing();
$drawing->setPath('图片位置');
$drawing->setHeight(50);//单元格高度
$drawing->setCoordinates('A1');
$drawing->setWorksheet($sheet);
$writer = new Xlsx($spreadsheet);
$writer->save('ggdoc.xlsx');
② 使用PHPExcel_Worksheet导出
require_once 'vendor/autoload.php';
$spreadsheet = new \PHPExcel();
$sheet = $spreadsheet->getActiveSheet();
//将图片绘制到excel中
$drawing = new \PHPExcel_Worksheet_Drawing();
$drawing->setPath('图片位置');
$drawing->setResizeProportional(false);
$drawing->setHeight(300);
$drawing->setWidth(200);
$drawing->setOffsetX(20);
$drawing->setOffsetY(20);
$drawing->setCoordinates('A1');
$drawing->setWorksheet($sheet);
$writer = \PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel2007');
$writer->save('ggdoc.xlsx');
代码仅供参考。
【版权提示】信息来自于互联网,不代表Intoep官方立场,内容仅供网友参考学习。如发现本站内容存在版权问题,烦请提供版权疑问、联系方式等发邮件至 1359125269@qq.com ,我们将及时沟通与处理。如若转载请联系原出处