Bläddra i källkod

优化技术资料附件接口

曹鹤洋 2 år sedan
förälder
incheckning
b4cedd85f6
1 ändrade filer med 38 tillägg och 20 borttagningar
  1. 38 20
      application/api/controller/WorkOrder.php

+ 38 - 20
application/api/controller/WorkOrder.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use Monolog\Handler\IFTTTHandler;
+use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
 use think\Db;
 use think\Request;
 use PhpOffice\PhpSpreadsheet\IOFactory;
@@ -1688,26 +1689,43 @@ class WorkOrder extends Api
     public function getExcelInfo()
     {
         $fileName = '黄金叶(软大金圆)(二维码版)';
-        $filePath = 'uploads/黄金叶(软大金圆)(二维码版).xlsx'; // Excel文件路径
-        $excelData = []; // 存储 Excel 数据的数组
-
-        $spreadsheet = IOFactory::load($filePath);
-        $sheet = $spreadsheet->getActiveSheet();
-        $highestRow = $sheet->getHighestRow();
-        $highestColumn = $sheet->getHighestColumn();
-        for ($row = 1; $row <= $highestRow; $row++) {
-            for ($col = 'A'; $col <= $highestColumn; $col++) {
-                $cellValue = $sheet->getCell($col . $row)->getValue();
-                $excelData[$row][$col] = $cellValue;
-            }
+    $filePath = 'uploads/黄金叶(软大金圆)(二维码版).xlsx'; // Excel文件路径
+    $this->success('成功',['fileName'=>$fileName,'filePath'=>$filePath]);
+    $excelData = []; // 存储 Excel 数据的数组
+
+    $reader = IOFactory::createReader('Xlsx'); // 创建Excel读取器
+    $spreadsheet = $reader->load($filePath); // 加载Excel文件
+
+    $sheetData = $spreadsheet->getActiveSheet(); // 获取第一个工作表
+
+    // 处理 Excel 数据
+    $celldata = [];
+    $calcChain = [];
+    foreach ($sheetData->getRowIterator() as $row) {
+        foreach ($row->getCellIterator() as $cell) {
+            $coordinate = $cell->getCoordinate();
+            $value = $cell->getValue();
+            // 根据您的逻辑进行数据处理
+
+            // 示例:将坐标和值加入到celldata数组中
+            $celldata[] = [
+                'r' => Coordinate::coordinateFromString($coordinate)[0],
+                'c' => Coordinate::coordinateFromString($coordinate)[1],
+                'v' => $value
+            ];
         }
-        // 将 Excel 数据转换为 Luckysheet 格式的 JSON
-        // $data = [
-        //     'fileName' => $fileName,
-        //     'data' => $excelData,
-        // ];
-        $data = json_encode($excelData);
-        
-        $this->success('成功', ['fileName'=>$fileName,'data'=>$data]);
+    }
+    // 构建templateData
+    $templateData = [
+        'name' => $spreadsheet->getSheetNames()[0],
+        'index' => '1',
+        'order' => 0,
+        'status' => 1,
+        // 其他字段按照您的逻辑处理
+        'celldata' => $celldata,
+        'calcChain' => $calcChain
+    ];
+
+    return $templateData; // 返回处理后的数据
     }
 }