Passed
Push — master ( 49ec85...39dc7c )
by ma
02:04
created
config/TSpreadSheet.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@
 block discarded – undo
1 1
 <?php
2 2
 use \tinymeng\spreadsheet\Util\ConstCode;
3 3
 return [
4
-    'creator'=>'tinymeng',                  //文件创建者
5
-    'pathName'=>null,                       //文件存储位置
6
-    'fileName'=>null,                       //文件名称
7
-    'horizontalCenter'=>true,               //是否居中
8
-    'titleHeight'=>null,                    //定义表头行高,常用22
9
-    'titleWidth'=>null,                     //定义表头列宽(未设置则自动计算宽度),常用20
10
-    'height'=>null,                         //定义数据行高,常用22
11
-    'autoFilter'=>false,                    //自动筛选(是否开启)
12
-    'autoDataType'=>true,                   //自动适应文本类型
13
-    'freezePane'=>false,                    //冻结窗格(要冻结的首行首列"B2",false不开启)
4
+    'creator'=>'tinymeng', //文件创建者
5
+    'pathName'=>null, //文件存储位置
6
+    'fileName'=>null, //文件名称
7
+    'horizontalCenter'=>true, //是否居中
8
+    'titleHeight'=>null, //定义表头行高,常用22
9
+    'titleWidth'=>null, //定义表头列宽(未设置则自动计算宽度),常用20
10
+    'height'=>null, //定义数据行高,常用22
11
+    'autoFilter'=>false, //自动筛选(是否开启)
12
+    'autoDataType'=>true, //自动适应文本类型
13
+    'freezePane'=>false, //冻结窗格(要冻结的首行首列"B2",false不开启)
14 14
     /**
15 15
      * 字段映射方式
16 16
      * ConstCode::FIELD_MAPPING_METHOD_FIELD_CORRESPONDING_NAME = 1;//字段对应名称
17 17
      * ConstCode::FIELD_MAPPING_METHOD_NAME_CORRESPONDING_FIELD = 2;//名称对应字段
18 18
      */
19 19
     'fieldMappingMethod'=>ConstCode::FIELD_MAPPING_METHOD_NAME_CORRESPONDING_FIELD,
20
-    'mainTitleLine'=>false,                 //主标题行是否显示
21
-    'mainTitle'=>'',                        //主标题名称,默认为sheet的名称
20
+    'mainTitleLine'=>false, //主标题行是否显示
21
+    'mainTitle'=>'', //主标题名称,默认为sheet的名称
22 22
 ];
Please login to merge, or discard this patch.
src/Gateways/Export.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     /**
34 34
      * __construct
35 35
      */
