From a3be1eb2f052b57e5c59758fd895dacc7f77a629 Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期一, 08 十二月 2025 09:14:35 +0800
Subject: [PATCH] 1、巡检导出2、报工

---
 WebApi/Gs.Toolbox/ExcelHelper.cs |   89 ++++++++++++++++++++++++++++++++------------
 1 files changed, 64 insertions(+), 25 deletions(-)

diff --git a/WebApi/Gs.Toolbox/ExcelHelper.cs b/WebApi/Gs.Toolbox/ExcelHelper.cs
index 8691007..8b0dce7 100644
--- a/WebApi/Gs.Toolbox/ExcelHelper.cs
+++ b/WebApi/Gs.Toolbox/ExcelHelper.cs
@@ -738,7 +738,6 @@
         }
     }
 
-
     /// <summary>
     /// 鐢熸垚宸℃
     /// </summary>
@@ -751,16 +750,14 @@
         //琛岄珮
         int rowHeight = 25;
         //鎬诲垪
-        int maxCols = tb1.Columns.Count;
+        int maxCols = 10;
         HSSFWorkbook workbook = new HSSFWorkbook();
         ISheet sheet = workbook.CreateSheet("Sheet1");
-
         // 鍒涘缓鍗曞厓鏍兼牱寮� - 甯﹁竟妗嗗拰鎸囧畾瀛椾綋
         ICellStyle style = getStyle(workbook);
         ICellStyle styleHeader = getStyle(workbook, 20, true, true);
         ICellStyle style12 = getStyle(workbook, 11, false, true);
-
-        // 璁剧疆鍒楀锛�6鍒楋級
+        // 璁剧疆鍒楀锛�10鍒楋級
         sheet.SetColumnWidth(0, 3000);  // 绗竴鍒楃◢瀹�
         sheet.SetColumnWidth(1, 3000);
         sheet.SetColumnWidth(2, 3000);
@@ -769,8 +766,10 @@
         sheet.SetColumnWidth(5, 3000);
         sheet.SetColumnWidth(6, 3000);
         sheet.SetColumnWidth(7, 3000);
-        // 鍒涘缓琛�
-        for (int rowIndex = 0; rowIndex <= 1; rowIndex++)
+        sheet.SetColumnWidth(8, 3000);
+        sheet.SetColumnWidth(9, 3000);
+        // 鍒涘缓澶磋
+        for (int rowIndex = 0; rowIndex <= 2; rowIndex++)
         {
             IRow row = sheet.CreateRow(rowIndex);
             // 璁剧疆琛岄珮锛堟墍鏈夎鐩稿悓楂樺害锛�
@@ -786,31 +785,70 @@
             }
         }
         //绗竴琛屽垪鍚堝苟
-        sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 7));
+        sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 9));
         setCellVal(sheet, 0, 0, row0["title"].ToString());
+        //绗簩琛屽垪鍚堝苟
+        sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 1));
+        sheet.AddMergedRegion(new CellRangeAddress(1, 1, 6, 9));
+        setCellVal(sheet, 1, 0, "宸ュ崟鍙�");
+        setCellVal(sheet, 1, 2, row0["daaNo"].ToString());
+        setCellVal(sheet, 1, 3, "浜у搧鍚嶇О");
+        setCellVal(sheet, 1, 4, row0["itemName"].ToString());
+        setCellVal(sheet, 1, 5, "瑙勬牸鍨嬪彿");
+        setCellVal(sheet, 1, 6, row0["itemModel"].ToString());
+        //绗笁琛屽垪鍚堝苟
+        sheet.AddMergedRegion(new CellRangeAddress(2, 2, 2, 4));
+        setCellVal(sheet, 2, 0, "搴忓彿");
+        setCellVal(sheet, 2, 1, "妫�楠岄」鐩�");
+        setCellVal(sheet, 2, 2, "妫�楠屾爣鍑�");
+        setCellVal(sheet, 2, 5, row0["tm1"].ToString());
+        setCellVal(sheet, 2, 6, row0["tm2"].ToString());
+        setCellVal(sheet, 2, 7, row0["tm3"].ToString());
+        setCellVal(sheet, 2, 8, row0["tm4"].ToString());
+        setCellVal(sheet, 2, 9, row0["tm5"].ToString());
         //寰幆鏁版嵁搴�
