diff --git a/README.md b/README.md index 7c4cd1c5..45a75326 100644 --- a/README.md +++ b/README.md @@ -886,6 +886,7 @@ No, the image test has 1 million rows*10 columns of data, the maximum memory usa ### Limitations and caveats - Not support xls and encrypted file now +- xlsm only support Query ### Reference diff --git a/README.zh-CN.md b/README.zh-CN.md index 14b7224d..51b65925 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -881,7 +881,8 @@ A. 名称一样,系统会自动映射(注意:大小写不敏感) ### 局限与警告 -- 目前不支援 xls (97-2003) 或是加密文件。 +- 目前不支援 xls (97-2003) 或是加密文件 +- xlsm 只支持查询 diff --git a/README.zh-Hant.md b/README.zh-Hant.md index 1e40099d..3a4f4852 100644 --- a/README.zh-Hant.md +++ b/README.zh-Hant.md @@ -874,7 +874,8 @@ A. 名稱一樣,系統會自動映射(注意:大小寫不敏感) ### 侷限與警告 -- 目前不支援 xls (97-2003) 或是加密檔案。 +- 目前不支援 xls (97-2003) 或是加密檔案 +- xlsm 只支持查詢 diff --git a/docs/README.md b/docs/README.md index e2fb5f68..125fc61b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,6 +6,10 @@ --- +### 0.14.3 +- [Opt] Support Xlsm AutoCheck #227 +- [Bug] Fix SaveAsByTemplate single column demension index error #226 + ### 0.14.2 - [Bug] Fix asp.net webform gridview datasource can't use QueryAsDataTable #223 diff --git a/docs/README.zh-CN.md b/docs/README.zh-CN.md index 1bbd4aaf..f80bc8e0 100644 --- a/docs/README.zh-CN.md +++ b/docs/README.zh-CN.md @@ -7,6 +7,11 @@ --- + +### 0.14.3 +- [Opt] 支持 Xlsm 自动判断 #227 +- [Bug] 修正 SaveAsByTemplate 单列 demension 索引错误 #226 + ### 0.14.2 - [Bug] 修正 asp.net webform gridview datasource 不能使用 QueryAsDataTable #223 diff --git a/docs/README.zh-Hant.md b/docs/README.zh-Hant.md index ebe2b61d..09d4916c 100644 --- a/docs/README.zh-Hant.md +++ b/docs/README.zh-Hant.md @@ -7,6 +7,10 @@ --- +### 0.14.3 +- [Opt] 支持 Xlsm 自動判斷 #227 +- [Bug] 修正 SaveAsByTemplate 單列 demension 索引錯誤 #226 + ### 0.14.2 - [Bug] 修正 asp.net webform gridview datasource 不能使用 QueryAsDataTable #223 diff --git a/samples/xlsx/TestIssue227.xlsm b/samples/xlsx/TestIssue227.xlsm new file mode 100644 index 00000000..37948167 Binary files /dev/null and b/samples/xlsx/TestIssue227.xlsm differ diff --git a/src/MiniExcel/MiniExcel.TypeCheker.cs b/src/MiniExcel/MiniExcel.TypeCheker.cs index 542824b5..aa5040d8 100644 --- a/src/MiniExcel/MiniExcel.TypeCheker.cs +++ b/src/MiniExcel/MiniExcel.TypeCheker.cs @@ -14,6 +14,7 @@ internal static ExcelType GetExcelType(string filePath, ExcelType excelType) case ".csv": return ExcelType.CSV; case ".xlsx": + case ".xlsm": return ExcelType.XLSX; //case ".xls": // return ExcelType.XLS; diff --git a/src/MiniExcel/MiniExcel.cs b/src/MiniExcel/MiniExcel.cs index ba362b62..00f4b1c4 100644 --- a/src/MiniExcel/MiniExcel.cs +++ b/src/MiniExcel/MiniExcel.cs @@ -3,6 +3,7 @@ using MiniExcelLibs.OpenXml; using MiniExcelLibs.Utils; using MiniExcelLibs.Zip; + using System; using System.Collections.Generic; using System.Data; using System.IO; @@ -12,6 +13,8 @@ public static partial class MiniExcel { public static void SaveAs(string path, object value, bool printHeader = true, string sheetName = "Sheet1", ExcelType excelType = ExcelType.UNKNOWN, IConfiguration configuration = null) { + if (Path.GetExtension(path).ToLowerInvariant() == ".xlsm") + throw new NotSupportedException("MiniExcel SaveAs not support xlsm"); using (FileStream stream = new FileStream(path, FileMode.CreateNew)) SaveAs(stream, value, printHeader, sheetName, GetExcelType(path, excelType), configuration); } diff --git a/src/MiniExcel/MiniExcelLibs.csproj b/src/MiniExcel/MiniExcelLibs.csproj index 8811f128..3ff02dba 100644 --- a/src/MiniExcel/MiniExcelLibs.csproj +++ b/src/MiniExcel/MiniExcelLibs.csproj @@ -1,7 +1,7 @@ net45;netstandard2.0;net5.0 - 0.14.1 + 0.14.3 MiniExcel diff --git a/tests/MiniExcelTests/MiniExcelIssueTests.cs b/tests/MiniExcelTests/MiniExcelIssueTests.cs index 1ca9dbae..19b45991 100644 --- a/tests/MiniExcelTests/MiniExcelIssueTests.cs +++ b/tests/MiniExcelTests/MiniExcelIssueTests.cs @@ -25,6 +25,53 @@ public MiniExcelIssueTests(ITestOutputHelper output) this.output = output; } + /// + /// [Support Xlsm AutoCheck · Issue #227 · shps951023/MiniExcel] + /// (https://github.com/shps951023/MiniExcel/issues/227) + /// + [Fact] + public void Issue227() + { + { + var path = PathHelper.GetNewTemplateFilePath("xlsm"); + Assert.Throws(() => MiniExcel.SaveAs(path, new[] { new { V = "A1" }, new { V = "A2" } })); + } + + { + var path = PathHelper.GetSamplePath("xlsx/TestIssue227.xlsm"); + { + var rows = MiniExcel.Query(path).ToList(); + + Assert.Equal(100, rows.Count()); + + Assert.Equal(Guid.Parse("78DE23D2-DCB6-BD3D-EC67-C112BBC322A2"), rows[0].ID); + Assert.Equal("Wade", rows[0].Name); + Assert.Equal(DateTime.ParseExact("27/09/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture), rows[0].BoD); + Assert.Equal(36, rows[0].Age); + Assert.False(rows[0].VIP); + Assert.Equal(decimal.Parse("5019.12"), rows[0].Points); + Assert.Equal(1, rows[0].IgnoredProperty); + } + { + using (var stream = File.OpenRead(path)) + { + var rows = stream.Query().ToList(); + + Assert.Equal(100, rows.Count()); + + Assert.Equal(Guid.Parse("78DE23D2-DCB6-BD3D-EC67-C112BBC322A2"), rows[0].ID); + Assert.Equal("Wade", rows[0].Name); + Assert.Equal(DateTime.ParseExact("27/09/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture), rows[0].BoD); + Assert.Equal(36, rows[0].Age); + Assert.False(rows[0].VIP); + Assert.Equal(decimal.Parse("5019.12"), rows[0].Points); + Assert.Equal(1, rows[0].IgnoredProperty); + } + } + } + + + } /// /// https://github.com/shps951023/MiniExcel/issues/226 @@ -53,7 +100,7 @@ public void Issue223() new Dictionary(){{"A",Guid.NewGuid()},{"B","HelloWorld"}}, }; var path = PathHelper.GetNewTemplateFilePath(); - MiniExcel.SaveAs(path,value); + MiniExcel.SaveAs(path, value); var dt = MiniExcel.QueryAsDataTable(path); var columns = dt.Columns; @@ -74,7 +121,7 @@ public void Issue222() var path = PathHelper.GetSamplePath("xlsx/TestIssue222.xlsx"); var rows = MiniExcel.Query(path).ToList(); Assert.Equal(typeof(DateTime), rows[1].A.GetType()); - Assert.Equal(new DateTime(2021,4,29), rows[1].A); + Assert.Equal(new DateTime(2021, 4, 29), rows[1].A); } /// @@ -142,7 +189,7 @@ public void Issue211() MiniExcel.SaveAs(path, reader); - var rows = MiniExcel.Query(path,true).ToList(); + var rows = MiniExcel.Query(path, true).ToList(); Assert.Equal((double)1, rows[0].Test1); Assert.Equal((double)2, rows[0].Test2); Assert.Equal((double)3, rows[1].Test1); @@ -157,7 +204,7 @@ public void Issue211() public void Issue216() { var path = PathHelper.GetNewTemplateFilePath(); - var value = new[] { new { Test1="1",Test2=2 }, new { Test1 = "3", Test2 = 4 } }; + var value = new[] { new { Test1 = "1", Test2 = 2 }, new { Test1 = "3", Test2 = 4 } }; MiniExcel.SaveAs(path, value); { @@ -205,7 +252,7 @@ public void IssueI3OSKV() var value = new[] { new { Test = 123456.789 } }; MiniExcel.SaveAs(path, value); - var A2 = MiniExcel.Query(path,true).First().Test ; + var A2 = MiniExcel.Query(path, true).First().Test; Assert.Equal(123456.789, A2); File.Delete(path); @@ -223,14 +270,14 @@ public void Issue220() var path = PathHelper.GetSamplePath("xlsx/TestIssue220.xlsx"); var rows = MiniExcel.Query(path, useHeaderRow: true); var result = (from s in rows - group s by s.PRT_ID into g - select new - { - PRT_ID = g.Key, - Apr = g.Sum(_ => (double?)_.Apr), - May = g.Sum(_ => (double?)_.May), - Jun = g.Sum(_ => (double?)_.Jun), - } + group s by s.PRT_ID into g + select new + { + PRT_ID = g.Key, + Apr = g.Sum(_ => (double?)_.Apr), + May = g.Sum(_ => (double?)_.May), + Jun = g.Sum(_ => (double?)_.Jun), + } ).ToList(); Assert.Equal(91843.25, result[0].Jun); Assert.Equal(50000.99, result[1].Jun);