@@ -315,6 +315,7 @@ private function processDomElementTitle(Worksheet $sheet, int &$row, string &$co
315
315
316
316
try {
317
317
$ sheet ->setTitle ($ cellContent , true , true );
318
+ $ sheet ->getParent ()?->getProperties()?->setTitle($ cellContent );
318
319
} catch (SpreadsheetException ) {
319
320
// leave default title if too long or illegal chars
320
321
}
@@ -476,6 +477,11 @@ private function processDomElementImg(Worksheet $sheet, int &$row, string &$colu
476
477
private function processDomElementTable (Worksheet $ sheet , int &$ row , string &$ column , string &$ cellContent , DOMElement $ child , array &$ attributeArray ): void
477
478
{
478
479
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
+ }
479
485
$ this ->currentColumn = 'A ' ;
480
486
$ this ->flushCell ($ sheet , $ column , $ row , $ cellContent , $ attributeArray );
481
487
$ column = $ this ->setTableStartColumn ($ column );
@@ -1038,14 +1044,21 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
1038
1044
if (!isset ($ attributes ['src ' ])) {
1039
1045
return ;
1040
1046
}
1047
+ $ styleArray = self ::getStyleArray ($ attributes );
1041
1048
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 );
1045
1055
$ name = $ attributes ['alt ' ] ?? null ;
1046
1056
1047
1057
$ drawing = new Drawing ();
1048
- $ drawing ->setPath ($ src );
1058
+ $ drawing ->setPath ($ src , false );
1059
+ if ($ drawing ->getPath () === '' ) {
1060
+ return ;
1061
+ }
1049
1062
$ drawing ->setWorksheet ($ sheet );
1050
1063
$ drawing ->setCoordinates ($ column . $ row );
1051
1064
$ drawing ->setOffsetX (0 );
@@ -1057,10 +1070,12 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
1057
1070
}
1058
1071
1059
1072
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 ) {
1064
1079
$ drawing ->setHeight ((int ) $ height );
1065
1080
}
1066
1081
@@ -1071,6 +1086,44 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
1071
1086
$ sheet ->getRowDimension ($ row )->setRowHeight (
1072
1087
$ drawing ->getHeight () * 0.9
1073
1088
);
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 ;
1074
1127
}
1075
1128
1076
1129
private const BORDER_MAPPINGS = [
0 commit comments