mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 00:38:34 +00:00
29c0162e2a
* Let Phpstan Run on Samples Phpstan currently analyzes all source and test members. We already run phpcs and php-cs-fixer on samples as well. I would expect that samples are often used as templates for code in userland; it behooves us to be at least as careful with those members as for the others which are already being analyzed. Aside from 1300+ messages `Variable $helper might not be defined.`, which will be suppressed in phpstan.neon.dist, there are really only a few changes needed for sample members, so that part of the code base was already in good shape, and is now even better. No annotations were needed. * Scrutinizer 2 out of 3 1 false positive, now suppressed; fix other 2. * Remove Dead Code * Very Minor Changes * Add infra
74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf as TcpdfClass;
|
|
|
|
function replaceBody(string $html): string
|
|
{
|
|
$lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
|
|
$bodystring = '~<body>.*</body>~ms';
|
|
$bodyrepl = <<<EOF
|
|
<body>
|
|
<h1>Serif</h1>
|
|
<p style='font-family: serif; font-size: 12pt;'>$lorem</p>
|
|
<h1>Sans-Serif</h1>
|
|
<p style='font-family: sans-serif; font-size: 12pt;'>$lorem</p>
|
|
<h1>Monospace</h1>
|
|
<p style='font-family: monospace; font-size: 12pt;'>$lorem</p>
|
|
</body>
|
|
EOF;
|
|
|
|
return preg_replace($bodystring, $bodyrepl, $html) ?? '';
|
|
}
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
$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);
|
|
|
|
$helper->log('Write to Dompdf');
|
|
IOFactory::registerWriter('Pdf', Dompdf::class);
|
|
$filename = str_replace('.php', '_dompdf.php', __FILE__);
|
|
$helper->write(
|
|
$spreadsheet,
|
|
$filename,
|
|
['Pdf'],
|
|
false,
|
|
function (Dompdf $writer): void {
|
|
$writer->setEditHtmlCallback('replaceBody');
|
|
}
|
|
);
|
|
|
|
$helper->log('Write to Mpdf');
|
|
IOFactory::registerWriter('Pdf', Mpdf::class);
|
|
$filename = str_replace('.php', '_mpdf.php', __FILE__);
|
|
$helper->write(
|
|
$spreadsheet,
|
|
$filename,
|
|
['Pdf'],
|
|
false,
|
|
function (Mpdf $writer): void {
|
|
$writer->setEditHtmlCallback('replaceBody');
|
|
}
|
|
);
|
|
|
|
$helper->log('Write to Tcpdf');
|
|
IOFactory::registerWriter('Pdf', TcpdfClass::class);
|
|
$filename = str_replace('.php', '_tcpdf.php', __FILE__);
|
|
$helper->write(
|
|
$spreadsheet,
|
|
$filename,
|
|
['Pdf'],
|
|
false,
|
|
function (TcpdfClass $writer): void {
|
|
$writer->setEditHtmlCallback('replaceBody');
|
|
}
|
|
);
|