@@ -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 | /* |
@@ -106,7 +106,10 @@ discard block |
||
106 | 106 | $this->fileTitle = []; |
107 | 107 | $this->data = []; |
108 | 108 | $this->field = []; |
109 | - if($this->freezePane) $this->workSheet->freezePane($this->freezePane); //冻结窗格 |
|
109 | + if($this->freezePane) { |
|
110 | + $this->workSheet->freezePane($this->freezePane); |
|
111 | + } |
|
112 | + //冻结窗格 |
|
110 | 113 | } |
111 | 114 | |
112 | 115 | /** |
@@ -131,7 +134,7 @@ discard block |
||
131 | 134 | $this->title_row = $fileTitle['title_row']??1; |
132 | 135 | $this->group_left = $fileTitle['group_left']??[]; |
133 | 136 | $titleData = $fileTitle['title']??[]; |
134 | - }else{ |
|
137 | + } else{ |
|
135 | 138 | /** |
136 | 139 | * $fileTitle = [ |
137 | 140 | * '姓名'=>'name', |
@@ -142,7 +145,7 @@ discard block |
||
142 | 145 | // 根据字段映射方式处理 title |
143 | 146 | if ($this->fieldMappingMethod === ConstCode::FIELD_MAPPING_METHOD_FIELD_CORRESPONDING_NAME) { |
144 | 147 | $this->fileTitle = array_flip($titleData);// 字段对应名称方式 - 需要将键值对调 |
145 | - }else{ |
|
148 | + } else{ |
|
146 | 149 | $this->fileTitle = $titleData;// 名称对应字段方式 - 保持原样 |
147 | 150 | } |
148 | 151 | $this->data = $data; |
@@ -161,7 +164,7 @@ discard block |
||
161 | 164 | foreach ($val as $k => $v){ |
162 | 165 | $this->field[] = $v; |
163 | 166 | } |
164 | - }else{ |
|
167 | + } else{ |
|
165 | 168 | $this->field[] = $val; |
166 | 169 | } |
167 | 170 | } |
@@ -182,7 +185,7 @@ discard block |
||
182 | 185 | foreach ($this->data as $key => $val){ |
183 | 186 | $this->excelSetCellValue($val); |
184 | 187 | } |
185 | - }else{ //根据设置分组字段进行分组 |
|
188 | + } else{ //根据设置分组字段进行分组 |
|
186 | 189 | /** 数据分组 **/ |
187 | 190 | $data = []; |
188 | 191 | $group_left_count = count($this->group_left); |
@@ -197,13 +200,13 @@ discard block |
||
197 | 200 | ]; |
198 | 201 | } |
199 | 202 | $this->excelGroupLeft($data, $group_left_count); |
200 | - }elseif($group_left_count == 2){ |
|
203 | + } elseif($group_left_count == 2){ |
|
201 | 204 | foreach ($this->data as $v) { |
202 | 205 | $data[$v[$this->group_left[0]]][$v[$this->group_left[1]]][] = $v; |
203 | 206 | } |
204 | 207 | $this->data = $this->arrayCount($data); |
205 | 208 | $this->excelGroupLeft($this->data, $group_left_count); |
206 | - }else{ |
|
209 | + } else{ |
|
207 | 210 | throw new TinymengException(StatusCode::COMMON_PARAM_INVALID, |
208 | 211 | '左侧分组过多,导出失败!' |
209 | 212 | ); |
@@ -244,7 +247,7 @@ discard block |
||
244 | 247 | $this->workSheet->setCellValue($this->cellName($_cols) . ($this->_row+1), $k); |
245 | 248 | if(!empty($this->titleWidth)) { |
246 | 249 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setWidth($this->titleWidth); //列宽度 |
247 | - }else{ |
|
250 | + } else{ |
|
248 | 251 | $this->workSheet->getColumnDimension($this->cellName($_cols))->setAutoSize(true); //自动计算宽度 |
249 | 252 | } |
250 | 253 | if ($num < count($val)) { |
@@ -262,7 +265,7 @@ discard block |
||
262 | 265 | $this->workSheet->setCellValue($rowName . $this->_row, $key);//设置值 |
263 | 266 | if(!empty($this->titleWidth)){ |
264 | 267 | $this->workSheet->getColumnDimension($rowName)->setWidth($this->titleWidth); //列宽度 |
265 | - }else{ |
|
268 | + } else{ |
|
266 | 269 | $this->workSheet->getColumnDimension($rowName)->setAutoSize(true); //自动计算宽度 |
267 | 270 | } |
268 | 271 | } |
@@ -293,9 +296,9 @@ discard block |
||
293 | 296 | for ($i=0;$i<count($v);$i++){ |
294 | 297 | $content = $content[$v[$i]]??''; |
295 | 298 | } |
296 | - }elseif($v == '_id'){ |
|
299 | + } elseif($v == '_id'){ |
|
297 | 300 | $content = $this->_row-$this->title_row;//自增序号列 |
298 | - }else{ |
|
301 | + } else{ |
|
299 | 302 | $content = ($val[$v]??''); |
300 | 303 | } |
301 | 304 | if(is_array($content) && isset($content['type']) && isset($content['content'])){ |
@@ -319,15 +322,15 @@ discard block |
||
319 | 322 | $drawing->setCoordinates($rowName.$this->_row); |
320 | 323 | $drawing->setWorksheet($this->workSheet); |
321 | 324 | } |
322 | - }else { |
|
325 | + } else { |
|
323 | 326 | $content = $this->formatValue($content);//格式化数据 |
324 | 327 | if (is_numeric($content)){ |
325 | 328 | if($this->autoDataType && strlen($content)<11){ |
326 | 329 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_NUMERIC); |
327 | - }else{ |
|
330 | + } else{ |
|
328 | 331 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
329 | 332 | } |
330 | - }else{ |
|
333 | + } else{ |
|
331 | 334 | $this->workSheet->setCellValueExplicit($rowName.$this->_row, $content,DataType::TYPE_STRING2); |
332 | 335 | } |
333 | 336 | } |
@@ -369,7 +372,7 @@ discard block |
||
369 | 372 | foreach ($val['data'] as $data){ |
370 | 373 | $this->excelSetCellValue($data); |
371 | 374 | } |
372 | - }else{ |
|
375 | + } else{ |
|
373 | 376 | $sub_group_start = $this->_row; |
374 | 377 | $rowName = $this->cellName($group_field_positions[1]); // 使用第二个分组字段的实际位置 |
375 | 378 |