You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Install with Composer "phpoffice/phpspreadsheet": "3.8.0" and "mpdf/mpdf": "^8.2"
store the following file as "test.php" and execute it with php test.php
<?php// filename: test.phprequire_once__DIR__ . "vendor/autoload.php";
usePhpOffice\PhpSpreadsheet\Spreadsheet;
usePhpOffice\PhpSpreadsheet\Style\Alignment;
usePhpOffice\PhpSpreadsheet\Style\Border;
usePhpOffice\PhpSpreadsheet\Style\Color;
usePhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
usePhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = newSpreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// just some labels for better visualisation of the problem$worksheet->setCellValue("A1", "A");
$worksheet->setCellValue("B1", "B");
$worksheet->setCellValue("C1", "C");
// setting the row height to better visualize the problemfor ($i = 1; $i <= 10; $i++) {
$worksheet->getRowDimension($i)->setRowHeight(17);
}
// Headline - merged over two cells AND two rows$worksheet->mergeCells("B2:C3");
$worksheet->setCellValue("B2", "Hello World Headline");
$worksheet->getStyle("B2:C3")->getFont()->setBold(TRUE);
$worksheet->getStyle("B2:C3")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$worksheet->getStyle("B2:C3")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->setColor(newColor(Color::COLOR_BLACK));
// Content 1 - merge over two rows$worksheet->mergeCells("B4:B5");
$worksheet->mergeCells("C4:C5");
$worksheet->setCellValue("B4", "Label 1");
$worksheet->setCellValue("C4", "Text 1");
$worksheet->getStyle("B4:B5")->getFont()->setBold(TRUE);
$worksheet->getStyle("B4:C5")->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
$worksheet->getStyle("B4:B5")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->setColor(newColor(Color::COLOR_BLACK));
$worksheet->getStyle("C4:C5")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->setColor(newColor(Color::COLOR_BLACK));
// Content 2 - merge over two rows$worksheet->mergeCells("B6:B7");
$worksheet->mergeCells("C6:C7");
$worksheet->setCellValue("B6", "Label 2");
$worksheet->setCellValue("C6", "Text 2");
$worksheet->getStyle("B6:B7")->getFont()->setBold(TRUE);
$worksheet->getStyle("B6:C7")->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
$worksheet->getStyle("B6:B7")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->setColor(newColor(Color::COLOR_BLACK));
$worksheet->getStyle("C6:C7")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->setColor(newColor(Color::COLOR_BLACK));
// This is where the error is introduced (!!!)// Uncomment next line to produce correct results$worksheet->getColumnDimension("A")->setVisible(FALSE);
// Generate PDF$pdfWriter = newMpdf($spreadsheet);
$filename = 'filename_test';
$pdfWriter->writeAllSheets();
$pdfWriter->save($filename . '.pdf');
// Optional: Generate XLSY to compare$xlsxWriter = newXlsx($spreadsheet);
$xlsxWriter->save($filename . '.xlsx');
I narrowed it down to this setup to reproduce the error
What features do you think are causing the issue
Reader
Writer
Styles
Data Validations
Formula Calculations
Charts
AutoFilter
Form Elements
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
I don't know.
Which versions of PhpSpreadsheet and PHP are affected?
This error does not exist in "phpoffice/phpspreadsheet": "2.0" ...
I tested multiple versions when upgrading and found the error in all the later versions
The text was updated successfully, but these errors were encountered:
stevenbuehner
changed the title
PDFWriter produces nonsense as soon as some Columns are setVisible(false)
PDFWriter produces incorrectly merged cells as soon as some columns are setVisible(false)
Jan 14, 2025
Probably a result of PR #3945. Your output isn't exactly correct for PhpSpreadsheet V1 either - the hidden column is part of the output there, which is the problem the PR addressed. I will try to figure out why unhidden merged cells are affected.
oleibman
added a commit
to oleibman/PhpSpreadsheet
that referenced
this issue
Jan 15, 2025
FixPHPOffice#4319. PR PHPOffice#3495 allowed Mpdf and Tcpdf to handle hidden rows and columns. The handling is a little off when merged cells are part of the output. The fix for Mpdf is pretty straightforward. Tcpdf is a little more convoluted. Dompdf and Html do not require a change. Unit tests are added for the same scenario for all of Mpdf, Tcpdf, Dompdf, and Html.
This problem was introduced after Version 2.0. I realized it, when updating to "phpoffice/phpspreadsheet": "3.8.0"
This is a bug report
What is the expected behavior?
When a column is setVisible(false) I expect the PDF-Writer to still display merged cells correctly.
What is the current behavior?
When some colums in the spreadsheet are hidden, the phpWriter is not able to correctly format merged cells anymore.
Example
This is a screenshot of the generated PDF with column (A) set to visible:
This is how the same spreadsheet is generated by the PDF-writer, when column A is set to hidden:
What are the steps to reproduce?
"phpoffice/phpspreadsheet": "3.8.0"
and"mpdf/mpdf": "^8.2"
php test.php
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
I don't know.
Which versions of PhpSpreadsheet and PHP are affected?
"phpoffice/phpspreadsheet": "2.0"
...The text was updated successfully, but these errors were encountered: