Browse Source

修正excel列格式不生效的bug

懒得勤快 11 months ago
parent
commit
294c90c2da
2 changed files with 16 additions and 2 deletions
  1. 1 1
      Directory.Build.props
  2. 15 1
      Masuit.Tools.Excel/ExcelExtension.cs

+ 1 - 1
Directory.Build.props

@@ -1,6 +1,6 @@
 <Project>
  <PropertyGroup>
-   <Version>2024.5.9</Version>
+   <Version>2024.5.10</Version>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
 </Project>

+ 15 - 1
Masuit.Tools.Excel/ExcelExtension.cs

@@ -386,6 +386,13 @@ public static class ExcelExtension
             {
                 sheet.Cells[startRow, startColumn].LoadFromDataTable(table, true, TableStyles.Light15).AutoFitColumns(12, 90);
                 sheet.Cells.Style.WrapText = true;
+                if (settings != null)
+                {
+                    foreach (var x in settings.ColumnTypes)
+                    {
+                        sheet.Column(x.Key).Style.Numberformat.Format = x.Value;
+                    }
+                }
             }
         }
     }
@@ -609,6 +616,13 @@ public static class ExcelExtension
             {
                 sheet.Cells[startRow, startColumn].LoadFromCollection(table, true, TableStyles.Light15).AutoFitColumns(12, 90);
                 sheet.Cells.Style.WrapText = true;
+                if (settings != null)
+                {
+                    foreach (var x in settings.ColumnTypes)
+                    {
+                        sheet.Column(x.Key).Style.Numberformat.Format = x.Value;
+                    }
+                }
             }
         }
     }
@@ -633,7 +647,7 @@ public static class ExcelExtension
     /// <param name="cell"></param>
     /// <param name="defaultValue"></param>
     /// <returns></returns>
-    public static T GetValue<T>(this ExcelRangeBase cell, T defaultValue=default)
+    public static T GetValue<T>(this ExcelRangeBase cell, T defaultValue = default)
     {
         return cell.Value.ChangeTypeTo(defaultValue);
     }