@@ -1074,13 +1074,13 @@ public function buildCSS(bool $generateSurroundingHTML = true): array
1074
1074
*
1075
1075
* @return string[]
1076
1076
*/
1077
- private function createCSSStyle (Style $ style ): array
1077
+ private function createCSSStyle (Style $ style, bool $ conditional = false ): array
1078
1078
{
1079
1079
// Create CSS
1080
1080
return array_merge (
1081
- $ this ->createCSSStyleAlignment ($ style ->getAlignment ()),
1081
+ $ conditional ? [] : $ this ->createCSSStyleAlignment ($ style ->getAlignment ()),
1082
1082
$ this ->createCSSStyleBorders ($ style ->getBorders ()),
1083
- $ this ->createCSSStyleFont ($ style ->getFont ()),
1083
+ $ this ->createCSSStyleFont ($ style ->getFont (), conditional: $ conditional ),
1084
1084
$ this ->createCSSStyleFill ($ style ->getFill ())
1085
1085
);
1086
1086
}
@@ -1124,7 +1124,7 @@ private function createCSSStyleAlignment(Alignment $alignment): array
1124
1124
*
1125
1125
* @return string[]
1126
1126
*/
1127
- private function createCSSStyleFont (Font $ font , bool $ useDefaults = false ): array
1127
+ private function createCSSStyleFont (Font $ font , bool $ useDefaults = false , bool $ conditional = false ): array
1128
1128
{
1129
1129
// Construct CSS
1130
1130
$ css = [];
@@ -1151,12 +1151,29 @@ private function createCSSStyleFont(Font $font, bool $useDefaults = false): arra
1151
1151
}
1152
1152
1153
1153
$ css ['color ' ] = '# ' . $ font ->getColor ()->getRGB ();
1154
- $ css ['font-family ' ] = '\'' . htmlspecialchars ((string ) $ font ->getName (), ENT_QUOTES ) . '\'' ;
1155
- $ css ['font-size ' ] = $ font ->getSize () . 'pt ' ;
1154
+ if (!$ conditional ) {
1155
+ $ css ['font-family ' ] = '\'' . htmlspecialchars ((string ) $ font ->getName (), ENT_QUOTES ) . '\'' ;
1156
+ $ css ['font-size ' ] = $ font ->getSize () . 'pt ' ;
1157
+ }
1156
1158
1157
1159
return $ css ;
1158
1160
}
1159
1161
1162
+ /**
1163
+ * @param string[] $css
1164
+ */
1165
+ private function styleBorder (array &$ css , string $ index , Border $ border ): void
1166
+ {
1167
+ $ borderStyle = $ border ->getBorderStyle ();
1168
+ // Mpdf doesn't process !important, so omit unimportant border none
1169
+ if ($ borderStyle === Border::BORDER_NONE && $ this instanceof Pdf \Mpdf) {
1170
+ return ;
1171
+ }
1172
+ if ($ borderStyle !== Border::BORDER_OMIT ) {
1173
+ $ css [$ index ] = $ this ->createCSSStyleBorder ($ border );
1174
+ }
1175
+ }
1176
+
1160
1177
/**
1161
1178
* Create CSS style.
1162
1179
*
@@ -1170,26 +1187,10 @@ private function createCSSStyleBorders(Borders $borders): array
1170
1187
$ css = [];
1171
1188
1172
1189
// Create CSS
1173
- if (!($ this instanceof Pdf \Mpdf)) {
1174
- $ css ['border-bottom ' ] = $ this ->createCSSStyleBorder ($ borders ->getBottom ());
1175
- $ css ['border-top ' ] = $ this ->createCSSStyleBorder ($ borders ->getTop ());
1176
- $ css ['border-left ' ] = $ this ->createCSSStyleBorder ($ borders ->getLeft ());
1177
- $ css ['border-right ' ] = $ this ->createCSSStyleBorder ($ borders ->getRight ());
1178
- } else {
1179
- // Mpdf doesn't process !important, so omit unimportant border none
1180
- if ($ borders ->getBottom ()->getBorderStyle () !== Border::BORDER_NONE ) {
1181
- $ css ['border-bottom ' ] = $ this ->createCSSStyleBorder ($ borders ->getBottom ());
1182
- }
1183
- if ($ borders ->getTop ()->getBorderStyle () !== Border::BORDER_NONE ) {
1184
- $ css ['border-top ' ] = $ this ->createCSSStyleBorder ($ borders ->getTop ());
1185
- }
1186
- if ($ borders ->getLeft ()->getBorderStyle () !== Border::BORDER_NONE ) {
1187
- $ css ['border-left ' ] = $ this ->createCSSStyleBorder ($ borders ->getLeft ());
1188
- }
1189
- if ($ borders ->getRight ()->getBorderStyle () !== Border::BORDER_NONE ) {
1190
- $ css ['border-right ' ] = $ this ->createCSSStyleBorder ($ borders ->getRight ());
1191
- }
1192
- }
1190
+ $ this ->styleBorder ($ css , 'border-bottom ' , $ borders ->getBottom ());
1191
+ $ this ->styleBorder ($ css , 'border-top ' , $ borders ->getTop ());
1192
+ $ this ->styleBorder ($ css , 'border-left ' , $ borders ->getLeft ());
1193
+ $ this ->styleBorder ($ css , 'border-right ' , $ borders ->getRight ());
1193
1194
1194
1195
return $ css ;
1195
1196
}
@@ -1393,7 +1394,11 @@ private function generateRowStart(Worksheet $worksheet, int $sheetIndex, int $ro
1393
1394
$ style = isset ($ this ->cssStyles ['table.sheet ' . $ sheetIndex . ' tr.row ' . $ row ])
1394
1395
? $ this ->assembleCSS ($ this ->cssStyles ['table.sheet ' . $ sheetIndex . ' tr.row ' . $ row ]) : '' ;
1395
1396
1396
- $ html .= ' <tr style=" ' . $ style . '"> ' . PHP_EOL ;
1397
+ if ($ style === '' ) {
1398
+ $ html .= ' <tr> ' . PHP_EOL ;
1399
+ } else {
1400
+ $ html .= ' <tr style=" ' . $ style . '"> ' . PHP_EOL ;
1401
+ }
1397
1402
}
1398
1403
1399
1404
return $ html ;
@@ -1605,6 +1610,7 @@ private function generateRowWriteCell(
1605
1610
$ html .= ' data-type=" ' . DataType::TYPE_STRING . '" ' ;
1606
1611
}
1607
1612
}
1613
+ $ holdCss = '' ;
1608
1614
if (!$ this ->useInlineCss && !$ this ->isPdf && is_string ($ cssClass )) {
1609
1615
$ html .= ' class=" ' . $ cssClass . '" ' ;
1610
1616
if ($ htmlx ) {
@@ -1650,9 +1656,17 @@ private function generateRowWriteCell(
1650
1656
$ xcssClass ['position ' ] = 'relative ' ;
1651
1657
}
1652
1658
/** @var string[] $xcssClass */
1653
- $ html .= ' style=" ' . $ this ->assembleCSS ($ xcssClass ) . ' " ' ;
1659
+ $ holdCss = $ this ->assembleCSS ($ xcssClass );
1654
1660
if ($ this ->useInlineCss ) {
1655
- $ html .= ' class="gridlines gridlinesp" ' ;
1661
+ $ prntgrid = $ worksheet ->getPrintGridlines ();
1662
+ $ viewgrid = $ this ->isPdf ? $ prntgrid : $ worksheet ->getShowGridlines ();
1663
+ if ($ viewgrid && $ prntgrid ) {
1664
+ $ html .= ' class="gridlines gridlinesp" ' ;
1665
+ } elseif ($ viewgrid ) {
1666
+ $ html .= ' class="gridlines" ' ;
1667
+ } elseif ($ prntgrid ) {
1668
+ $ html .= ' class="gridlinesp" ' ;
1669
+ }
1656
1670
}
1657
1671
}
1658
1672
@@ -1700,14 +1714,23 @@ private function generateRowWriteCell(
1700
1714
}
1701
1715
}
1702
1716
if ($ matched ) {
1703
- $ styles = $ this ->createCSSStyle ($ styleMerger ->getStyle ());
1717
+ $ styles = $ this ->createCSSStyle ($ styleMerger ->getStyle (), true );
1704
1718
$ html .= ' style=" ' ;
1719
+ if ($ holdCss !== '' ) {
1720
+ $ html .= "$ holdCss; " ;
1721
+ $ holdCss = '' ;
1722
+ }
1705
1723
foreach ($ styles as $ key => $ value ) {
1706
- $ html .= $ key . ': ' . $ value . '; ' ;
1724
+ if (!str_starts_with ($ key , 'border- ' ) || $ value !== 'none #000000 ' ) {
1725
+ $ html .= $ key . ': ' . $ value . '; ' ;
1726
+ }
1707
1727
}
1708
1728
$ html .= '" ' ;
1709
1729
}
1710
1730
}
1731
+ if ($ holdCss !== '' ) {
1732
+ $ html .= ' style=" ' . $ holdCss . '" ' ;
1733
+ }
1711
1734
1712
1735
$ html .= '> ' ;
1713
1736
$ html .= $ htmlx ;
0 commit comments