@@ -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); |
@@ -237,7 +240,7 @@ discard block |
||
| 237 | 240 | ]; |
| 238 | 241 | } |
| 239 | 242 | $this->excelGroupLeft($data, $group_left_count); |
| 240 | - }elseif($group_left_count == 2){ |
|
| 243 | + } elseif($group_left_count == 2){ |
|
| 241 | 244 | foreach ($this->data as $v) { |
| 242 | 245 | if(isset($v[$this->group_left[0]]) && isset($v[$this->group_left[1]])){ |
| 243 | 246 | $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v; |
@@ -245,7 +248,7 @@ discard block |
||
| 245 | 248 | } |
| 246 | 249 | $this->data = $this->arrayCount($data); |
| 247 | 250 | $this->excelGroupLeft($this->data, $group_left_count); |
| 248 | - }else{ |
|
| 251 | + } else{ |
|
| 249 | 252 | throw new TinymengException(StatusCode::COMMON_PARAM_INVALID, |
| 250 | 253 | '左侧分组过多,导出失败!' |
| 251 | 254 | ); |
@@ -302,7 +305,7 @@ discard block |
||
| 302 | 305 | } |
| 303 | 306 | if(!empty($this->titleWidth)) { |
| 304 | 307 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度 |
| 305 | - }else{ |
|
| 308 | + } else{ |
|
| 306 | 309 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度 |
| 307 | 310 | } |
| 308 | 311 | if ($num < count($val)) { |
@@ -324,7 +327,7 @@ discard block |
||
| 324 | 327 | } |
| 325 | 328 | if(!empty($this->titleWidth)){ |
| 326 | 329 | $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度 |
| 327 | - }else{ |
|
| 330 | + } else{ |
|
| 328 | 331 | $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度 |
| 329 | 332 | } |
| 330 | 333 | } |
@@ -355,9 +358,9 @@ discard block |
||
| 355 | 358 | for ($i=0;$i<count($v);$i++){ |
| 356 | 359 | $content = $content[$v[$i]]??''; |
| 357 | 360 | } |
| 358 | - }elseif($v == '_id'){ |
|
| 361 | + } elseif($v == '_id'){ |
|
| 359 | 362 | $content = $this->_row-$this->title_row;//自增序号列 |
| 360 | - }else{ |
|
| 363 | + } else{ |
|
| 361 | 364 | $content = ($val[$v]??''); |
| 362 | 365 | } |
| 363 | 366 | if(is_array($content) && isset($content['type']) && isset($content['content'])){ |
@@ -381,18 +384,18 @@ discard block |
||
| 381 | 384 | $drawing->setCoordinates($rowName.$this->_row); |
| 382 | 385 | $drawing->setWorksheet($this->workSheet); |
| 383 | 386 | } |
| 384 | - }elseif(is_array($content) && isset($content['formula'])){ |
|
| 387 | + } elseif(is_array($content) && isset($content['formula'])){ |
|
| 385 | 388 | // 新增:支持 ['formula' => '公式'] 写法 |
| 386 | 389 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content['formula'], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA); |
| 387 | - }else { |
|
| 390 | + } else { |
|
| 388 | 391 | $content = $this->formatValue($content);//格式化数据 |
| 389 | 392 | if (is_numeric($content)){ |
| 390 | 393 | if($this->autoDataType && strlen($content)<11){ |
| 391 | 394 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC); |
| 392 | - }else{ |
|
| 395 | + } else{ |
|
| 393 | 396 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
| 394 | 397 | } |
| 395 | - }else{ |
|
| 398 | + } else{ |
|
| 396 | 399 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
| 397 | 400 | } |
| 398 | 401 | } |
@@ -434,7 +437,9 @@ discard block |
||
| 434 | 437 | if (!empty($this->mergeColumns)) { |
| 435 | 438 | foreach ($this->mergeColumns as $field) { |
| 436 | 439 | // 跳过分组字段本身 |
| 437 | - if (in_array($field, $this->group_left)) continue; |
|
| 440 | + if (in_array($field, $this->group_left)) { |
|
| 441 | + continue; |
|
| 442 | + } |
|
| 438 | 443 | $colIdx = array_search($field, $this->field); |
| 439 | 444 | if ($colIdx !== false) { |
| 440 | 445 | $colLetter = $this->cellName($colIdx); |
@@ -449,7 +454,7 @@ discard block |
||
| 449 | 454 | foreach ($val['data'] as $dataRow){ |
| 450 | 455 | $this->excelSetCellValue($dataRow); |
| 451 | 456 | } |
| 452 | - }else{ |
|
| 457 | + } else{ |
|
| 453 | 458 | $sub_group_start = $this->_row; |
| 454 | 459 | $rowName = $this->cellName($group_field_positions[1]); // 使用第二个分组字段的实际位置 |
| 455 | 460 | |
@@ -504,10 +509,14 @@ discard block |
||
| 504 | 509 | */ |
| 505 | 510 | private function autoMergeColumns($rowStart, $rowEnd) |
| 506 | 511 | { |
| 507 | - if ($rowEnd <= $rowStart) return; |
|
| 512 | + if ($rowEnd <= $rowStart) { |
|
| 513 | + return; |
|
| 514 | + } |
|
| 508 | 515 | foreach ($this->mergeColumns as $fieldName) { |
| 509 | 516 | $colIdx = array_search($fieldName, $this->field); |
| 510 | - if ($colIdx === false) continue; |
|
| 517 | + if ($colIdx === false) { |
|
| 518 | + continue; |
|
| 519 | + } |
|
| 511 | 520 | $colLetter = $this->cellName($colIdx); |
| 512 | 521 | $lastValue = null; |
| 513 | 522 | $mergeStart = $rowStart; |
@@ -533,7 +542,9 @@ discard block |
||
| 533 | 542 | */ |
| 534 | 543 | private function applySheetStyle() |
| 535 | 544 | { |
| 536 | - if (empty($this->sheetStyle)) return; |
|
| 545 | + if (empty($this->sheetStyle)) { |
|
| 546 | + return; |
|
| 547 | + } |
|
| 537 | 548 | // 计算数据区范围 |
| 538 | 549 | $startCol = 'A'; |
| 539 | 550 | $endCol = $this->cellName(count($this->field) - 1); |