فهرست منبع

1. 移除多余的字典方法
2. Excel支持在指定位置开始填充单元格

懒得勤快 3 سال پیش
والد
کامیت
08d96ebccb

+ 10 - 39
Masuit.Tools.Abstractions/Extensions/BaseType/IDictionaryExtensions.cs

@@ -7,29 +7,6 @@ namespace Masuit.Tools
 {
     public static class IDictionaryExtensions
     {
-        /// <summary>
-        /// 添加或更新键值对
-        /// </summary>
-        /// <typeparam name="TKey"></typeparam>
-        /// <typeparam name="TValue"></typeparam>
-        /// <param name="this"></param>
-        /// <param name="key">键</param>
-        /// <param name="value">值</param>
-        /// <returns></returns>
-        public static TValue AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> @this, TKey key, TValue value)
-        {
-            if ([email protected](key))
-            {
-                @this.Add(key, value);
-            }
-            else
-            {
-                @this[key] = value;
-            }
-
-            return @this[key];
-        }
-
         /// <summary>
         /// 添加或更新键值对
         /// </summary>
@@ -42,7 +19,7 @@ namespace Masuit.Tools
         {
             foreach (var item in that)
             {
-                AddOrUpdate(@this, item.Key, item.Value);
+                @this[item.Key] = item.Value;
             }
         }
 
@@ -58,7 +35,7 @@ namespace Masuit.Tools
         {
             foreach (var item in @this)
             {
-                AddOrUpdate(that, item.Key, item.Value);
+                that[item.Key] = item.Value;
             }
         }
 
@@ -337,7 +314,7 @@ namespace Masuit.Tools
             var dic = new Dictionary<TKey, TSource>();
             foreach (var item in source)
             {
-                AddOrUpdate(dic, keySelector(item), item);
+                dic[keySelector(item)] = item;
             }
 
             return dic;
@@ -358,7 +335,7 @@ namespace Masuit.Tools
             var dic = new Dictionary<TKey, TElement>();
             foreach (var item in source)
             {
-                AddOrUpdate(dic, keySelector(item), elementSelector(item));
+                dic[keySelector(item)] = elementSelector(item);
             }
 
             return dic;
@@ -377,7 +354,7 @@ namespace Masuit.Tools
         public static async Task<IDictionary<TKey, TElement>> ToDictionarySafetyAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector)
         {
             var dic = new ConcurrentDictionary<TKey, TElement>();
-            await source.ForeachAsync(async item => dic.AddOrUpdate(keySelector(item), await elementSelector(item)));
+            await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
             return dic;
         }
 
@@ -395,7 +372,7 @@ namespace Masuit.Tools
             var dic = new ConcurrentDictionary<TKey, TSource>();
             foreach (var item in source)
             {
-                AddOrUpdate(dic, keySelector(item), item);
+                dic[keySelector(item)] = item;
             }
 
             return dic;
@@ -416,7 +393,7 @@ namespace Masuit.Tools
             var dic = new ConcurrentDictionary<TKey, TElement>();
             foreach (var item in source)
             {
-                AddOrUpdate(dic, keySelector(item), elementSelector(item));
+                dic[keySelector(item)] = elementSelector(item);
             }
 
             return dic;
@@ -435,7 +412,7 @@ namespace Masuit.Tools
         public static async Task<ConcurrentDictionary<TKey, TElement>> ToConcurrentDictionaryAsync<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, Task<TElement>> elementSelector)
         {
             var dic = new ConcurrentDictionary<TKey, TElement>();
-            await source.ForeachAsync(async item => dic.AddOrUpdate(keySelector(item), await elementSelector(item)));
+            await source.ForeachAsync(async item => dic[keySelector(item)] = await elementSelector(item));
             return dic;
         }
 
@@ -446,10 +423,7 @@ namespace Masuit.Tools
         /// <typeparam name="TValue"></typeparam>
         /// <param name="dic"></param>
         /// <returns></returns>
-        public static ConcurrentDictionary<TKey, TValue> AsConcurrentDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dic)
-        {
-            return new(dic);
-        }
+        public static ConcurrentDictionary<TKey, TValue> AsConcurrentDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dic) => new(dic);
 
         /// <summary>
         /// 转换成普通字典集合
@@ -458,9 +432,6 @@ namespace Masuit.Tools
         /// <typeparam name="TValue"></typeparam>
         /// <param name="dic"></param>
         /// <returns></returns>
