我正在使用这个包在Laravel中生成Excel文档:https://github.com/Maatwebsite/Laravel-Excel
然而,文档没有提到如何将文件中的图片插入到我的Excel文档中。我相信这是可能的,在原生phpexcel中可以实现,但通过这个包如何实现呢?
希望能给出一些示例代码。
我正在使用这个包在Laravel中生成Excel文档:https://github.com/Maatwebsite/Laravel-Excel
然而,文档没有提到如何将文件中的图片插入到我的Excel文档中。我相信这是可能的,在原生phpexcel中可以实现,但通过这个包如何实现呢?
希望能给出一些示例代码。
首先需要声明类 use PHPExcel_Worksheet_Drawing;
然后在控制器中:
$filename = 'File Name';
Excel::create($filename, function($excel){
$excel->sheet('sheet name', function($sheet){
$objDrawing = new PHPExcel_Worksheet_Drawing;
$objDrawing->setPath(public_path('img/headerKop.png')); //your image path
$objDrawing->setCoordinates('A2');
$objDrawing->setWorksheet($sheet);
});
})->export('xls');
新版本3.1
导入
使用Maatwebsite\Excel\Concerns\WithDrawings;
使用PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
和
类InvoicesExport实现WithDrawings接口。
public function drawings()
{
$drawing = new Drawing();
$drawing->setName('Logo');
$drawing->setDescription('This is my logo');
$drawing->setPath(public_path('/img/vir.png'));
$drawing->setHeight(90);
$drawing->setCoordinates('B3');
return $drawing;
}