mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-21 03:19:04 +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.
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
|
|
$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php';
|
|
|
|
$helper->log('Hide grid lines');
|
|
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
|
|
|
$helper->log('Set orientation to landscape');
|
|
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
|
|
$spreadsheet->setActiveSheetIndex(0)->setPrintGridlines(true);
|
|
// Issue 2299 - mpdf can't handle hide rows without kludge
|
|
$spreadsheet->getActiveSheet()->getRowDimension(2)->setVisible(false);
|
|
|
|
function changeGridlines(string $html): string
|
|
{
|
|
return str_replace('{border: 1px solid black;}', '{border: 2px dashed red;}', $html);
|
|
}
|
|
|
|
$helper->log('Write to Mpdf');
|
|
IOFactory::registerWriter('Pdf', Mpdf::class);
|
|
$helper->write(
|
|
$spreadsheet,
|
|
__FILE__,
|
|
['Pdf'],
|
|
false,
|
|
function (Mpdf $writer): void {
|
|
$writer->setEmbedImages(true);
|
|
$writer->setEditHtmlCallback('changeGridlines');
|
|
}
|
|
);
|