@@ -315,6 +315,7 @@ private function processDomElementTitle(Worksheet $sheet, int &$row, string &$co
315315
316316 try {
317317 $ sheet ->setTitle ($ cellContent , true , true );
318+ $ sheet ->getParent ()?->getProperties()?->setTitle($ cellContent );
318319 } catch (SpreadsheetException ) {
319320 // leave default title if too long or illegal chars
320321 }
@@ -476,6 +477,11 @@ private function processDomElementImg(Worksheet $sheet, int &$row, string &$colu
476477 private function processDomElementTable (Worksheet $ sheet , int &$ row , string &$ column , string &$ cellContent , DOMElement $ child , array &$ attributeArray ): void
477478 {
478479 if ($ child ->nodeName === 'table ' ) {
480+ if (isset ($ attributeArray ['class ' ])) {
481+ $ classes = explode (' ' , $ attributeArray ['class ' ]);
482+ $ sheet ->setShowGridlines (in_array ('gridlines ' , $ classes , true ));
483+ $ sheet ->setPrintGridlines (in_array ('gridlinesp ' , $ classes , true ));
484+ }
479485 $ this ->currentColumn = 'A ' ;
480486 $ this ->flushCell ($ sheet , $ column , $ row , $ cellContent , $ attributeArray );
481487 $ column = $ this ->setTableStartColumn ($ column );
@@ -1038,14 +1044,21 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
10381044 if (!isset ($ attributes ['src ' ])) {
10391045 return ;
10401046 }
1047+ $ styleArray = self ::getStyleArray ($ attributes );
10411048
1042- $ src = urldecode ($ attributes ['src ' ]);
1043- $ width = isset ($ attributes ['width ' ]) ? (float ) $ attributes ['width ' ] : null ;
1044- $ height = isset ($ attributes ['height ' ]) ? (float ) $ attributes ['height ' ] : null ;
1049+ $ src = $ attributes ['src ' ];
1050+ if (substr ($ src , 0 , 5 ) !== 'data: ' ) {
1051+ $ src = urldecode ($ src );
1052+ }
1053+ $ width = isset ($ attributes ['width ' ]) ? (float ) $ attributes ['width ' ] : ($ styleArray ['width ' ] ?? null );
1054+ $ height = isset ($ attributes ['height ' ]) ? (float ) $ attributes ['height ' ] : ($ styleArray ['height ' ] ?? null );
10451055 $ name = $ attributes ['alt ' ] ?? null ;
10461056
10471057 $ drawing = new Drawing ();
1048- $ drawing ->setPath ($ src );
1058+ $ drawing ->setPath ($ src , false );
1059+ if ($ drawing ->getPath () === '' ) {
1060+ return ;
1061+ }
10491062 $ drawing ->setWorksheet ($ sheet );
10501063 $ drawing ->setCoordinates ($ column . $ row );
10511064 $ drawing ->setOffsetX (0 );
@@ -1057,10 +1070,12 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
10571070 }
10581071
10591072 if ($ width ) {
1060- $ drawing ->setWidth ((int ) $ width );
1061- }
1062-
1063- if ($ height ) {
1073+ if ($ height ) {
1074+ $ drawing ->setWidthAndHeight ((int ) $ width , (int ) $ height );
1075+ } else {
1076+ $ drawing ->setWidth ((int ) $ width );
1077+ }
1078+ } elseif ($ height ) {
10641079 $ drawing ->setHeight ((int ) $ height );
10651080 }
10661081
@@ -1071,6 +1086,44 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
10711086 $ sheet ->getRowDimension ($ row )->setRowHeight (
10721087 $ drawing ->getHeight () * 0.9
10731088 );
1089+
1090+ if (isset ($ styleArray ['opacity ' ])) {
1091+ $ opacity = $ styleArray ['opacity ' ];
1092+ if (is_numeric ($ opacity )) {
1093+ $ drawing ->setOpacity ((int ) ($ opacity * 100000 ));
1094+ }
1095+ }
1096+ }
1097+
1098+ private static function getStyleArray (array $ attributes ): array
1099+ {
1100+ $ styleArray = [];
1101+ if (isset ($ attributes ['style ' ])) {
1102+ $ styles = explode ('; ' , $ attributes ['style ' ]);
1103+ foreach ($ styles as $ style ) {
1104+ $ value = explode (': ' , $ style );
1105+ if (count ($ value ) === 2 ) {
1106+ $ arrayKey = trim ($ value [0 ]);
1107+ $ arrayValue = trim ($ value [1 ]);
1108+ if ($ arrayKey === 'width ' ) {
1109+ if (substr ($ arrayValue , -2 ) === 'px ' ) {
1110+ $ arrayValue = (string ) (((float ) substr ($ arrayValue , 0 , -2 )));
1111+ } else {
1112+ $ arrayValue = (new CssDimension ($ arrayValue ))->width ();
1113+ }
1114+ } elseif ($ arrayKey === 'height ' ) {
1115+ if (substr ($ arrayValue , -2 ) === 'px ' ) {
1116+ $ arrayValue = substr ($ arrayValue , 0 , -2 );
1117+ } else {
1118+ $ arrayValue = (new CssDimension ($ arrayValue ))->height ();
1119+ }
1120+ }
1121+ $ styleArray [$ arrayKey ] = $ arrayValue ;
1122+ }
1123+ }
1124+ }
1125+
1126+ return $ styleArray ;
10741127 }
10751128
10761129 private const BORDER_MAPPINGS = [
0 commit comments