Browse Source

修复如果点击单元格依然会变成科学计数法

sugangqiang 2 năm trước cách đây
mục cha
commit
c487b41657
2 tập tin đã thay đổi với 14 bổ sung5 xóa
  1. 5 4
      app/admin/controller/Talent.php
  2. 9 1
      app/common.php

+ 5 - 4
app/admin/controller/Talent.php

@@ -1792,14 +1792,15 @@ class Talent extends AdminController {
         for ($i = 0; $i < count($list); $i++) {
             $data = [];
             for ($n = 0; $n < count($fields); $n++) {
-                $data[] = $list[$i][$fields[$n]];
-                if ($fields[$n] == "deptPass" && $list[$i][$fields[$n]] > 0) {
+                $cellValue = $list[$i][$fields[$n]];
+                $data[] = $cellValue;
+                if ($fields[$n] == "deptPass" && $cellValue > 0) {
                     $setting["color"][] = [sprintf("%s%d", getExcelColumnByIndex($n), $i + 2), "15dd0f"];
                 }
-                if ($fields[$n] == "deptReject" && $list[$i][$fields[$n]] > 0) {
+                if ($fields[$n] == "deptReject" && $cellValue > 0) {
                     $setting["color"][] = [sprintf("%s%d", getExcelColumnByIndex($n), $i + 2), "ff0000"];
                 }
-                if ($fields[$n] == "deptWait" && $list[$i][$fields[$n]] > 0) {
+                if ($fields[$n] == "deptWait" && $cellValue > 0) {
                     $setting["color"][] = [sprintf("%s%d", getExcelColumnByIndex($n), $i + 2), "fdcb54"];
                 }
             }

+ 9 - 1
app/common.php

@@ -113,22 +113,30 @@ function export($columns, $rows, $filename = "jjrcw", $settings = [], $sheetname
     for ($i = 0; $i < $colCount; $i++) {
         $objPHPExcel->setCellValue(getExcelColumnByIndex($i) . $titleStartLine, $columns[$i]);
     }
+    $formatString = []; //需要文本处理的列
     //设置正文内容
     for ($i = 0; $i < $rowCount; $i++) {
         for ($n = 0; $n < $colCount; $n++) {
             if (is_numeric($rows[$i][$n]) && strlen($rows[$i][$n]) > 11) {
                 //超过11位的数字转成文本方以免被转化为科学数
                 $objPHPExcel->setCellValueExplicit(getExcelColumnByIndex($n) . ($rowStartLine + $i), $rows[$i][$n], $datatype::TYPE_STRING);
+                $formatString[] = $n;
             } else {
                 $objPHPExcel->setCellValue(getExcelColumnByIndex($n) . ($rowStartLine + $i), $rows[$i][$n]);
             }
         }
     }
+    $formatString = array_unique($formatString); //去掉重复项
+
     $objPHPExcel->getDefaultColumnDimension()->setWidth(16); //默认列宽
     $objPHPExcel->getDefaultRowDimension()->setRowHeight(30); //默认列高
     //样式设置
     $defaultSetting = getCommonExcelSetting($colCount, $rowCount);
-    $mergeSettings = [];
+    foreach ($formatString as $fs) {
+        $columnName = getExcelColumnByIndex($fs);
+        $defaultSetting["format"][] = ["string", sprintf("%s%d:%s%d", $columnName, 2, $columnName, count($rows) + 1)];
+    }
+    $mergeSettings = []; //合并默认设置与个性设置的集合
     foreach ($defaultSetting as $key => $set) {
         $mergeSettings[$key] = is_array($set) ? array_merge((array) $set, (array) $settings[$key]) : ($settings[$key] ?: $set);
         unset($settings[$key]);