@@ -1074,13 +1074,13 @@ public function buildCSS(bool $generateSurroundingHTML = true): array
10741074 *
10751075 * @return string[]
10761076 */
1077- private function createCSSStyle (Style $ style ): array
1077+ private function createCSSStyle (Style $ style, bool $ conditional = false ): array
10781078 {
10791079 // Create CSS
10801080 return array_merge (
1081- $ this ->createCSSStyleAlignment ($ style ->getAlignment ()),
1081+ $ conditional ? [] : $ this ->createCSSStyleAlignment ($ style ->getAlignment ()),
10821082 $ this ->createCSSStyleBorders ($ style ->getBorders ()),
1083- $ this ->createCSSStyleFont ($ style ->getFont ()),
1083+ $ this ->createCSSStyleFont ($ style ->getFont (), conditional: $ conditional ),
10841084 $ this ->createCSSStyleFill ($ style ->getFill ())
10851085 );
10861086 }
@@ -1124,7 +1124,7 @@ private function createCSSStyleAlignment(Alignment $alignment): array
11241124 *
11251125 * @return string[]
11261126 */
1127- private function createCSSStyleFont (Font $ font , bool $ useDefaults = false ): array
1127+ private function createCSSStyleFont (Font $ font , bool $ useDefaults = false , bool $ conditional = false ): array
11281128 {
11291129 // Construct CSS
11301130 $ css = [];
@@ -1151,12 +1151,29 @@ private function createCSSStyleFont(Font $font, bool $useDefaults = false): arra
11511151 }
11521152
11531153 $ 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+ }
11561158
11571159 return $ css ;
11581160 }
11591161
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+
11601177 /**
11611178 * Create CSS style.
11621179 *
@@ -1170,26 +1187,10 @@ private function createCSSStyleBorders(Borders $borders): array
11701187 $ css = [];
11711188
11721189 // 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 ());
11931194
11941195 return $ css ;
11951196 }
@@ -1393,7 +1394,11 @@ private function generateRowStart(Worksheet $worksheet, int $sheetIndex, int $ro
13931394 $ style = isset ($ this ->cssStyles ['table.sheet ' . $ sheetIndex . ' tr.row ' . $ row ])
13941395 ? $ this ->assembleCSS ($ this ->cssStyles ['table.sheet ' . $ sheetIndex . ' tr.row ' . $ row ]) : '' ;
13951396
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+ }
13971402 }
13981403
13991404 return $ html ;
@@ -1605,6 +1610,7 @@ private function generateRowWriteCell(
16051610 $ html .= ' data-type=" ' . DataType::TYPE_STRING . '" ' ;
16061611 }
16071612 }
1613+ $ holdCss = '' ;
16081614 if (!$ this ->useInlineCss && !$ this ->isPdf && is_string ($ cssClass )) {
16091615 $ html .= ' class=" ' . $ cssClass . '" ' ;
16101616 if ($ htmlx ) {
@@ -1650,9 +1656,17 @@ private function generateRowWriteCell(
16501656 $ xcssClass ['position ' ] = 'relative ' ;
16511657 }
16521658 /** @var string[] $xcssClass */
1653- $ html .= ' style=" ' . $ this ->assembleCSS ($ xcssClass ) . ' " ' ;
1659+ $ holdCss = $ this ->assembleCSS ($ xcssClass );
16541660 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+ }
16561670 }
16571671 }
16581672
@@ -1700,14 +1714,23 @@ private function generateRowWriteCell(
17001714 }
17011715 }
17021716 if ($ matched ) {
1703- $ styles = $ this ->createCSSStyle ($ styleMerger ->getStyle ());
1717+ $ styles = $ this ->createCSSStyle ($ styleMerger ->getStyle (), true );
17041718 $ html .= ' style=" ' ;
1719+ if ($ holdCss !== '' ) {
1720+ $ html .= "$ holdCss; " ;
1721+ $ holdCss = '' ;
1722+ }
17051723 foreach ($ styles as $ key => $ value ) {
1706- $ html .= $ key . ': ' . $ value . '; ' ;
1724+ if (!str_starts_with ($ key , 'border- ' ) || $ value !== 'none #000000 ' ) {
1725+ $ html .= $ key . ': ' . $ value . '; ' ;
1726+ }
17071727 }
17081728 $ html .= '" ' ;
17091729 }
17101730 }
1731+ if ($ holdCss !== '' ) {
1732+ $ html .= ' style=" ' . $ holdCss . '" ' ;
1733+ }
17111734
17121735 $ html .= '> ' ;
17131736 $ html .= $ htmlx ;
0 commit comments