Browse Source

优化Excel导出

懒得勤快 3 years ago
parent
commit
8af91e8850

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

@@ -109,7 +109,7 @@ namespace Masuit.Tools.Excel
         /// <param name="settings">列设置</param>
         /// <param name="startRow">起始行,默认第一行</param>
         /// <param name="startColumn">起始列,默认第一列A列</param>
-        public static void FillWorksheet(this ExcelWorksheet sheet, DataTable table, ColumnSettings settings, int startRow = 1, int startColumn = 1)
+        public static void FillWorksheet(this ExcelWorksheet sheet, DataTable table, ColumnSettings settings = null, int startRow = 1, int startColumn = 1)
         {
             // 填充表头
             var maxWidth = new int[table.Columns.Count];
@@ -153,6 +153,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, bmp.Width * percent / 600 > 32 ? bmp.Width * percent / 600 : 32);
                                 }
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
 
                                 break;
                             }
@@ -169,6 +170,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, bmp.Width * percent / 600 > 32 ? bmp.Width * percent / 600 : 32);
                                 }
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
 
                                 break;
                             }
@@ -189,6 +191,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
                                 break;
                             }
 
@@ -207,6 +210,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
                                 break;
                             }
 
@@ -226,6 +230,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
                                 break;
                             }
 
@@ -245,6 +250,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
                                 break;
                             }
 
@@ -263,6 +269,7 @@ namespace Masuit.Tools.Excel
                                     sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
+                                sheet.SetValue(i + startRow + 1, j + startColumn, "");
                                 break;
                             }
 

+ 4 - 5
Masuit.Tools.Excel/Masuit.Tools.Excel.csproj

@@ -3,8 +3,7 @@
         <TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5;net6</TargetFrameworks>
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-        <CodeAnalysisRuleSet />
-        <Version>1.0.7</Version>
+        <Version>1.0.8</Version>
         <Authors>懒得勤快</Authors>
         <Description>Masuit.Tools.Excel导出库,支持一些简单数据的导出,支持图片列</Description>
         <Copyright>懒得勤快</Copyright>
@@ -17,9 +16,9 @@
         <RepositoryType>Github</RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
         <PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
-        <FileVersion>1.0.7</FileVersion>
-        <Company>ldqk.org</Company>
-        <AssemblyVersion>1.0.7</AssemblyVersion>
+        <FileVersion>1.0.8</FileVersion>
+        <Company>masuit.org</Company>
+        <AssemblyVersion>1.0.8</AssemblyVersion>
         <PackageLicenseUrl>https://github.com/ldqk/Masuit.Tools/blob/master/LICENSE</PackageLicenseUrl>
         <EmbedUntrackedSources>true</EmbedUntrackedSources>
         <IncludeSymbols>true</IncludeSymbols>