Browse Source

修正Excel导出图像缩放的问题

懒得勤快 3 years ago
parent
commit
2f225a6aeb

+ 9 - 7
Masuit.Tools.Excel/ExcelExtension.cs

@@ -148,11 +148,12 @@ namespace Masuit.Tools.Excel
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
                                     picture.SetPosition(i + startRow, 3, j + startColumn - 1, 5); //设置图片显示位置
-                                    var percent = 11000f / bmp.Height;
+                                    var percent = Math.Min(11000f / bmp.Height, 100);
                                     picture.SetSize((int)percent);
                                     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;
@@ -165,11 +166,12 @@ namespace Masuit.Tools.Excel
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
                                     picture.SetPosition(i + startRow, 3, j + startColumn - 1, 5); //设置图片显示位置
-                                    var percent = 11000f / bmp.Height;
+                                    var percent = Math.Min(11000f / bmp.Height, 100);
                                     picture.SetSize((int)percent);
                                     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;
@@ -184,7 +186,7 @@ namespace Masuit.Tools.Excel
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
                                     picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
-                                    var percent = 11000f / bmp.Height;
+                                    var percent = Math.Min(11000f / bmp.Height, 100);
                                     picture.SetSize((int)percent);
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
@@ -203,7 +205,7 @@ namespace Masuit.Tools.Excel
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp);
                                     picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
-                                    var percent = 11000f / bmp.Height;
+                                    var percent = Math.Min(11000f / bmp.Height, 100);
                                     picture.SetSize((int)percent);
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
@@ -223,7 +225,7 @@ namespace Masuit.Tools.Excel
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp, new Uri(kv.Key));
                                     picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
-                                    var percent = 11000f / bmp.Height;
+                                    var percent = Math.Min(11000f / bmp.Height, 100);
                                     picture.SetSize((int)percent);
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
@@ -243,7 +245,7 @@ namespace Masuit.Tools.Excel
                                     bmp.SetResolution(96, 96);
                                     var picture = sheet.Drawings.AddPicture(Guid.NewGuid().ToString(), bmp, new Uri(kv.Key));
                                     picture.SetPosition(i + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
-                                    var percent = 11000f / bmp.Height;
+                                    var percent = Math.Min(11000f / bmp.Height, 100);
                                     picture.SetSize((int)percent);
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += bmp.Width * 1.0 * percent / 100 + 5;
@@ -262,7 +264,7 @@ 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 + startRow, 3, j + startColumn - 1, (int)(5 + sumWidth)); //设置图片显示位置
-                                    var percent = 11000f / kv.Value.Height;
+                                    var percent = Math.Min(11000f / kv.Value.Height, 100);
                                     picture.SetSize((int)percent);
                                     sheet.Row(i + startRow + 1).Height = 90;
                                     sumWidth += kv.Value.Width * 1.0 * percent / 100 + 5;

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

@@ -3,7 +3,7 @@
         <TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5;net6</TargetFrameworks>
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-        <Version>1.0.9</Version>
+        <Version>1.1</Version>
         <Authors>懒得勤快</Authors>
         <Description>Masuit.Tools.Excel导出库,支持一些简单数据的导出,支持图片列</Description>
         <Copyright>懒得勤快</Copyright>