mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 02:38:26 +00:00
fadfb727bf
See discussion in #2999. Mpdf is not acknowledging the styling that we're using to hide table rows. I have opened an issue with them, but enclosing the cells in the hidden row inside a div with appropriate css does seem to be a workaround, and that can be incorporated into PhpSpreadsheet. It's kludgey, and it isn't even valid HTML, but ... Mpdf also doesn't like the addition of the ```file:///``` prefix when using local images from Windows (sample 21). Results are better when that prefix is not added. Dompdf seemed to have problems with sample 21 images on both Windows and Unix, with or without the file prefix. It does, however, support data urls for both, so is changed to embed images. It's still not perfect - the image seems truncated to the row height - but the results are better. I will continue to research, but may proceed as-is if I don't find anything better to do. Html Writer was producing a file with mixed line endings on Windows. This didn't cause any harm, but it seems a bit sloppy. It is changed to always use PHP_EOL as a line ending.
28 lines
986 B
PHP
28 lines
986 B
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
|
|
|
|
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);
|
|
$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');
|
|
$writer = new Mpdf($spreadsheet);
|
|
$filename = $helper->getFileName('21a_Pdf_mpdf.xlsx', 'pdf');
|
|
$writer->setEditHtmlCallback('changeGridlines');
|
|
$writer->save($filename);
|