-        public static Dictionary<TKey, TValue> AsDictionary<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dic)
-        {
-            return new(dic);
-        }
+        public static Dictionary<TKey, TValue> AsDictionary<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dic) => new(dic);
     }
 }

+ 3 - 3
Masuit.Tools.Abstractions/Masuit.Tools.Abstractions.csproj

@@ -4,7 +4,7 @@
     <LangVersion>latest</LangVersion>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <CodeAnalysisRuleSet />
-    <Version>2.4.5.3</Version>
+    <Version>2.4.5.5</Version>
     <Authors>懒得勤快</Authors>
     <Description>Masuit.Tools基础公共库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,Excel简单导出,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展等常用封装。</Description>
     <Copyright>懒得勤快,长空X</Copyright>
@@ -17,9 +17,9 @@
     <RepositoryType>Github</RepositoryType>
     <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
     <PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
-    <FileVersion>2.4.5.3</FileVersion>
+    <FileVersion>2.4.5.5</FileVersion>
     <Company>masuit.com</Company>
-    <AssemblyVersion>2.4.5.3</AssemblyVersion>
+    <AssemblyVersion>2.4.5.5</AssemblyVersion>
     <PackageLicenseUrl>https://github.com/ldqk/Masuit.Tools/blob/master/LICENSE</PackageLicenseUrl>
     <EmbedUntrackedSources>true</EmbedUntrackedSources>
     <IncludeSymbols>true</IncludeSymbols>

+ 4 - 4
Masuit.Tools.Abstractions/Mime/MimeMapper.cs

@@ -32,8 +32,8 @@ namespace Masuit.Tools.AspNetCore.Mime
         {
             foreach (var item in DefaultMimeItems.Items)
             {
-                MimeTypes.AddOrUpdate("." + item.Extension, item.MimeType);
-                ExtTypes.AddOrUpdate(item.MimeType, "." + item.Extension);
+                MimeTypes["." + item.Extension] = item.MimeType;
+                ExtTypes[item.MimeType] = "." + item.Extension;
             }
         }
 
@@ -64,8 +64,8 @@ namespace Masuit.Tools.AspNetCore.Mime
             {
                 foreach (var mapping in extensions)
                 {
-                    MimeTypes.AddOrUpdate(mapping.Extension, mapping.MimeType);
-                    ExtTypes.AddOrUpdate(mapping.MimeType, mapping.Extension);
+                    MimeTypes[mapping.Extension] = mapping.MimeType;
+                    ExtTypes[mapping.MimeType] = mapping.Extension;
                 }
             }
             return this;

+ 4 - 4
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -18,10 +18,10 @@ github:https://github.com/ldqk/Masuit.Tools
         <UserSecretsId>830c282f-f7c1-42be-8651-4cd06ac8e73f</UserSecretsId>
         <RepositoryType>Github</RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-        <Version>2.4.5.3</Version>
-        <FileVersion>2.4.5.3</FileVersion>
+        <Version>2.4.5.5</Version>
+        <FileVersion>2.4.5.5</FileVersion>
         <Company>masuit.com</Company>
-        <AssemblyVersion>2.4.5.3</AssemblyVersion>
+        <AssemblyVersion>2.4.5.5</AssemblyVersion>
         <Authors>懒得勤快</Authors>
         <RepositoryUrl>https://github.com/ldqk/Masuit.Tools</RepositoryUrl>
         <EmbedUntrackedSources>true</EmbedUntrackedSources>
@@ -36,7 +36,7 @@ github:https://github.com/ldqk/Masuit.Tools
         <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.7.0" />
         <PackageReference Include="System.Management" Version="4.7.0" />
         <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
-        <PackageReference Include="SharpCompress" Version="0.30.0" />
+        <PackageReference Include="SharpCompress" Version="0.30.1" />
     </ItemGroup>
 
     <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">

+ 54 - 40
Masuit.Tools.Excel/ExcelExtension.cs

@@ -89,17 +89,39 @@ namespace Masuit.Tools.Excel
             pkg.Workbook.Worksheets.Add(table.TableName);
             var sheet = pkg.Workbook.Worksheets[table.TableName];
 
