@@ -1044,31 +1044,7 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
1044
1044
if (!isset ($ attributes ['src ' ])) {
1045
1045
return ;
1046
1046
}
1047
- $ styleArray = [];
1048
- if (isset ($ attributes ['style ' ])) {
1049
- $ styles = explode ('; ' , $ attributes ['style ' ]);
1050
- foreach ($ styles as $ style ) {
1051
- $ value = explode (': ' , $ style );
1052
- if (count ($ value ) === 2 ) {
1053
- $ arrayKey = trim ($ value [0 ]);
1054
- $ arrayValue = trim ($ value [1 ]);
1055
- if ($ arrayKey === 'width ' ) {
1056
- if (substr ($ arrayValue , -2 ) === 'px ' ) {
1057
- $ arrayValue = (string ) (((float ) substr ($ arrayValue , 0 , -2 )));
1058
- } else {
1059
- $ arrayValue = (new CssDimension ($ arrayValue ))->width ();
1060
- }
1061
- } elseif ($ arrayKey === 'height ' ) {
1062
- if (substr ($ arrayValue , -2 ) === 'px ' ) {
1063
- $ arrayValue = substr ($ arrayValue , 0 , -2 );
1064
- } else {
1065
- $ arrayValue = (new CssDimension ($ arrayValue ))->height ();
1066
- }
1067
- }
1068
- $ styleArray [$ arrayKey ] = $ arrayValue ;
1069
- }
1070
- }
1071
- }
1047
+ $ styleArray = self ::getStyleArray ($ attributes );
1072
1048
1073
1049
$ src = $ attributes ['src ' ];
1074
1050
if (substr ($ src , 0 , 5 ) !== 'data: ' ) {
@@ -1116,6 +1092,37 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
1116
1092
}
1117
1093
}
1118
1094
1095
+ private static function getStyleArray (array $ attributes ): array
1096
+ {
1097
+ $ styleArray = [];
1098
+ if (isset ($ attributes ['style ' ])) {
1099
+ $ styles = explode ('; ' , $ attributes ['style ' ]);
1100
+ foreach ($ styles as $ style ) {
1101
+ $ value = explode (': ' , $ style );
1102
+ if (count ($ value ) === 2 ) {
1103
+ $ arrayKey = trim ($ value [0 ]);
1104
+ $ arrayValue = trim ($ value [1 ]);
1105
+ if ($ arrayKey === 'width ' ) {
1106
+ if (substr ($ arrayValue , -2 ) === 'px ' ) {
1107
+ $ arrayValue = (string ) (((float ) substr ($ arrayValue , 0 , -2 )));
1108
+ } else {
1109
+ $ arrayValue = (new CssDimension ($ arrayValue ))->width ();
1110
+ }
1111
+ } elseif ($ arrayKey === 'height ' ) {
1112
+ if (substr ($ arrayValue , -2 ) === 'px ' ) {
1113
+ $ arrayValue = substr ($ arrayValue , 0 , -2 );
1114
+ } else {
1115
+ $ arrayValue = (new CssDimension ($ arrayValue ))->height ();
1116
+ }
1117
+ }
1118
+ $ styleArray [$ arrayKey ] = $ arrayValue ;
1119
+ }
1120
+ }
1121
+ }
1122
+
1123
+ return $ styleArray ;
1124
+ }
1125
+
1119
1126
private const BORDER_MAPPINGS = [
1120
1127
'dash-dot ' => Border::BORDER_DASHDOT ,
1121
1128
'dash-dot-dot ' => Border::BORDER_DASHDOTDOT ,
0 commit comments