@@ -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 | /* |
@@ -99,7 +99,10 @@ discard block |
||
| 99 | 99 | $this->fileTitle = []; |
| 100 | 100 | $this->data = []; |
| 101 | 101 | $this->field = []; |
| 102 | - if($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格 |
|
| 102 | + if($this->freezePane) { |
|
| 103 | + $this->workSheet->freezePane($this->freezePane); |
|
| 104 | + } |
|
| 105 | + //冻结窗格 |
|
| 103 | 106 | } |
| 104 | 107 | |
| 105 | 108 | /** |
@@ -124,7 +127,7 @@ discard block |
||
| 124 | 127 | $this->title_row = $fileTitle['title_row']??1; |
| 125 | 128 | $this->group_left = $fileTitle['group_left']??[]; |
| 126 | 129 | $this->fileTitle = $fileTitle['title']??[]; |
| 127 | - }else{ |
|
| 130 | + } else{ |
|
| 128 | 131 | /** |
| 129 | 132 | * $fileTitle = [ |
| 130 | 133 | * '姓名'=>'name', |
@@ -148,7 +151,7 @@ discard block |
||
| 148 | 151 | foreach ($val as $k => $v){ |
| 149 | 152 | $this->field[] = $v; |
| 150 | 153 | } |
| 151 | - }else{ |
|
| 154 | + } else{ |
|
| 152 | 155 | $this->field[] = $val; |
| 153 | 156 | } |
| 154 | 157 | } |
@@ -169,7 +172,7 @@ discard block |
||
| 169 | 172 | foreach ($this->data as $key => $val){ |
| 170 | 173 | $this->excelSetCellValue($val); |
| 171 | 174 | } |
| 172 | - }else{ //根据设置分组字段进行分组 |
|
| 175 | + } else{ //根据设置分组字段进行分组 |
|
| 173 | 176 | /** 数据分组 **/ |
| 174 | 177 | $data = []; |
| 175 | 178 | $group_left_count = count($this->group_left); |
@@ -184,13 +187,13 @@ discard block |
||
| 184 | 187 | ]; |
| 185 | 188 | } |
| 186 | 189 | $this->excelGroupLeft($data, 0, $group_left_count); |
| 187 | - }elseif($group_left_count == 2){ |
|
| 190 | + } elseif($group_left_count == 2){ |
|
| 188 | 191 | foreach ($this->data as $v) { |
| 189 | 192 | $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v; |
| 190 | 193 | } |
| 191 | 194 | $this->data = $this->arrayCount($data); |
| 192 | 195 | $this->excelGroupLeft($this->data, 0, $group_left_count); |
| 193 | - }else{ |
|
| 196 | + } else{ |
|
| 194 | 197 | throw new TinymengException(StatusCode::COMMON_PARAM_INVALID, |
| 195 | 198 | '左侧分组过多,导出失败!' |
| 196 | 199 | ); |
@@ -231,7 +234,7 @@ discard block |
||
| 231 | 234 | $this->workSheet->setCellValue($this->cellName($_cols) . ($this->_row+1), $k); |
| 232 | 235 | if(!empty($this->titleWidth)) { |
| 233 | 236 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度 |
| 234 | - }else{ |
|
| 237 | + } else{ |
|
| 235 | 238 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度 |
| 236 | 239 | } |
| 237 | 240 | if ($num < count($val)) { |
@@ -249,7 +252,7 @@ discard block |
||
| 249 | 252 | $this->workSheet->setCellValue($rowName . $this->_row, $key);//设置值 |
| 250 | 253 | if(!empty($this->titleWidth)){ |
| 251 | 254 | $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度 |
| 252 | - }else{ |
|
| 255 | + } else{ |
|
| 253 | 256 | $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度 |
| 254 | 257 | } |
| 255 | 258 | } |
@@ -280,9 +283,9 @@ discard block |
||
| 280 | 283 | for ($i=0;$i<count($v);$i++){ |
| 281 | 284 | $content = $content[$v[$i]]??''; |
| 282 | 285 | } |
| 283 | - }elseif($v == '_id'){ |
|
| 286 | + } elseif($v == '_id'){ |
|
| 284 | 287 | $content = $this->_row-$this->title_row;//自增序号列 |
| 285 | - }else{ |
|
| 288 | + } else{ |
|
| 286 | 289 | $content = ($val[$v]??''); |
| 287 | 290 | } |
| 288 | 291 | if(is_array($content) && isset($content['type']) && isset($content['content'])){ |
@@ -306,15 +309,15 @@ discard block |
||
| 306 | 309 | $drawing->setCoordinates($rowName.$this->_row); |
| 307 | 310 | $drawing->setWorksheet($this->workSheet); |
| 308 | 311 | } |
| 309 | - }else { |
|
| 312 | + } else { |
|
| 310 | 313 | $content = $this->formatValue($content);//格式化数据 |
| 311 | 314 | if (is_numeric($content)){ |
| 312 | 315 | if($this->autoDataType && strlen($content)<11){ |
| 313 | 316 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC); |
| 314 | - }else{ |
|
| 317 | + } else{ |
|
| 315 | 318 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
| 316 | 319 | } |
| 317 | - }else{ |
|
| 320 | + } else{ |
|
| 318 | 321 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
| 319 | 322 | } |
| 320 | 323 | } |
@@ -341,7 +344,7 @@ discard block |
||
| 341 | 344 | foreach ($val['data'] as $data){ |
| 342 | 345 | $this->excelSetCellValue($data); |
| 343 | 346 | } |
| 344 | - }else{ |
|
| 347 | + } else{ |
|
| 345 | 348 | $rowName = $this->cellName($_lie+1); //对应的列值 |
| 346 | 349 | foreach ($val['data'] as $k => $v){ |
| 347 | 350 | $group_end_col = $group_start + $v['count']-1; |