+            FillWorksheet(sheet, table, settings);
+
+            //打印方向:纵向
+            sheet.PrinterSettings.Orientation = eOrientation.Landscape;
+
+            //集中在一页里打印
+            sheet.PrinterSettings.FitToPage = true;
+
+            //使用A4纸
+            sheet.PrinterSettings.PaperSize = ePaperSize.A4;
+        }
+
+        /// <summary>
+        /// 从datatable填充工作簿
+        /// </summary>
+        /// <param name="sheet">工作簿</param>
+        /// <param name="table">数据</param>
+        /// <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)
+        {
             // 填充表头
             var maxWidth = new int[table.Columns.Count];
             for (var j = 0; j < table.Columns.Count; j++)
             {
-                sheet.SetValue(1, j + 1, table.Columns[j].ColumnName);
+                sheet.SetValue(startRow, j + startColumn, table.Columns[j].ColumnName);
                 maxWidth[j] = Encoding.UTF8.GetBytes(table.Columns[j].ColumnName).Length;
             }
 
-            sheet.Row(1).Style.Font.Bold = true; // 表头设置为粗体
-            sheet.Row(1).Style.Font.Size = sheet.Row(1).Style.Font.Size * 1.11f; // 表头字号放大1.11倍
-            sheet.Row(1).CustomHeight = true; // 自动调整行高
+            sheet.Row(startRow).Style.Font.Bold = true; // 表头设置为粗体
+            sheet.Row(startRow).Style.Font.Size = sheet.Row(startRow).Style.Font.Size * 1.11f; // 表头字号放大1.11倍
+            sheet.Row(startRow).CustomHeight = true; // 自动调整行高
             sheet.Cells.AutoFitColumns(); // 表头自适应列宽
             sheet.Cells.Style.WrapText = true;
             if (settings != null)
@@ -113,7 +135,7 @@ namespace Masuit.Tools.Excel
             // 填充内容
             for (var i = 0; i < table.Rows.Count; i++)
             {
-                sheet.Row(i + 2).CustomHeight = true; // 自动调整行高
+                sheet.Row(i + startRow + 1).CustomHeight = true; // 自动调整行高
                 for (var j = 0; j < table.Columns.Count; j++)
                 {
                     switch (table.Rows[i][j])
@@ -125,11 +147,11 @@ namespace Masuit.Tools.Excel
                                     using var bmp = new Bitmap(s);
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
-                                    picture.SetPosition(i + 1, 3, j, 5); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, 5); //设置图片显示位置
                                     var percent = 11000f / bmp.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, bmp.Width * percent / 600 > 32 ? bmp.Width * percent / 600 : 32);
+                                    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);
                                 }
 
                                 break;
@@ -141,11 +163,11 @@ namespace Masuit.Tools.Excel
                                 {
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
-                                    picture.SetPosition(i + 1, 3, j, 5); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, 5); //设置图片显示位置
                                     var percent = 11000f / bmp.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, bmp.Width * percent / 600 > 32 ? bmp.Width * percent / 600 : 32);
+                                    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);
                                 }
 
                                 break;
@@ -159,12 +181,12 @@ namespace Masuit.Tools.Excel
                                     using var bmp = new Bitmap(stream);
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
-                                    picture.SetPosition(i + 1, 3, j, (int)(5 + sumWidth)); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
                                     var percent = 11000f / bmp.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
+                                    sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
+                                    sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
                                 break;
@@ -177,12 +199,12 @@ namespace Masuit.Tools.Excel
                                 {
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
-                                    picture.SetPosition(i + 1, 3, j, (int)(5 + sumWidth)); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
                                     var percent = 11000f / bmp.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
+                                    sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
+                                    sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
                                 break;
@@ -196,12 +218,12 @@ namespace Masuit.Tools.Excel
                                     using var bmp = new Bitmap(kv.Value);
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp, new Uri(kv.Key));
-                                    picture.SetPosition(i + 1, 3, j, (int)(5 + sumWidth)); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
                                     var percent = 11000f / bmp.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
+                                    sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
+                                    sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
                                 break;
@@ -215,12 +237,12 @@ namespace Masuit.Tools.Excel
                                     using var bmp = new Bitmap(kv.Value);
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp, new Uri(kv.Key));
-                                    picture.SetPosition(i + 1, 3, j, (int)(5 + sumWidth)); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
                                     var percent = 11000f / bmp.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
+                                    sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
+                                    sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
                                 break;
@@ -233,12 +255,12 @@ namespace Masuit.Tools.Excel
                                 {
                                     kv.Value.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), kv.Value, new Uri(kv.Key));
-                                    picture.SetPosition(i + 1, 3, j, (int)(5 + sumWidth)); //设置图片显示位置
+                                    picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
                                     var percent = 11000f / kv.Value.Height;
                                     picture.SetSize((int)percent);
-                                    sheet.Row(i + 2).Height = 90;
+                                    sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += kv.Value.Width * 1.0 * percent / 100 + 5;
-                                    sheet.Column(j + 1).Width = Math.Max(sheet.Column(j + 1).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
+                                    sheet.Column(j + startColumn).Width = Math.Max(sheet.Column(j + startColumn).Width, sumWidth / 6 > 32 ? sumWidth / 6 : 32);
                                 }
 
                                 break;
@@ -246,34 +268,26 @@ namespace Masuit.Tools.Excel
 
                         default:
                             {
-                                sheet.SetValue(i + 2, j + 1, table.Rows[i][j] ?? "");
+                                sheet.SetValue(i + startRow + 1, j + startColumn, table.Rows[i][j] ?? "");
                                 if (table.Rows[i][j] is ValueType)
                                 {
-                                    sheet.Column(j + 1).AutoFit();
+                                    sheet.Column(j + startColumn).AutoFit();
                                 }
                                 else
                                 {
                                     // 根据单元格内容长度来自适应调整列宽
-                                    sheet.Column(j + 1).Width = Math.Max(Encoding.UTF8.GetBytes(table.Rows[i][j].ToString() ?? string.Empty).Length + 2, sheet.Column(j + 1).Width);
-                                    if (sheet.Column(j + 1).Width > 110)
+                                    sheet.Column(j + startColumn).Width = Math.Max(Encoding.UTF8.GetBytes(table.Rows[i][j].ToString() ?? string.Empty).Length + 2, sheet.Column(j + startColumn).Width);
+                                    if (sheet.Column(j + startColumn).Width > 110)
                                     {
-                                        sheet.Column(j + 1).AutoFit(100, 110);
+                                        sheet.Column(j + startColumn).AutoFit(100, 110);
                                     }
                                 }
+
                                 break;
                             }
                     }
                 }
             }
-
-            //打印方向:纵向
-            sheet.PrinterSettings.Orientation = eOrientation.Landscape;
-
-            //集中在一页里打印
-            sheet.PrinterSettings.FitToPage = true;
-
-            //使用A4纸
-            sheet.PrinterSettings.PaperSize = ePaperSize.A4;
         }
     }
 }

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

@@ -4,7 +4,7 @@
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
         <CodeAnalysisRuleSet />
-        <Version>1.0.6</Version>
+        <Version>1.0.7</Version>
         <Authors>懒得勤快</Authors>
         <Description>Masuit.Tools.Excel导出库,支持一些简单数据的导出,支持图片列</Description>
         <Copyright>懒得勤快</Copyright>
@@ -17,9 +17,9 @@
         <RepositoryType>Github</RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
         <PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
-        <FileVersion>1.0.6</FileVersion>
+        <FileVersion>1.0.7</FileVersion>
         <Company>ldqk.org</Company>
-        <AssemblyVersion>1.0.6</AssemblyVersion>
+        <AssemblyVersion>1.0.7</AssemblyVersion>
         <PackageLicenseUrl>https://github.com/ldqk/Masuit.Tools/blob/master/LICENSE</PackageLicenseUrl>
         <EmbedUntrackedSources>true</EmbedUntrackedSources>
         <IncludeSymbols>true</IncludeSymbols>
@@ -29,7 +29,7 @@
         <DocumentationFile>.\Masuit.Tools.Excel.xml</DocumentationFile>
     </PropertyGroup>
     <ItemGroup>
-        <PackageReference Include="EPPlus" Version="5.8.2" />
+        <PackageReference Include="EPPlus" Version="5.8.3" />
         <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
         <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
     </ItemGroup>

BIN
Masuit.Tools.Net45/Properties/AssemblyInfo.cs


+ 1 - 1
Masuit.Tools.Net45/package.nuspec

@@ -4,7 +4,7 @@
     <!--*-->
     <id>Masuit.Tools.Net45</id>
     <!--*-->
-    <version>2.4.5.3</version>
+    <version>2.4.5.5</version>
     <title>Masuit.Tools</title>
     <!--*-->
     <authors>懒得勤快</authors>

+ 1 - 1
Masuit.Tools.NoSQL.MongoDBClient/Masuit.Tools.NoSQL.MongoDBClient.csproj

@@ -38,7 +38,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="MongoDB.Driver" Version="2.13.2" />
+    <PackageReference Include="MongoDB.Driver" Version="2.14.1" />
   </ItemGroup>
 
 </Project>

