Browse Source

Added MapHeader

Piotr Czajkowski 2 months ago
parent
commit
42fb40709d
1 changed files with 22 additions and 1 deletions
  1. 22 1
      ExcelORM/ExcelORM/Models/DynamicCell.cs

+ 22 - 1
ExcelORM/ExcelORM/Models/DynamicCell.cs

@@ -1,4 +1,6 @@
-namespace ExcelORM.Models
+using ClosedXML.Excel;
+
+namespace ExcelORM.Models
 {
     public record DynamicCell
     {
@@ -6,5 +8,24 @@
         public string? Header { get; set; }
         public Type? Type { get; set; }
         public object? Value { get; set; }
+
+        public static List<DynamicCell>? MapHeader(IXLCells? headerCells)
+        {
+            if (headerCells == null || !headerCells.Any()) return null;
+
+            var map = new List<DynamicCell>();
+            foreach(var cell in headerCells)
+            {
+                var headerItem = new DynamicCell
+                {
+                    Position = cell.Address.ColumnNumber,
+                    Header = cell.Value.GetText()
+                };
+
+                map.Add(headerItem);
+            }
+
+            return map;
+        }
     }
 }