@@ -1046,13 +1046,13 @@ public function buildCSS(bool $generateSurroundingHTML = true): array
1046
1046
*
1047
1047
* @return string[]
1048
1048
*/
1049
- private function createCSSStyle (Style $ style ): array
1049
+ private function createCSSStyle (Style $ style, bool $ conditional = false ): array
1050
1050
{
1051
1051
// Create CSS
1052
1052
return array_merge (
1053
- $ this ->createCSSStyleAlignment ($ style ->getAlignment ()),
1053
+ $ conditional ? [] : $ this ->createCSSStyleAlignment ($ style ->getAlignment ()),
1054
1054
$ this ->createCSSStyleBorders ($ style ->getBorders ()),
1055
- $ this ->createCSSStyleFont ($ style ->getFont ()),
1055
+ $ this ->createCSSStyleFont ($ style ->getFont (), conditional: $ conditional ),
1056
1056
$ this ->createCSSStyleFill ($ style ->getFill ())
1057
1057
);
1058
1058
}
@@ -1096,7 +1096,7 @@ private function createCSSStyleAlignment(Alignment $alignment): array
1096
1096
*
1097
1097
* @return string[]
1098
1098
*/
1099
- private function createCSSStyleFont (Font $ font , bool $ useDefaults = false ): array
1099
+ private function createCSSStyleFont (Font $ font , bool $ useDefaults = false , bool $ conditional = false ): array
1100
1100
{
1101
1101
// Construct CSS
1102
1102
$ css = [];
@@ -1123,12 +1123,29 @@ private function createCSSStyleFont(Font $font, bool $useDefaults = false): arra
1123
1123
}
1124
1124
1125
1125
$ css ['color ' ] = '# ' . $ font ->getColor ()->getRGB ();
1126
- $ css ['font-family ' ] = '\'' . htmlspecialchars ((string ) $ font ->getName (), ENT_QUOTES ) . '\'' ;
1127
- $ css ['font-size ' ] = $ font ->getSize () . 'pt ' ;
1126
+ if (!$ conditional ) {
1127
+ $ css ['font-family ' ] = '\'' . htmlspecialchars ((string ) $ font ->getName (), ENT_QUOTES ) . '\'' ;
1128
+ $ css ['font-size ' ] = $ font ->getSize () . 'pt ' ;
1129
+ }
1128
1130
1129
1131
return $ css ;
1130
1132
}
1131
1133
1134
+ /**
1135
+ * @param string[] $css
1136
+ */
1137
+ private function styleBorder (array &$ css , string $ index , Border $ border ): void
1138
+ {
1139
+ $ borderStyle = $ border ->getBorderStyle ();
1140
+ // Mpdf doesn't process !important, so omit unimportant border none
1141
+ if ($ borderStyle === Border::BORDER_NONE && $ this instanceof Pdf \Mpdf) {
1142
+ return ;
1143
+ }
1144
+ if ($ borderStyle !== Border::BORDER_OMIT ) {
1145
+ $ css [$ index ] = $ this ->createCSSStyleBorder ($ border );
1146
+ }
1147
+ }
1148
+
1132
1149
/**
1133
1150
* Create CSS style.
1134
1151
*
@@ -1142,26 +1159,10 @@ private function createCSSStyleBorders(Borders $borders): array
1142
1159
$ css = [];
1143
1160
1144
1161
// Create CSS
1145
- if (!($ this instanceof Pdf \Mpdf)) {
1146
- $ css ['border-bottom ' ] = $ this ->createCSSStyleBorder ($ borders ->getBottom ());
1147
- $ css ['border-top ' ] = $ this ->createCSSStyleBorder ($ borders ->getTop ());
1148
- $ css ['border-left ' ] = $ this ->createCSSStyleBorder ($ borders ->getLeft ());
1149
- $ css ['border-right ' ] = $ this ->createCSSStyleBorder ($ borders ->getRight ());
1150
- } else {
1151
- // Mpdf doesn't process !important, so omit unimportant border none
1152
- if ($ borders ->getBottom ()->getBorderStyle () !== Border::BORDER_NONE ) {
1153
- $ css ['border-bottom ' ] = $ this ->createCSSStyleBorder ($ borders ->getBottom ());
1154
- }
1155
- if ($ borders ->getTop ()->getBorderStyle () !== Border::BORDER_NONE ) {
1156
- $ css ['border-top ' ] = $ this ->createCSSStyleBorder ($ borders ->getTop ());
1157
- }
1158
- if ($ borders ->getLeft ()->getBorderStyle () !== Border::BORDER_NONE ) {
1159
- $ css ['border-left ' ] = $ this ->createCSSStyleBorder ($ borders ->getLeft ());
1160
- }
1161
- if ($ borders ->getRight ()->getBorderStyle () !== Border::BORDER_NONE ) {
1162
- $ css ['border-right ' ] = $ this ->createCSSStyleBorder ($ borders ->getRight ());
1163
- }
1164
- }
1162
+ $ this ->styleBorder ($ css , 'border-bottom ' , $ borders ->getBottom ());
1163
+ $ this ->styleBorder ($ css , 'border-top ' , $ borders ->getTop ());
1164
+ $ this ->styleBorder ($ css , 'border-left ' , $ borders ->getLeft ());
1165
+ $ this ->styleBorder ($ css , 'border-right ' , $ borders ->getRight ());
1165
1166
1166
1167
return $ css ;
1167
1168
}
@@ -1594,7 +1595,15 @@ private function generateRowWriteCell(
1594
1595
/** @var string[] $xcssClass */
1595
1596
$ holdCss = $ this ->assembleCSS ($ xcssClass );
1596
1597
if ($ this ->useInlineCss ) {
1597
- $ html .= ' class="gridlines gridlinesp" ' ;
1598
+ $ prntgrid = $ worksheet ->getPrintGridlines ();
1599
+ $ viewgrid = $ this ->isPdf ? $ prntgrid : $ worksheet ->getShowGridlines ();
1600
+ if ($ viewgrid && $ prntgrid ) {
1601
+ $ html .= ' class="gridlines gridlinesp" ' ;
1602
+ } elseif ($ viewgrid ) {
1603
+ $ html .= ' class="gridlines" ' ;
1604
+ } elseif ($ prntgrid ) {
1605
+ $ html .= ' class="gridlinesp" ' ;
1606
+ }
1598
1607
}
1599
1608
}
1600
1609
@@ -1642,9 +1651,12 @@ private function generateRowWriteCell(
1642
1651
}
1643
1652
}
1644
1653
if ($ matched ) {
1645
- $ styles = $ this ->createCSSStyle ($ styleMerger ->getStyle ());
1646
- $ html .= ' style=" ' . $ holdCss . ' ' ;
1647
- $ holdCss = '' ;
1654
+ $ styles = $ this ->createCSSStyle ($ styleMerger ->getStyle (), true );
1655
+ $ html .= ' style=" ' ;
1656
+ if ($ holdCss !== '' ) {
1657
+ $ html .= "$ holdCss; " ;
1658
+ $ holdCss = '' ;
1659
+ }
1648
1660
foreach ($ styles as $ key => $ value ) {
1649
1661
$ html .= $ key . ': ' . $ value . '; ' ;
1650
1662
}
0 commit comments