@@ -103,6 +103,8 @@ class Html extends BaseWriter
103
103
104
104
/**
105
105
* Is the current writer creating mPDF?
106
+ *
107
+ * @deprecated 2.0.1 use instanceof Mpdf instead
106
108
*/
107
109
protected bool $ isMPdf = false ;
108
110
@@ -454,7 +456,7 @@ public function generateSheetData(): string
454
456
455
457
// Get worksheet dimension
456
458
[$ min , $ max ] = explode (': ' , $ sheet ->calculateWorksheetDataDimension ());
457
- [$ minCol , $ minRow ] = Coordinate::indexesFromString ($ min );
459
+ [$ minCol , $ minRow, $ minColString ] = Coordinate::indexesFromString ($ min );
458
460
[$ maxCol , $ maxRow ] = Coordinate::indexesFromString ($ max );
459
461
$ this ->extendRowsAndColumns ($ sheet , $ maxCol , $ maxRow );
460
462
@@ -467,16 +469,20 @@ public function generateSheetData(): string
467
469
$ html .= $ startTag ;
468
470
469
471
// Write row if there are HTML table cells in it
470
- $ mpdfInvisible = $ this ->isMPdf && !$ sheet ->isRowVisible ($ row );
471
- if (!$ mpdfInvisible && !isset ($ this ->isSpannedRow [$ sheet ->getParent ()->getIndex ($ sheet )][$ row ])) {
472
+ if ($ this ->shouldGenerateRow ($ sheet , $ row ) && !isset ($ this ->isSpannedRow [$ sheet ->getParent ()->getIndex ($ sheet )][$ row ])) {
472
473
// Start a new rowData
473
474
$ rowData = [];
474
475
// Loop through columns
475
476
$ column = $ minCol ;
477
+ $ colStr = $ minColString ;
476
478
while ($ column <= $ maxCol ) {
477
479
// Cell exists?
478
480
$ cellAddress = Coordinate::stringFromColumnIndex ($ column ) . $ row ;
479
- $ rowData [$ column ++] = ($ sheet ->getCellCollection ()->has ($ cellAddress )) ? $ cellAddress : '' ;
481
+ if ($ this ->shouldGenerateColumn ($ sheet , $ colStr )) {
482
+ $ rowData [$ column ] = ($ sheet ->getCellCollection ()->has ($ cellAddress )) ? $ cellAddress : '' ;
483
+ }
484
+ ++$ column ;
485
+ ++$ colStr ;
480
486
}
481
487
$ html .= $ this ->generateRow ($ sheet , $ rowData , $ row - 1 , $ cellType );
482
488
}
@@ -610,7 +616,7 @@ private function writeImageInCell(string $coordinates): string
610
616
$ filename = htmlspecialchars ($ filename , Settings::htmlEntityFlags ());
611
617
612
618
$ html .= PHP_EOL ;
613
- $ imageData = self ::winFileToUrl ($ filename , $ this -> isMPdf );
619
+ $ imageData = self ::winFileToUrl ($ filename , $ this instanceof Pdf \Mpdf );
614
620
615
621
if ($ this ->embedImages || str_starts_with ($ imageData , 'zip:// ' )) {
616
622
$ picture = @file_get_contents ($ filename );
@@ -822,9 +828,13 @@ private function buildCssPerSheet(Worksheet $sheet, array &$css): void
822
828
// col elements, initialize
823
829
$ highestColumnIndex = Coordinate::columnIndexFromString ($ sheet ->getHighestColumn ()) - 1 ;
824
830
$ column = -1 ;
831
+ $ colStr = 'A ' ;
825
832
while ($ column ++ < $ highestColumnIndex ) {
826
833
$ this ->columnWidths [$ sheetIndex ][$ column ] = self ::DEFAULT_CELL_WIDTH_POINTS ; // approximation
827
- $ css ['table.sheet ' . $ sheetIndex . ' col.col ' . $ column ]['width ' ] = self ::DEFAULT_CELL_WIDTH_POINTS . 'pt ' ;
834
+ if ($ this ->shouldGenerateColumn ($ sheet , $ colStr )) {
835
+ $ css ['table.sheet ' . $ sheetIndex . ' col.col ' . $ column ]['width ' ] = self ::DEFAULT_CELL_WIDTH_POINTS . 'pt ' ;
836
+ }
837
+ ++$ colStr ;
828
838
}
829
839
830
840
// col elements, loop through columnDimensions and set width
@@ -834,6 +844,9 @@ private function buildCssPerSheet(Worksheet $sheet, array &$css): void
834
844
$ width = SharedDrawing::pixelsToPoints ($ width );
835
845
if ($ columnDimension ->getVisible () === false ) {
836
846
$ css ['table.sheet ' . $ sheetIndex . ' .column ' . $ column ]['display ' ] = 'none ' ;
847
+ // This would be better but Firefox has an 11-year-old bug.
848
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=819045
849
+ //$css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse';
837
850
}
838
851
if ($ width >= 0 ) {
839
852
$ this ->columnWidths [$ sheetIndex ][$ column ] = $ width ;
@@ -991,7 +1004,7 @@ private function createCSSStyleAlignment(Alignment $alignment): array
991
1004
}
992
1005
$ rotation = $ alignment ->getTextRotation ();
993
1006
if ($ rotation !== 0 && $ rotation !== Alignment::TEXTROTATION_STACK_PHPSPREADSHEET ) {
994
- if ($ this -> isMPdf ) {
1007
+ if ($ this instanceof Pdf \Mpdf ) {
995
1008
$ css ['text-rotate ' ] = "$ rotation " ;
996
1009
} else {
997
1010
$ css ['transform ' ] = "rotate( {$ rotation }deg) " ;
@@ -1782,4 +1795,25 @@ private function generatePageDeclarations(bool $generateSurroundingHTML): string
1782
1795
1783
1796
return $ htmlPage ;
1784
1797
}
1798
+
1799
+ private function shouldGenerateRow (Worksheet $ sheet , int $ row ): bool
1800
+ {
1801
+ if (!($ this instanceof Pdf \Mpdf || $ this instanceof Pdf \Tcpdf)) {
1802
+ return true ;
1803
+ }
1804
+
1805
+ return $ sheet ->isRowVisible ($ row );
1806
+ }
1807
+
1808
+ private function shouldGenerateColumn (Worksheet $ sheet , string $ colStr ): bool
1809
+ {
1810
+ if (!($ this instanceof Pdf \Mpdf || $ this instanceof Pdf \Tcpdf)) {
1811
+ return true ;
1812
+ }
1813
+ if (!$ sheet ->columnDimensionExists ($ colStr )) {
1814
+ return true ;
1815
+ }
1816
+
1817
+ return $ sheet ->getColumnDimension ($ colStr )->getVisible ();
1818
+ }
1785
1819
}
0 commit comments