mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 20:58:19 +00:00
ecbd702628
Phpstan hasn't identified any errors in Samples in a long time. But, as it turns out, one particular error is suppressed: ``` Variable $helper might not be defined. ``` This error would be generated by almost all samples, and the errors that it suppresses will become problematic if we move to Level 10. We are not yet committed to doing that, but it is pretty easy to write a script to change the samples so that error no longer happens, and there isn't really any reason to delay doing so. The results of that script constitute this PR.
28 lines
924 B
PHP
28 lines
924 B
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
|
|
|
|
// Read from Xlsx (.xls) template
|
|
$helper->log('Load Xlsx template file');
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
// Note that Xlsx converts bmp to png, so it needs to be added
|
|
// programmatically rather than in template.
|
|
// Also note Xls converts both bmp and gif to png.
|
|
$spreadsheet = $reader->load(__DIR__ . '/../templates/27template.xlsx');
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$drawing = new Drawing();
|
|
$drawing->setName('Test BMP');
|
|
$drawing->setPath(__DIR__ . '/../images/bmp.bmp');
|
|
$drawing->setCoordinates('G17');
|
|
$drawing->setWorksheet($sheet);
|
|
|
|
$sheet->getCell('G16')->setValue('BMP');
|
|
$sheet->getStyle('G16')->getFont()->setName('Arial Black')->setBold(true);
|
|
|
|
// Save
|
|
$helper->write($spreadsheet, __FILE__);
|