Files
PhpSpreadsheet/samples/Basic4/53_ImageOpacity.php
T
oleibman 5c3ae52446 Fix Minor Break Handling Drawings
Fix #4241. Some security batches caused a minor break in Drawings, forcing `setWorksheet` to come after `setPath`. Although the problem is easily fixed in user code, this was not an intended change. Some slight recoding restores the earlier functionality where the order of calls was not important, without sacrificing the security gains. This change will be back-ported to the other active branches to which the security patch had been applied.
2024-11-25 19:54:38 -08:00

67 lines
1.9 KiB
PHP

<?php
require __DIR__ . '/../Header.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'images/blue_square.png';
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setTitle('53_ImageOpacity');
$helper->log('Add image to spreadsheet 6 times with different opacities');
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Squares different opacities');
$sheet->setShowGridLines(false);
$drawing = new Drawing();
$drawing->setName('Blue Square opacity not specified');
$drawing->setPath($path);
$drawing->setCoordinates('A1');
$drawing->setCoordinates2('B5');
$drawing->setWorksheet($sheet);
$drawing = new Drawing();
$drawing->setName('Blue Square opacity 80%');
$drawing->setPath($path);
$drawing->setCoordinates('C1');
$drawing->setCoordinates2('D5');
$drawing->setOpacity(80000);
$drawing->setWorksheet($sheet);
$drawing = new Drawing();
$drawing->setWorksheet($sheet);
$drawing->setName('Blue Square opacity 60%');
$drawing->setPath($path);
$drawing->setCoordinates('E1');
$drawing->setCoordinates2('F5');
$drawing->setOpacity(60000);
$drawing = new Drawing();
$drawing->setName('Blue Square opacity 40%');
$drawing->setPath($path);
$drawing->setCoordinates('A8');
$drawing->setCoordinates2('B12');
$drawing->setOpacity(40000);
$drawing->setWorksheet($sheet);
$drawing = new Drawing();
$drawing->setName('Blue Square opacity 20%');
$drawing->setPath($path);
$drawing->setCoordinates('C8');
$drawing->setCoordinates2('D12');
$drawing->setOpacity(20000);
$drawing->setWorksheet($sheet);
$drawing = new Drawing();
$drawing->setWorksheet($sheet);
$drawing->setName('Blue Square opacity 0%');
$drawing->setPath($path);
$drawing->setCoordinates('E8');
$drawing->setCoordinates2('F12');
$drawing->setOpacity(0);
// Save
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Html', 'Dompdf', 'Mpdf']);
$spreadsheet->disconnectWorksheets();