@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | if($this->workSheet == null){ |
86 | 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 | 91 | $this->sheetCount += 1;//总sheet数量 |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | public function download($filename=''){ |
147 | 147 | if(empty($filename)){ |
148 | 148 | $filename = $this->fileName; |
149 | - }else{ |
|
149 | + } else{ |
|
150 | 150 | $filename = $this->getFileName($filename); |
151 | 151 | } |
152 | 152 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $pathName = $this->getPathName($pathName); |
177 | 177 | if(empty($filename)){ |
178 | 178 | $filename = $this->fileName; |
179 | - }else{ |
|
179 | + } else{ |
|
180 | 180 | $filename = $this->getFileName($filename); |
181 | 181 | } |
182 | 182 | FileTool::mkdir($pathName); |
@@ -67,7 +67,9 @@ |
||
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | 69 | protected function formatValue($v){ |
70 | - if($this->format === false) return $v; |
|
70 | + if($this->format === false) { |
|
71 | + return $v; |
|
72 | + } |
|
71 | 73 | if(is_numeric($v) && strlen($v)===10){ |
72 | 74 | $v = date($this->format_date,$v);//时间戳转时间格式 |
73 | 75 | } |
@@ -136,10 +136,15 @@ |
||
136 | 136 | $value = trim($cell->getFormattedValue()); |
137 | 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)) { |
|
140 | + $rowFlog = true; |
|
141 | + } |
|
142 | + //有内容 |
|
140 | 143 | } |
141 | 144 | } |
142 | - if($rowFlog) $result[] = $data; |
|
145 | + if($rowFlog) { |
|
146 | + $result[] = $data; |
|
147 | + } |
|
143 | 148 | } |
144 | 149 | |
145 | 150 | /* |
@@ -123,7 +123,10 @@ discard block |
||
123 | 123 | $this->fileTitle = []; |
124 | 124 | $this->data = []; |
125 | 125 | $this->field = []; |
126 | - if($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格 |
|
126 | + if($this->freezePane) { |
|
127 | + $this->workSheet->freezePane($this->freezePane); |
|
128 | + } |
|
129 | + //冻结窗格 |
|
127 | 130 | } |
128 | 131 | |
129 | 132 | /** |
@@ -153,7 +156,7 @@ discard block |
||
153 | 156 | if (isset($titleConfig['mergeColumns'])) { |
154 | 157 | $this->mergeColumns = $titleConfig['mergeColumns']; |
155 | 158 | } |
156 | - }else{ |
|
159 | + } else{ |
|
157 | 160 | /** |
158 | 161 | * $titleConfig = [ |
159 | 162 | * '姓名'=>'name', |
@@ -164,7 +167,7 @@ discard block |
||
164 | 167 | // 根据字段映射方式处理 title |
165 | 168 | if ($this->fieldMappingMethod === ConstCode::FIELD_MAPPING_METHOD_FIELD_CORRESPONDING_NAME) { |
166 | 169 | $this->fileTitle = array_flip($titleData);// 字段对应名称方式 - 需要将键值对调 |
167 | - }else{ |
|
170 | + } else{ |
|
168 | 171 | $this->fileTitle = $titleData;// 名称对应字段方式 - 保持原样 |
169 | 172 | } |
170 | 173 | $this->data = $data; |
@@ -184,7 +187,7 @@ discard block |
||
184 | 187 | foreach ($val as $k => $v){ |
185 | 188 | $this->field[] = $v; |
186 | 189 | } |
187 | - }else{ |
|
190 | + } else{ |
|
188 | 191 | $this->field[] = $val; |
189 | 192 | } |
190 | 193 | } |
@@ -220,7 +223,7 @@ discard block |
||
220 | 223 | if (!empty($this->mergeColumns)) { |
221 | 224 | $this->autoMergeColumns($rowStart, $this->_row - 1); |
222 | 225 | } |
223 | - }else{ //根据设置分组字段进行分组 |
|
226 | + } else{ //根据设置分组字段进行分组 |
|
224 | 227 | /** 数据分组 **/ |
225 | 228 | $data = []; |
226 | 229 | $group_left_count = count($this->group_left); |
@@ -235,13 +238,13 @@ discard block |
||
235 | 238 | ]; |
236 | 239 | } |
237 | 240 | $this->excelGroupLeft($data, $group_left_count); |
238 | - }elseif($group_left_count == 2){ |
|
241 | + } elseif($group_left_count == 2){ |
|
239 | 242 | foreach ($this->data as $v) { |
240 | 243 | $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v; |
241 | 244 | } |
242 | 245 | $this->data = $this->arrayCount($data); |
243 | 246 | $this->excelGroupLeft($this->data, $group_left_count); |
244 | - }else{ |
|
247 | + } else{ |
|
245 | 248 | throw new TinymengException(StatusCode::COMMON_PARAM_INVALID, |
246 | 249 | '左侧分组过多,导出失败!' |
247 | 250 | ); |
@@ -299,7 +302,7 @@ discard block |
||
299 | 302 | $this->workSheet->setCellValue($this->cellName($_cols) . ($this->_row+1), $k); |
300 | 303 | if(!empty($this->titleWidth)) { |
301 | 304 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度 |
302 | - }else{ |
|
305 | + } else{ |
|
303 | 306 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度 |
304 | 307 | } |
305 | 308 | if ($num < count($val)) { |
@@ -317,7 +320,7 @@ discard block |
||
317 | 320 | $this->workSheet->setCellValue($rowName . $this->_row, $key);//设置值 |
318 | 321 | if(!empty($this->titleWidth)){ |
319 | 322 | $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度 |
320 | - }else{ |
|
323 | + } else{ |
|
321 | 324 | $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度 |
322 | 325 | } |
323 | 326 | } |
@@ -348,9 +351,9 @@ discard block |
||
348 | 351 | for ($i=0;$i<count($v);$i++){ |
349 | 352 | $content = $content[$v[$i]]??''; |
350 | 353 | } |
351 | - }elseif($v == '_id'){ |
|
354 | + } elseif($v == '_id'){ |
|
352 | 355 | $content = $this->_row-$this->title_row;//自增序号列 |
353 | - }else{ |
|
356 | + } else{ |
|
354 | 357 | $content = ($val[$v]??''); |
355 | 358 | } |
356 | 359 | if(is_array($content) && isset($content['type']) && isset($content['content'])){ |
@@ -374,18 +377,18 @@ discard block |
||
374 | 377 | $drawing->setCoordinates($rowName.$this->_row); |
375 | 378 | $drawing->setWorksheet($this->workSheet); |
376 | 379 | } |
377 | - }elseif(is_array($content) && isset($content['formula'])){ |
|
380 | + } elseif(is_array($content) && isset($content['formula'])){ |
|
378 | 381 | // 新增:支持 ['formula' => '公式'] 写法 |
379 | 382 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content['formula'], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA); |
380 | - }else { |
|
383 | + } else { |
|
381 | 384 | $content = $this->formatValue($content);//格式化数据 |
382 | 385 | if (is_numeric($content)){ |
383 | 386 | if($this->autoDataType && strlen($content)<11){ |
384 | 387 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC); |
385 | - }else{ |
|
388 | + } else{ |
|
386 | 389 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
387 | 390 | } |
388 | - }else{ |
|
391 | + } else{ |
|
389 | 392 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
390 | 393 | } |
391 | 394 | } |
@@ -427,7 +430,9 @@ discard block |
||
427 | 430 | if (!empty($this->mergeColumns)) { |
428 | 431 | foreach ($this->mergeColumns as $field) { |
429 | 432 | // 跳过分组字段本身 |
430 | - if (in_array($field, $this->group_left)) continue; |
|
433 | + if (in_array($field, $this->group_left)) { |
|
434 | + continue; |
|
435 | + } |
|
431 | 436 | $colIdx = array_search($field, $this->field); |
432 | 437 | if ($colIdx !== false) { |
433 | 438 | $colLetter = $this->cellName($colIdx); |
@@ -442,7 +447,7 @@ discard block |
||
442 | 447 | foreach ($val['data'] as $dataRow){ |
443 | 448 | $this->excelSetCellValue($dataRow); |
444 | 449 | } |
445 | - }else{ |
|
450 | + } else{ |
|
446 | 451 | $sub_group_start = $this->_row; |
447 | 452 | $rowName = $this->cellName($group_field_positions[1]); // 使用第二个分组字段的实际位置 |
448 | 453 | |
@@ -497,10 +502,14 @@ discard block |
||
497 | 502 | */ |
498 | 503 | private function autoMergeColumns($rowStart, $rowEnd) |
499 | 504 | { |
500 | - if ($rowEnd <= $rowStart) return; |
|
505 | + if ($rowEnd <= $rowStart) { |
|
506 | + return; |
|
507 | + } |
|
501 | 508 | foreach ($this->mergeColumns as $fieldName) { |
502 | 509 | $colIdx = array_search($fieldName, $this->field); |
503 | - if ($colIdx === false) continue; |
|
510 | + if ($colIdx === false) { |
|
511 | + continue; |
|
512 | + } |
|
504 | 513 | $colLetter = $this->cellName($colIdx); |
505 | 514 | $lastValue = null; |
506 | 515 | $mergeStart = $rowStart; |
@@ -526,7 +535,9 @@ discard block |
||
526 | 535 | */ |
527 | 536 | private function applySheetStyle() |
528 | 537 | { |
529 | - if (empty($this->sheetStyle)) return; |
|
538 | + if (empty($this->sheetStyle)) { |
|
539 | + return; |
|
540 | + } |
|
530 | 541 | // 计算数据区范围 |
531 | 542 | $startCol = 'A'; |
532 | 543 | $endCol = $this->cellName(count($this->field) - 1); |