-        int _idx = 1;
-        IRow row6 = sheet.CreateRow(_idx);
-        for (int colIndex = 0; colIndex < maxCols; colIndex++)
-        {
-            ICell cell6 = row6.CreateCell(colIndex);
-            cell6.CellStyle = style;
-            cell6.SetCellValue(tb1.Columns[colIndex].Caption.ToString().Trim());
-        }
-        _idx++;
+        int _idx = 3;
         foreach (DataRow rrr in tb1.Rows)
         {
             IRow row7 = sheet.CreateRow(_idx);
             row7.HeightInPoints = rowHeight;
-            for (int colIndex = 0; colIndex < tb1.Columns.Count; colIndex++)
+            for (int colIndex = 0; colIndex < maxCols; colIndex++)
             {
                 ICell cell7 = row7.CreateCell(colIndex);
                 cell7.CellStyle = style;
-                cell7.SetCellValue(rrr[tb1.Columns[colIndex]].ToString());
+                // cell7.SetCellValue("1");
+                switch (colIndex)
+                {
+                    case 0:
+                        cell7.SetCellValue(rrr["搴忓彿"].ToString());
+                        break;
+                    case 1:
+                        sheet.AddMergedRegion(new CellRangeAddress(_idx, _idx, 2, 4));
+                        cell7.SetCellValue(rrr["妫�楠岄」鐩�"].ToString());
+                        break;
+                    case 2:
+                        cell7.SetCellValue(rrr["妫�楠屾爣鍑�"].ToString());
+                        break;
+                    case 5:
+                        cell7.SetCellValue(rrr["tm1"].ToString());
+                        break;
+                    case 6:
+                        cell7.SetCellValue(rrr["tm2"].ToString());
+                        break;
+                    case 7:
+                        cell7.SetCellValue(rrr["tm3"].ToString());
+                        break;
+                    case 8:
+                        cell7.SetCellValue(rrr["tm4"].ToString());
+                        break;
+                    case 9:
+                        cell7.SetCellValue(rrr["tm5"].ToString());
+                        break;
+                }
             }
             _idx++;
         }
-        //澶囨敞
+        ////澶囨敞
         IRow row8 = sheet.CreateRow(_idx);
         row8.HeightInPoints = rowHeight;
         for (int colIndex = 0; colIndex < maxCols; colIndex++)
@@ -818,12 +856,13 @@
             ICell cell = row8.CreateCell(colIndex);
             cell.CellStyle = style12;
         }
-        sheet.AddMergedRegion(new CellRangeAddress(_idx, _idx, 0, 2));
+        sheet.AddMergedRegion(new CellRangeAddress(_idx, _idx, 0, 4));
         setCellVal(sheet, _idx, 0, "宸℃浜猴細");
-        for (int colIndex = 2; colIndex < tb1.Columns.Count; colIndex++)
-        {
-            setCellVal(sheet, _idx, colIndex, "浣欏悏鏋�");
-        }
+        setCellVal(sheet, _idx, 5, row0["xjr1"].ToString());
+        setCellVal(sheet, _idx, 6, row0["xjr2"].ToString());
+        setCellVal(sheet, _idx, 7, row0["xjr3"].ToString());
+        setCellVal(sheet, _idx, 8, row0["xjr4"].ToString());
+        setCellVal(sheet, _idx, 9, row0["xjr5"].ToString());
         //淇濆瓨
         using (var ms = new MemoryStream())
         {

--
Gitblit v1.9.3