Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MiniExcel/MiniExcel.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static async Task<int[]> SaveAsAsync(this Stream stream, object value, bo
return await ExcelWriterFactory.GetProvider(stream, value, sheetName, excelType, configuration, printHeader).SaveAsAsync(cancellationToken);
}

public static async Task MergeSameCellsAsync(string mergedFilePath, string path, ExcelType excelType = ExcelType.UNKNOWN, IConfiguration configuration = null, CancellationToken cancellationToken = default)
public static async Task MergeSameCellsAsync(string mergedFilePath, string path, ExcelType excelType = ExcelType.XLSX, IConfiguration configuration = null, CancellationToken cancellationToken = default)
Comment thread
michelebastione marked this conversation as resolved.
{
await Task.Run(() => MergeSameCells(mergedFilePath, path, excelType, configuration), cancellationToken).ConfigureAwait(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/MiniExcel/SaveByTemplate/InputValueExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private static IDictionary<string, object> GetValuesFromObject(object valueObjec

var propertyValues = type
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(property => property.CanRead && property.GetIndexParameters().Length == 0)
.Select(property => new { property.Name, Value = property.GetValue(valueObject) });

var fieldValues = type
Expand Down
47 changes: 38 additions & 9 deletions tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

private class SaveAsControlChracterVO
{
public string Test { get; set; }

Check warning on line 44 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

private class ExcelAttributeDemo
{
[ExcelColumnName("Column1")]
public string Test1 { get; set; }

Check warning on line 50 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test1' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[ExcelColumnName("Column2")]
public string Test2 { get; set; }

Check warning on line 52 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[ExcelIgnore]
public string Test3 { get; set; }
[ExcelColumnIndex("I")] // system will convert "I" to 8 index
Expand All @@ -63,17 +63,17 @@
private class ExcelAttributeDemo2
{
[ExcelColumn(Name = "Column1")]
public string Test1 { get; set; }

Check warning on line 66 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test1' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[ExcelColumn(Name = "Column2")]
public string Test2 { get; set; }

Check warning on line 68 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[ExcelColumn(Ignore = true)]
public string Test3 { get; set; }

Check warning on line 70 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test3' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[ExcelColumn(IndexName = "I")] // system will convert "I" to 8 index
public string Test4 { get; set; }

Check warning on line 72 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test4' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Test5 { get; } //wihout set will ignore

Check warning on line 73 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test5' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Test6 { get; private set; } //un-public set will ignore

Check warning on line 74 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test6' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[ExcelColumn(Index = 3)] // start with 0
public string Test7 { get; set; }

Check warning on line 76 in tests/MiniExcelTests/MiniExcelOpenXmlAsyncTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Test7' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

[Fact]
Expand Down Expand Up @@ -1607,21 +1607,50 @@
{
using var path = AutoDeletingPath.Create();

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
await MiniExcel.SaveAsAsync(path.ToString(), GetValues());
var results = MiniExcel.Query<Demo>(path.ToString()).ToList();

Assert.Equal(2, results.Count);
Assert.Equal("MiniExcel", results.First().Column1);
Assert.Equal(1, results.First().Column2);
Assert.Equal("Github", results.Last().Column1);
Assert.Equal(2, results.Last().Column2);
return;

static async IAsyncEnumerable<Demo> GetValues()
{
yield return new Demo { Column1 = "MiniExcel", Column2 = 1 };
await Task.CompletedTask;
yield return new Demo { Column1 = "Github", Column2 = 2 };
await Task.CompletedTask;
}
#pragma warning restore CS1998
}

await MiniExcel.SaveAsAsync(path.ToString(), GetValues());
var results = MiniExcel.Query<Demo>(path.ToString()).ToList();
[Fact]
public async Task TestIssue951()
{
var templatePath = PathHelper.GetFile("xlsx/TestTemplateEasyFill.xlsx");
using var path = AutoDeletingPath.Create();

var value = new Issue951
{
Name = "Jack",
CreateDate = new DateTime(2021, 01, 01),
VIP = true,
Points = 123
};

Assert.True(results.Count == 2);
Assert.True(results.First().Column1 == "MiniExcel");
Assert.True(results.First().Column2 == 1);
Assert.True(results.Last().Column1 == "Github");
Assert.True(results.Last().Column2 == 2);
// must not throw
await MiniExcel.SaveAsByTemplateAsync(path.ToString(), templatePath, value);
}

class Issue951
{
public string? Name { get; set; }
public DateTime CreateDate { get; set; }
public bool VIP { get; set; }
public double Points { get; set; }

public object this[string test] => new();
}
}
Loading