36
-    public function __construct($config=[]){
36
+    public function __construct($config = []) {
37 37
         $this->setConfig($config);
38 38
 
39 39
         $this->spreadSheet = new Spreadsheet();
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @param $config
47 47
      * @return $this
48 48
      */
49
-    public function setConfig($config){
49
+    public function setConfig($config) {
50 50
         foreach ($config as $key => $value) {
51 51
             if (property_exists($this, $key)) {
52 52
                 $this->$key = $value;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     {
65 65
         /** 实例化定义默认excel **/
66 66
         $this->spreadSheet->getProperties()->setCreator($this->creator)->setLastModifiedBy($this->creator);
67
-        if($this->horizontalCenter){
67
+        if ($this->horizontalCenter) {
68 68
             $this->spreadSheet->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); //默认水平居中
69 69
             $this->spreadSheet->getDefaultStyle()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); //默认垂直居中
70 70
             $this->spreadSheet->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::VERTICAL_CENTER); //默认垂直居中
@@ -77,21 +77,21 @@  discard block
 block discarded – undo
77 77
      * @return $this
78 78
      * @throws \PhpOffice\PhpSpreadsheet\Exception
79 79
      */
80
-    public function createWorkSheet($sheetName="Worksheet")
80
+    public function createWorkSheet($sheetName = "Worksheet")
81 81
     {
82 82
         $this->sheetName = $sheetName;
83 83
         /** @var workSheet */
84 84
         $this->workSheet = $this->greateWorkSheet($sheetName);
85
-        if($this->workSheet == null){
86
-            if($this->sheetCount==1){
85
+        if ($this->workSheet == null) {
86
+            if ($this->sheetCount == 1) {
87 87
                 $this->workSheet = $this->spreadSheet->getActiveSheet();
88
-            }else{
88
+            } else {
89 89
                 $this->workSheet = $this->spreadSheet->createSheet();
90 90
             }
91
-            $this->sheetCount += 1;//总sheet数量
92
-            $this->workSheet->setTitle($sheetName);//设置sheet名称
91
+            $this->sheetCount += 1; //总sheet数量
92
+            $this->workSheet->setTitle($sheetName); //设置sheet名称
93 93
         }
94
-        if(empty($this->mainTitle)){
94
+        if (empty($this->mainTitle)) {
95 95
             $this->mainTitle = $sheetName;
96 96
         }
97 97
 
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
     public function generate()
119 119
     {
120 120
         /** 开启自动筛选 **/
121
-        if($this->autoFilter){
121
+        if ($this->autoFilter) {
122 122
             $this->spreadSheet->getActiveSheet()->setAutoFilter(
123 123
                 $this->spreadSheet->getActiveSheet()->calculateWorksheetDimension()
124 124
             );
125 125
         }
126 126
         //文件存储
127
-        if(empty($this->fileName)){
127
+        if (empty($this->fileName)) {
128 128
             $this->getFileName($this->sheetName);
129 129
         }
130 130
         return $this;
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
      * @param $file_name
136 136
      * @return string
137 137
      */
138
-    private function getFileName($sheetName){
139
-        $this->fileName = $sheetName.'_'.date('Y-m-d').'_'.rand(111,999).'.xlsx';
138
+    private function getFileName($sheetName) {
139
+        $this->fileName = $sheetName.'_'.date('Y-m-d').'_'.rand(111, 999).'.xlsx';
140 140
         return $this->fileName;
141 141
     }
142 142
 
@@ -146,18 +146,18 @@  discard block
 block discarded – undo
146 146
      * @return void
147 147
      * @throws ExceptionAlias
148 148
      */
149
-    public function download($filename=''){
150
-        if(empty($filename)){
149
+    public function download($filename = '') {
150
+        if (empty($filename)) {
151 151
             $filename = $this->fileName;
152
-        }else{
152
+        } else {
153 153
             $filename = $this->getFileName($filename);
154 154
         }
155 155
 
156 156
         /** 输出下载 **/
157
-        ob_end_clean();//清除缓冲区,避免乱码
158
-        header( 'Access-Control-Allow-Headers:responsetype,content-type,usertoken');
159
-        header( 'Access-Control-Allow-Methods:GET,HEAD,PUT,POST,DELETE,PATCH');
160
-        header( 'Access-Control-Allow-Origin:*');
157
+        ob_end_clean(); //清除缓冲区,避免乱码
158
+        header('Access-Control-Allow-Headers:responsetype,content-type,usertoken');
159
+        header('Access-Control-Allow-Methods:GET,HEAD,PUT,POST,DELETE,PATCH');
160
+        header('Access-Control-Allow-Origin:*');
161 161
         header('Content-Type: application/vnd.ms-excel');
162 162
         header('Content-Disposition: attachment;filename="'.$filename);
163 163
         header('Cache-Control: max-age=0');
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
      * @return string
175 175
      * @throws ExceptionAlias
176 176
      */
177
-    public function save($filename='',$pathName=''): string
177
+    public function save($filename = '', $pathName = ''): string
178 178
     {
179 179
         $pathName = $this->getPathName($pathName);
180
-        if(empty($filename)){
180
+        if (empty($filename)) {
181 181
             $filename = $this->fileName;
182
-        }else{
182
+        } else {
183 183
             $filename = $this->getFileName($filename);
184 184
         }
185 185
         FileTool::mkdir($pathName);
Please login to merge, or discard this patch.
src/Excel/TWorkSheet.php 1 patch
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use tinymeng\tools\exception\StatusCode;
13 13
 use tinymeng\tools\exception\TinymengException;
14 14
 
15
-trait TWorkSheet{
15
+trait TWorkSheet {
16 16
 
17 17
     /**
18 18
      * sheet名称
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * 文件信息
46 46
      * @var array
47 47
      */
48
-    private $fileTitle=[];
48
+    private $fileTitle = [];
49 49
 
50 50
 
51 51
     /**
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * @param $data
72 72
      * @return $this
73 73
      */
74
-    public function setData($data){
74
+    public function setData($data) {
75 75
         $this->data = $data;
76 76
         return $this;
77 77
     }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @param $data
81 81
      * @return $this
82 82
      */
83
-    public function getData(){
83
+    public function getData() {
84 84
         return $this->data;
85 85
     }
86 86
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $this->fileTitle = [];
97 97
         $this->data = [];
98 98
         $this->field = [];
99
-        if($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格
99
+        if ($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格
100 100
     }
101 101
 
102 102
     /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
      * @throws TinymengException
107 107
      * @throws \PhpOffice\PhpSpreadsheet\Exception
108 108
      */
109
-    public function setWorkSheetData($fileTitle,$data)
109
+    public function setWorkSheetData($fileTitle, $data)
110 110
     {
111
-        if(isset($fileTitle['title_row']) || isset($fileTitle['group_left'])){
111
+        if (isset($fileTitle['title_row']) || isset($fileTitle['group_left'])) {
112 112
             /**
113 113
              * $fileTitle = [
114 114
              *       'title_row'=>1,
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
              *       ],
119 119
              *  ];
120 120
              */
121
-            $this->title_row = $fileTitle['title_row']??1;
122
-            $this->group_left = $fileTitle['group_left']??[];
123
-            $titleData = $fileTitle['title']??[];
124
-        }else{
121
+            $this->title_row = $fileTitle['title_row'] ?? 1;
122
+            $this->group_left = $fileTitle['group_left'] ?? [];
123
+            $titleData = $fileTitle['title'] ?? [];
124
+        } else {
125 125
             /**
126 126
              *  $fileTitle = [
127 127
              *       '姓名'=>'name',
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
         }
132 132
         // 根据字段映射方式处理 title
133 133
         if ($this->fieldMappingMethod === ConstCode::FIELD_MAPPING_METHOD_FIELD_CORRESPONDING_NAME) {
134
-            $this->fileTitle = array_flip($titleData);// 字段对应名称方式 - 需要将键值对调
135
-        }else{
136
-            $this->fileTitle = $titleData;// 名称对应字段方式 - 保持原样
134
+            $this->fileTitle = array_flip($titleData); // 字段对应名称方式 - 需要将键值对调
135
+        } else {
136
+            $this->fileTitle = $titleData; // 名称对应字段方式 - 保持原样
137 137
         }
138 138
         $this->data = $data;
139 139
 
140 140
         /** 设置第一行格式 */
141
-        if($this->mainTitleLine === true){
141
+        if ($this->mainTitleLine === true) {
142 142
             $this->excelHeader();
143 143
         }
144 144
 
@@ -146,17 +146,17 @@  discard block
 block discarded – undo
146 146
         $this->excelTitle();
147 147
 
148 148
         /** 获取列表里所有字段 **/
149
-        foreach ($this->fileTitle as $key => $val){
150
-            if(is_array($val)){
151
-                foreach ($val as $k => $v){
149
+        foreach ($this->fileTitle as $key => $val) {
150
+            if (is_array($val)) {
151
+                foreach ($val as $k => $v) {
152 152
                     $this->field[] = $v;
153 153
                 }
154
-            }else{
154
+            } else {
155 155
                 $this->field[] = $val;
156 156
             }
157 157
         }
158 158
         /** 查询结果赋值 **/
159
-        if(!empty($this->data)){
159
+        if (!empty($this->data)) {
160 160
             $this->excelSetValue();
161 161
         }
162 162
         return $this;
@@ -167,33 +167,33 @@  discard block
 block discarded – undo
167 167
      * @author: Tinymeng <[email protected]>
168 168
      * @time: 2022/2/22 11:43
169 169
      */
170
-    public function excelSetValue(){
171
-        if(empty($this->group_left)){ //判断左侧是否分组
172
-            foreach ($this->data as $key => $val){
170
+    public function excelSetValue() {
171
+        if (empty($this->group_left)) { //判断左侧是否分组
172
+            foreach ($this->data as $key => $val) {
173 173
                 $this->excelSetCellValue($val);
174 174
             }
175
-        }else{   //根据设置分组字段进行分组
175
+        } else {   //根据设置分组字段进行分组
176 176
             /** 数据分组 **/
177 177
             $data = [];
178 178
             $group_left_count = count($this->group_left);
179
-            if($group_left_count == 1){
180
-                foreach ($this->data as $k => $v){
179
+            if ($group_left_count == 1) {
180
+                foreach ($this->data as $k => $v) {
181 181
                     $data[$v[$this->group_left[0]]][] = $v;
182 182
                 }
183
-                foreach ($data as $k =>$v){
183
+                foreach ($data as $k =>$v) {
184 184
                     $data[$k] = [
185 185
                         'data' => $v,
186 186
                         'count' => count($v)
187 187
                     ];
188 188
                 }
189 189
                 $this->excelGroupLeft($data, $group_left_count);
190
-            }elseif($group_left_count == 2){
190
+            }elseif ($group_left_count == 2) {
191 191
                 foreach ($this->data as $v) {
192 192
                     $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v;
193 193
                 }
194 194
                 $this->data = $this->arrayCount($data);
195 195
                 $this->excelGroupLeft($this->data, $group_left_count);
196
-            }else{
196
+            } else {
197 197
                 throw new TinymengException(StatusCode::COMMON_PARAM_INVALID,
198 198
                     '左侧分组过多,导出失败!'
199 199
                 );
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      * @return void
206 206
      * @throws \PhpOffice\PhpSpreadsheet\Exception
207 207
      */
208
-    public function excelHeader(){
208
+    public function excelHeader() {
209 209
         $row = 1;
210 210
         $this->workSheet->setCellValue('A'.$row, $this->mainTitle);
211 211
         
@@ -220,33 +220,33 @@  discard block
 block discarded – undo
220 220
         }
221 221
         
222 222
         // 使用实际的标题列数来合并单元格
223
-        $this->workSheet->mergeCells('A'.$row.':'.$this->cellName($titleCount-1).$row);
223
+        $this->workSheet->mergeCells('A'.$row.':'.$this->cellName($titleCount - 1).$row);
224 224
     }
225 225
 
226 226
     /**
227 227
      * @return void
228 228
      * @throws \PhpOffice\PhpSpreadsheet\Exception
229 229
      */
230
-    private function excelTitle(){
231
-        if($this->mainTitleLine === true){
232
-            $this->_row ++;//当前行数
230
+    private function excelTitle() {
231
+        if ($this->mainTitleLine === true) {
232
+            $this->_row++; //当前行数
233 233
         }
234 234
 
235 235
         $_merge = $this->cellName($this->_col);
236 236
         foreach ($this->fileTitle as $key => $val) {
237
-            if(!empty($this->titleHeight)) {
238
-                $this->workSheet->getRowDimension($this->_col)->setRowHeight($this->titleHeight);//行高度
237
+            if (!empty($this->titleHeight)) {
238
+                $this->workSheet->getRowDimension($this->_col)->setRowHeight($this->titleHeight); //行高度
239 239
             }
240 240
             $rowName = $this->cellName($this->_col);
241
-            $this->workSheet->getStyle($rowName . $this->_row)->getAlignment()->setWrapText(true);//自动换行
241
+            $this->workSheet->getStyle($rowName.$this->_row)->getAlignment()->setWrapText(true); //自动换行
242 242
             if (is_array($val)) {
243 243
                 $num = 1;
244 244
                 $_cols = $this->_col;
245 245
                 foreach ($val as $k => $v) {
246
-                    $this->workSheet->setCellValue($this->cellName($_cols) . ($this->_row+1), $k);
247
-                    if(!empty($this->titleWidth)) {
246
+                    $this->workSheet->setCellValue($this->cellName($_cols).($this->_row + 1), $k);
247
+                    if (!empty($this->titleWidth)) {
248 248
                         $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度
249
-                    }else{
249
+                    } else {
250 250
                         $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度
251 251
                     }
252 252
                     if ($num < count($val)) {
@@ -255,23 +255,23 @@  discard block
 block discarded – undo
255 255
                     }
256 256
                     $_cols++;
257 257
                 }
258
-                $this->workSheet->mergeCells($_merge . $this->_row.':' . $this->cellName($this->_col) .$this->_row);
259
-                $this->workSheet->setCellValue($_merge . $this->_row, $key);//设置值
258
+                $this->workSheet->mergeCells($_merge.$this->_row.':'.$this->cellName($this->_col).$this->_row);
259
+                $this->workSheet->setCellValue($_merge.$this->_row, $key); //设置值
260 260
             } else {
261 261
                 if ($this->title_row != 1) {
262
-                    $this->workSheet->mergeCells($rowName . $this->_row.':' . $rowName . ($this->_row + $this->title_row - 1));
262
+                    $this->workSheet->mergeCells($rowName.$this->_row.':'.$rowName.($this->_row + $this->title_row - 1));
263 263
                 }
264
-                $this->workSheet->setCellValue($rowName . $this->_row, $key);//设置值
265
-                if(!empty($this->titleWidth)){
264
+                $this->workSheet->setCellValue($rowName.$this->_row, $key); //设置值
265
+                if (!empty($this->titleWidth)) {
266 266
                     $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度
267
-                }else{
267
+                } else {
268 268
                     $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度
269 269
                 }
270 270
             }
271 271
             $this->_col++;
272 272
             $_merge = $this->cellName($this->_col);
273 273
         }
274
-        $this->_row += $this->title_row;//当前行数
274
+        $this->_row += $this->title_row; //当前行数
275 275
     }
276 276
 
277 277
     /**
@@ -282,60 +282,60 @@  discard block
 block discarded – undo
282 282
     private function excelSetCellValue($val)
283 283
     {
284 284
         //设置单元格行高
285
-        if(!empty($this->height)){
285
+        if (!empty($this->height)) {
286 286
             $this->workSheet->getRowDimension($this->_row)->setRowHeight($this->height);
287 287
         }
288 288
         $_lie = 0;
289
-        foreach ($this->field as $v){
289
+        foreach ($this->field as $v) {
290 290
             $rowName = $this->cellName($_lie);
291 291
 
292
-            if(strpos($v,'.') !== false){
293
-                $v = explode('.',$v);
292
+            if (strpos($v, '.') !== false) {
293
+                $v = explode('.', $v);
294 294
                 $content = $val;
295
-                for ($i=0;$i<count($v);$i++){
296
-                    $content = $content[$v[$i]]??'';
295
+                for ($i = 0; $i < count($v); $i++) {
296
+                    $content = $content[$v[$i]] ?? '';
297 297
                 }
298
-            }elseif($v == '_id'){
299
-                $content = $this->_row-$this->title_row;//自增序号列
300
-            }else{
301
-                $content = ($val[$v]??'');
298
+            }elseif ($v == '_id') {
299
+                $content = $this->_row - $this->title_row; //自增序号列
300
+            } else {
301
+                $content = ($val[$v] ?? '');
302 302
             }
303
-            if(is_array($content) && isset($content['type']) && isset($content['content'])){
304
-                if($content['type'] == 'image'){
303
+            if (is_array($content) && isset($content['type']) && isset($content['content'])) {
304
+                if ($content['type'] == 'image') {
305 305
                     $path = $this->verifyFile($content['content']);
306 306
                     $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
307 307
                     $drawing->setPath($path);
308
-                    if(!empty($content['height'])) {
308
+                    if (!empty($content['height'])) {
309 309
                         $drawing->setHeight($content['height']);
310 310
                     }
311
-                    if(!empty($content['width'])) {
312
-                        $drawing->setWidth($content['width']);//只设置高,宽会自适应,如果设置宽后,高则失效
311
+                    if (!empty($content['width'])) {
312
+                        $drawing->setWidth($content['width']); //只设置高,宽会自适应,如果设置宽后,高则失效
313 313
                     }
314
-                    if(!empty($content['offsetX'])) {
315
-                        $drawing->setOffsetX($content['offsetX']);//设置X方向偏移量
314
+                    if (!empty($content['offsetX'])) {
315
+                        $drawing->setOffsetX($content['offsetX']); //设置X方向偏移量
316 316
                     }
317
-                    if(!empty($content['offsetY'])) {
318
-                        $drawing->setOffsetY($content['offsetY']);//设置Y方向偏移量
317
+                    if (!empty($content['offsetY'])) {
318
+                        $drawing->setOffsetY($content['offsetY']); //设置Y方向偏移量
319 319
                     }
320 320
 
321 321
                     $drawing->setCoordinates($rowName.$this->_row);
322 322
                     $drawing->setWorksheet($this->workSheet);
323 323
                 }
324
-            }else {
325
-                $content = $this->formatValue($content);//格式化数据
326
-                if (is_numeric($content)){
327
-                    if($this->autoDataType && strlen($content)<11){
328
-                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC);
329
-                    }else{
330
-                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2);
324
+            } else {
325
+                $content = $this->formatValue($content); //格式化数据
326
+                if (is_numeric($content)) {
327
+                    if ($this->autoDataType && strlen($content) < 11) {
328
+                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content, DataType::TYPE_NUMERIC);
329
+                    } else {
330
+                        $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content, DataType::TYPE_STRING2);
331 331
                     }
332
-                }else{
333
-                    $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2);
332
+                } else {
333
+                    $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content, DataType::TYPE_STRING2);
334 334
                 }
335 335
             }
336
-            $_lie ++;
336
+            $_lie++;
337 337
         }
338
-        $this->_row ++;
338
+        $this->_row++;
339 339
     }
340 340
 
341 341
     /**
@@ -348,39 +348,39 @@  discard block
 block discarded – undo
348 348
     {
349 349
         // 获取分组字段在field中的实际位置
350 350
         $group_field_positions = [];
351
-        foreach($this->group_left as $group_field){
351
+        foreach ($this->group_left as $group_field) {
352 352
             $position = array_search($group_field, $this->field);
353
-            if($position !== false){
353
+            if ($position !== false) {
354 354
                 $group_field_positions[] = $position;
355 355
             }
356 356
         }
357 357
 
358
-        if(empty($group_field_positions)){
358
+        if (empty($group_field_positions)) {
359 359
             throw new TinymengException(StatusCode::COMMON_PARAM_INVALID, '分组字段未在标题中定义');
360 360
         }
361 361
 
362 362
         $group_start = $this->_row;
363
-        foreach ($data as $key => $val){
363
+        foreach ($data as $key => $val) {
364 364
             // 第一级分组的合并单元格
365 365
             $rowName = $this->cellName($group_field_positions[0]); // 使用第一个分组字段的实际位置
366
-            $coordinate = $rowName.$this->_row.':'.$rowName.($this->_row+$val['count']-1);
366
+            $coordinate = $rowName.$this->_row.':'.$rowName.($this->_row + $val['count'] - 1);
367 367
             $this->workSheet->mergeCells($coordinate);
368 368
             $this->workSheet->setCellValue($rowName.$this->_row, $key);
369 369
             
370
-            if($group_left_count == 1){
371
-                foreach ($val['data'] as $data){
370
+            if ($group_left_count == 1) {
371
+                foreach ($val['data'] as $data) {
372 372
                     $this->excelSetCellValue($data);
373 373
                 }
374
-            }else{
374
+            } else {
375 375
                 $sub_group_start = $this->_row;
376 376
                 $rowName = $this->cellName($group_field_positions[1]); // 使用第二个分组字段的实际位置
377 377
                 
378
-                foreach ($val['data'] as $k => $v){
379
-                    $coordinate = $rowName.$sub_group_start.':'.$rowName.($sub_group_start+$v['count']-1);
378
+                foreach ($val['data'] as $k => $v) {
379
+                    $coordinate = $rowName.$sub_group_start.':'.$rowName.($sub_group_start + $v['count'] - 1);
380 380
                     $this->workSheet->mergeCells($coordinate);
381 381
                     $this->workSheet->setCellValue($rowName.$sub_group_start, $k);
382 382
                     
383
-                    foreach ($v['data'] as $data){
383
+                    foreach ($v['data'] as $data) {
384 384
                         $this->excelSetCellValue($data);
385 385
                     }
386 386
                     
@@ -399,13 +399,13 @@  discard block
 block discarded – undo
399 399
      * @param array $data 二维数组原始数据
400 400
      * @return array
401 401
      */
402
-    private function arrayCount($data=[])
402
+    private function arrayCount($data = [])
403 403
     {
404
-        foreach ($data as $key => $val){
404
+        foreach ($data as $key => $val) {
405 405
             $num = 0;
406
-            foreach ($val as $k => $v){
406
+            foreach ($val as $k => $v) {
407 407
                 $sub_num = count($v);
408
-                $num = $num+$sub_num;
408
+                $num = $num + $sub_num;
409 409
                 $val[$k] = [
410 410
                     'count' => $sub_num,
411 411
                     'data' => $v
Please login to merge, or discard this patch.