From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 HMI.Util/ExcelHelper.cs |   79 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/HMI.Util/ExcelHelper.cs b/HMI.Util/ExcelHelper.cs
index 9e795dc..801b657 100644
--- a/HMI.Util/ExcelHelper.cs
+++ b/HMI.Util/ExcelHelper.cs
@@ -1,10 +1,12 @@
 锘縰sing HMI.Core;
 using HMI.Core.Util;
 using NPOI.HSSF.UserModel;
+using NPOI.SS.Formula.Functions;
 using NPOI.SS.UserModel;
 using NPOI.XSSF.UserModel;
 using System;
 using System.Collections.Generic;
+using System.Data;
 using System.IO;
 using System.Linq;
 using System.Reflection;
@@ -55,6 +57,83 @@
             }
         }
 
+        public static void ExportExcel<T>(string targetPath, DataTable table)
+        {
+            Type type = typeof(T);
+            var properties = PropertyHelper.GetAtterProperty<T, ExcelColumnAttribute>(out var attrs);
+            if (properties == null || properties.Count <= 0)
+            {
+                throw new Exception("No Attribute");
+            }
+            IWorkbook workbook = null;
+            if (targetPath.EndsWith(".xlsx"))
+            {
+                workbook = new XSSFWorkbook();
+            }
+            else if (targetPath.EndsWith(".xls"))
+            {
+                workbook = new HSSFWorkbook();
+            }
+            workbook.CreateSheet("sheet1");////鏂板缓涓�涓伐浣滆〃
+            ISheet SheetOne = workbook.GetSheet("Sheet1");
+            IRow row1 = SheetOne.CreateRow(0);
+            for (int i = 0; i < properties.Count; i++)
+            {
+                row1.CreateCell(i).SetCellValue(LangUtil.Get((attrs[i]).Name));
+            }
+
+            for (int i = 0; i < table.Rows.Count; i++)
+            {
+                IRow rowTemp = SheetOne.CreateRow(i + 1);
+                for (int j = 0; j < properties.Count; j++)
+                {
+                    var attr = attrs[j];
+                    object obj = attr.IgnoreExport ? "" : table.Rows[i][properties[j].Name];
+                    string value = obj?.ToString();
+                    if (obj is DateTime time)
+                    {
+                        value = time.ToString("yyyy-MM-dd HH:mm:ss");
+                    }
+                    rowTemp.CreateCell(j).SetCellValue(value);
+                }
+            }
+
+            using (FileStream fs = new FileStream(targetPath, FileMode.OpenOrCreate))
+            {
+                workbook.Write(fs);
+            }
+        }
+
+        public static void ExportExcel(string targetPath, List<string[]> rows)
+        {
+            IWorkbook workbook = null;
+            if (targetPath.EndsWith(".xlsx"))
+            {
+                workbook = new XSSFWorkbook();
+            }
+            else if (targetPath.EndsWith(".xls"))
+            {
+                workbook = new HSSFWorkbook();
+            }
+            workbook.CreateSheet("sheet1");////鏂板缓涓�涓伐浣滆〃
+            ISheet SheetOne = workbook.GetSheet("sheet1");
+
+
+            for (int i = 0; i < rows.Count; i++)
+            {
+                IRow rowTemp = SheetOne.CreateRow(i);
+                for (int j = 0; j < rows[i].Length; j++)
+                {
+                    rowTemp.CreateCell(j).SetCellValue(rows[i][j]);
+                }
+            }
+
+            using (FileStream fs = new FileStream(targetPath, FileMode.OpenOrCreate))
+            {
+                workbook.Write(fs);
+            }
+        }
+
 
         public static List<T> ReadFromExcel<T>(string sourcePath)
         {

--
Gitblit v1.9.1