[QUESTION] How to Insert Image on a template file with multiple sheets #3249
Unanswered
luccasrafael
asked this question in
Q&A
Replies: 1 comment 4 replies
-
I could find a way of inserting the image using the test code below class TestExport implements WithEvents
{
use Exportable, RegistersEventListeners;
public static function beforeExport(BeforeExport $event)
{
$event->writer->reopen(new \Maatwebsite\Excel\Files\LocalTemporaryFile(storage_path('app/exports/report-front-page.xlsx')),Excel::XLSX);
$event->writer->getSheetByIndex(0);
$event->getWriter()->getSheetByIndex(0)->setCellValue('A1','Your Logo Goes Here');
return $event->getWriter()->getSheetByIndex(0);
}
public static function beforeWriting(BeforeWriting $event)
{
//
}
public static function beforeSheet(BeforeSheet $event)
{
//
}
public static function afterSheet(AfterSheet $event)
{
$drawing = new Drawing();
$drawing->setName('Logo');
$drawing->setDescription('This is my logo');
$drawing->setPath(storage_path('/img/other.png'));
$drawing->setHeight(50);
$drawing->setWidth(50);
$drawing->setCoordinates('D10');
$drawing->setWorksheet($event->sheet->getDelegate());
}
} However, now the image is inserted in a new worksheet. It seems that the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Versions
Description
I want to create a report that gets a template for the first worksheet, insert an image on this first worksheet, and insert more worksheets that don't need that image.
How can I:
Additional Information
My export class example is able to create the first worksheet based on the template. Also, it creates additional worksheets, but the image is not inserted on the first worksheet.
This is the current code.
This code creates the worksheet based on the template, creates many worksheets but does not add the image on the first worksheet.
Could this be a problem with
WithDrawings
not working withWithEvents
andWithMultipleSheets
or am I missing something?Beta Was this translation helpful? Give feedback.
All reactions