Passed
Push — master ( 39dc7c...4474a4 )
by ma
02:07
created
src/Excel/SpreadSheet.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
13 13
 use tinymeng\tools\FileTool;
14 14
 
15
-trait SpreadSheet{
15
+trait SpreadSheet {
16 16
 
17 17
     /**
18 18
      * sheet名称
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * 文件信息
30 30
      * @var array
31 31
      */
32
-    private $fileTitle=[];
32
+    private $fileTitle = [];
33 33
 
34 34
     /**
35 35
      * 标题占用行数
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public $image_path = '/images';
92 92
 
93
-    public function setTitle($title){
93
+    public function setTitle($title) {
94 94
         $this->title = $title;
95 95
         $this->getTitleFields();
96 96
         return $this;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      * @param $value
101 101
      * @return $this
102 102
      */
103
-    public function setRelativePath($value){
103
+    public function setRelativePath($value) {
104 104
         $this->relative_path = $value;
105 105
         return $this;
106 106
     }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      * @param $value
110 110
      * @return $this
111 111
      */
112
-    public function setImagePath($value){
112
+    public function setImagePath($value) {
113 113
         $this->image_path = $value;
114 114
         return $this;
115 115
     }
@@ -121,40 +121,40 @@  discard block
 block discarded – undo
121 121
      * @author: Tinymeng <[email protected]>
122 122
      * @time: 2022/2/22 11:30
123 123
      */
124
-    public function getExcelData(){
124
+    public function getExcelData() {
125 125
         /* 循环读取每个单元格的数据 */
126 126
         $result = [];
127
-        $dataRow = $this->titleFieldsRow+1;
127
+        $dataRow = $this->titleFieldsRow + 1;
128 128
 
129 129
         //行数循环
130
-        for ($row = $dataRow; $row <= $this->rowCount; $row++){
131
-            $rowFlog = false;//行是否有内容(过滤空行)
130
+        for ($row = $dataRow; $row <= $this->rowCount; $row++) {
131
+            $rowFlog = false; //行是否有内容(过滤空行)
132 132
             //列数循环 , 列数是以A列开始
133 133
             $data = [];
134
-            foreach ($this->cellName as $column){
134
+            foreach ($this->cellName as $column) {
135 135
                 $cell = $this->workSheet->getCell($column.$row);
136 136
                 $value = trim($cell->getFormattedValue());
137
-                if(isset($this->title_fields[$column])){
137
+                if (isset($this->title_fields[$column])) {
138 138
                     $data[$this->title_fields[$column]] = $value;
139
-                    if(!empty($value)) $rowFlog = true;//有内容
139
+                    if (!empty($value)) $rowFlog = true; //有内容
140 140
                 }
141 141
             }
142
-            if($rowFlog) $result[] = $data;
142
+            if ($rowFlog) $result[] = $data;
143 143
         }
144 144
 
145 145
         /*
146 146
          * 读取表格图片数据
147 147
          * (如果为空右击图片转为浮动图片)
148 148
          */
149
-        $image_filename_prefix = time().rand(100,999).$this->sheet;
149
+        $image_filename_prefix = time().rand(100, 999).$this->sheet;
150 150
         foreach ($this->workSheet->getDrawingCollection() as $drawing) {
151 151
             /**@var $drawing Drawing* */
152 152
             list($column, $row) = Coordinate::coordinateFromString($drawing->getCoordinates());
153
-            $image_filename = "/{$image_filename_prefix}-" . $drawing->getCoordinates();
153
+            $image_filename = "/{$image_filename_prefix}-".$drawing->getCoordinates();
154 154
             $image_suffix = $this->saveImage($drawing, $image_filename);
155
-            $image_name = ltrim($this->relative_path, '/') . "{$image_filename}.{$image_suffix}";
156
-            if(isset($this->title_fields[$column])) {
157
-                $result[$row-($this->titleFieldsRow+1)][$this->title_fields[$column]] = $image_name;
155
+            $image_name = ltrim($this->relative_path, '/')."{$image_filename}.{$image_suffix}";
156
+            if (isset($this->title_fields[$column])) {
157
+                $result[$row - ($this->titleFieldsRow + 1)][$this->title_fields[$column]] = $image_name;
158 158
             }
159 159
         }
160 160
         return $result;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      * @author: Tinymeng <[email protected]>
167 167
      * @time: 2022/2/22 11:30
168 168
      */
169
-    public function getTitle(){
169
+    public function getTitle() {
170 170
         return $this->title;
171 171
     }
172 172
 
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
      * @author: Tinymeng <[email protected]>
177 177
      * @time: 2022/2/22 11:30
178 178
      */
179
-    public function getTitleFields(){
179
+    public function getTitleFields() {
180 180
         $title = $this->getTitle();
181 181
 
182 182
         $row = $this->titleFieldsRow;
183 183
         $titleDataArr = [];
184 184
 
185
-        foreach ($this->cellName as $column){
185
+        foreach ($this->cellName as $column) {
186 186
             $value = trim($this->workSheet->getCell($column.$row)->getValue());
187
-            if(!empty($value)){
187
+            if (!empty($value)) {
188 188
                 $titleDataArr[$value] = $column;
189 189
             }
190 190
         }
191 191
         $title_fields = [];
192 192
         foreach ($title as $key=>$value) {
193
-            if(isset($titleDataArr[$key])){
193
+            if (isset($titleDataArr[$key])) {
194 194
                 $title_fields[$titleDataArr[$key]] = $value;
195 195
             }
196 196
         }
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
                 $real_extension = 'jpg';
221 221
                 $image_filename .= '.'.$real_extension;
222 222
                 $source = imagecreatefromjpeg($drawing->getPath());
223
-                imagejpeg($source, $this->image_path . $image_filename);
223
+                imagejpeg($source, $this->image_path.$image_filename);
224 224
                 break;
225 225
             case 'image/gif':
226 226
                 $real_extension = 'gif';
227 227
                 $image_filename .= '.'.$real_extension;
228 228
                 $source = imagecreatefromgif($drawing->getPath());
229
-                imagegif($source, $this->image_path . $image_filename);
229
+                imagegif($source, $this->image_path.$image_filename);
230 230
                 break;
231 231
             case 'image/png':
232 232
                 $real_extension = 'png';
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
                 // 保持透明度设置
236 236
                 imagealphablending($source, false);
237 237
                 imagesavealpha($source, true);
238
-                imagepng($source, $this->image_path . $image_filename);
238
+                imagepng($source, $this->image_path.$image_filename);
239 239
                 break;
240 240
             default:
241 241
                 throw new Exception('image format error!');
Please login to merge, or discard this patch.