+ 1 - 1
Masuit.Tools/Masuit.Tools.csproj

@@ -178,7 +178,7 @@
       <Version>0.30.0</Version>
     </PackageReference>
     <PackageReference Include="StackExchange.Redis">
-      <Version>2.2.79</Version>
+      <Version>2.2.88</Version>
     </PackageReference>
     <PackageReference Include="System.ValueTuple">
       <Version>4.5.0</Version>

BIN
Masuit.Tools/Properties/AssemblyInfo.cs


+ 1 - 1
Masuit.Tools/package.nuspec

@@ -4,7 +4,7 @@
     <!--*-->
     <id>Masuit.Tools.Net</id>
     <!--*-->
-    <version>2.4.5.3</version>
+    <version>2.4.5.5</version>
     <title>Masuit.Tools</title>
     <!--*-->
     <authors>懒得勤快</authors>

+ 22 - 0
NetCoreTest/Program.cs

@@ -8,11 +8,13 @@ using Masuit.Tools.Security;
 using Microsoft.AspNetCore;
 using Microsoft.AspNetCore.Hosting;
 using Newtonsoft.Json;
+using OfficeOpenXml;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.IO;
 using System.Linq;
+using LicenseContext = OfficeOpenXml.LicenseContext;
 
 namespace NetCoreTest
 {
@@ -20,6 +22,26 @@ namespace NetCoreTest
     {
         public static void Main(string[] args)
         {
+            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
+            var pkg = new ExcelPackage();
+            pkg.Workbook.Worksheets.Add("Sheet1");
+            var sheet = pkg.Workbook.Worksheets["Sheet1"];
+            sheet.FillWorksheet(Enumerable.Range(1, 2).Select(i => new
+            {
+                序号 = i,
+                图片 = new Dictionary<string, Stream>()
+                {
+                    ["https://ldqk.org/1383"] = File.OpenRead(@"D:\images\emotion\16.jpg"),
+                    ["https://ldqk.org/1384"] = File.OpenRead(@"D:\images\emotion\16.jpg"),
+                    ["https://ldqk.org/1385"] = File.OpenRead(@"D:\images\emotion\16.jpg"),
+                }
+            }).ToDataTable("aa"), null, 4, 3);
+            sheet.Cells["A1:F1"].Merge = true;
+            sheet.Cells["A1"].Value = "title";
+            pkg.SaveAs("Y:\\1.xlsx");
+            Console.WriteLine("ok");
+
+            Console.ReadKey();
             Enumerable.Range(1, 2).Select(i => new
             {
                 序号 = i,

+ 6 - 6
Test/Masuit.Tools.Test/Masuit.Tools.Test.csproj

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props')" />
+  <Import Project="..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props')" />
   <Import Project="..\..\packages\NUnit.3.13.2\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.13.2\build\NUnit.props')" />
   <Import Project="..\..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
@@ -46,10 +46,10 @@
     </Reference>
     <Reference Include="Microsoft.CSharp" />
     <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
-      <HintPath>..\..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
+      <HintPath>..\..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
-      <HintPath>..\..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
+      <HintPath>..\..\packages\MSTest.TestFramework.2.2.8\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <HintPath>..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
@@ -152,9 +152,9 @@
     <Error Condition="!Exists('..\..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
     <Error Condition="!Exists('..\..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
     <Error Condition="!Exists('..\..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit.3.13.2\build\NUnit.props'))" />
-    <Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props'))" />
-    <Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets'))" />
+    <Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.props'))" />
+    <Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets'))" />
   </Target>
   <Import Project="..\..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
-  <Import Project="..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets')" />
+  <Import Project="..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\packages\MSTest.TestAdapter.2.2.8\build\net45\MSTest.TestAdapter.targets')" />
 </Project>

+ 2 - 2
Test/Masuit.Tools.Test/packages.config

@@ -6,8 +6,8 @@
   <package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net461" />
   <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
   <package id="Moq" version="4.16.1" targetFramework="net461" />
-  <package id="MSTest.TestAdapter" version="2.2.7" targetFramework="net461" />
-  <package id="MSTest.TestFramework" version="2.2.7" targetFramework="net461" />
+  <package id="MSTest.TestAdapter" version="2.2.8" targetFramework="net461" />
+  <package id="MSTest.TestFramework" version="2.2.8" targetFramework="net461" />
   <package id="NUnit" version="3.13.2" targetFramework="net461" />
   <package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net461" />
   <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net461" />