Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 0 additions & 1 deletion MiniExcel.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<File Path=".editorconfig" />
<File Path=".gitattributes" />
<File Path=".gitignore" />
<File Path="appveyor.yml" />
<File Path=".github\workflows\dotnet.yml" />
<File Path="LICENSE" />
<File Path="README.md" />
Expand Down
3 changes: 0 additions & 3 deletions README-V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<a href="https://www.nuget.org/packages/MiniExcel">
<img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt="">
</a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master">
<img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status">
</a>
<a href="https://gitee.com/dotnetchina/MiniExcel">
<img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star">
</a>
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div align="center">
<p><a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/v/MiniExcel.svg" alt="NuGet"></a> <a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt=""></a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master"><img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status"></a>
<a href="https://gitee.com/dotnetchina/MiniExcel"><img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star"></a> <a href="https://github.com/mini-software/MiniExcel" rel="nofollow"><img src="https://img.shields.io/github/stars/mini-software/MiniExcel?logo=github" alt="GitHub stars"></a>
<a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/badge/.NET-%3E%3D%204.5-red.svg" alt="version"></a>
<a href="https://deepwiki.com/mini-software/MiniExcel"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
Expand Down
1 change: 0 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div align="center">
<p><a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/v/MiniExcel.svg" alt="NuGet"></a> <a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt=""></a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master"><img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status"></a>
<a href="https://gitee.com/dotnetchina/MiniExcel"><img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star"></a> <a href="https://github.com/mini-software/MiniExcel" rel="nofollow"><img src="https://img.shields.io/github/stars/mini-software/MiniExcel?logo=github" alt="GitHub stars"></a>
<a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/badge/.NET-%3E%3D%204.5-red.svg" alt="version"></a>
<a href="https://deepwiki.com/mini-software/MiniExcel"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
Expand Down
23 changes: 0 additions & 23 deletions appveyor.yml

This file was deleted.

1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<div align="center">
<p><a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/v/MiniExcel.svg" alt="NuGet"></a> <a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt=""></a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master"><img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status"></a>
<a href="https://gitee.com/dotnetchina/MiniExcel"><img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star"></a> <a href="https://github.com/mini-software/MiniExcel" rel="nofollow"><img src="https://img.shields.io/github/stars/mini-software/MiniExcel?logo=github" alt="GitHub stars"></a>
<a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/badge/.NET-%3E%3D%204.5-red.svg" alt="version"></a>
</p>
Expand Down
1 change: 0 additions & 1 deletion docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<div align="center">
<p><a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/v/MiniExcel.svg" alt="NuGet"></a> <a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt=""></a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master"><img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status"></a>
<a href="https://gitee.com/dotnetchina/MiniExcel"><img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star"></a> <a href="https://github.com/mini-software/MiniExcel" rel="nofollow"><img src="https://img.shields.io/github/stars/mini-software/MiniExcel?logo=github" alt="GitHub stars"></a>
<a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/badge/.NET-%3E%3D%204.5-red.svg" alt="version"></a>
</p>
Expand Down
1 change: 0 additions & 1 deletion docs/README.zh-Hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<div align="center">
<p><a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/v/MiniExcel.svg" alt="NuGet"></a> <a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt=""></a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master"><img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status"></a>
<a href="https://gitee.com/dotnetchina/MiniExcel"><img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star"></a> <a href="https://github.com/mini-software/MiniExcel" rel="nofollow"><img src="https://img.shields.io/github/stars/mini-software/MiniExcel?logo=github" alt="GitHub stars"></a>
<a href="https://www.nuget.org/packages/MiniExcel"><img src="https://img.shields.io/badge/.NET-%3E%3D%204.5-red.svg" alt="version"></a>
</p>
Expand Down
3 changes: 0 additions & 3 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<a href="https://www.nuget.org/packages/MiniExcel">
<img src="https://img.shields.io/nuget/dt/MiniExcel.svg" alt="">
</a>
<a href="https://ci.appveyor.com/project/mini-software/miniexcel/branch/master">
<img src="https://ci.appveyor.com/api/projects/status/b2vustrwsuqx45f4/branch/master?svg=true" alt="Build status">
</a>
<a href="https://gitee.com/dotnetchina/MiniExcel">
<img src="https://gitee.com/dotnetchina/MiniExcel/badge/star.svg" alt="star">
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,110 +1,11 @@
namespace MiniExcelLib.Csv.Tests;
namespace MiniExcelLib.Csv.Tests.Issues;

public class AsyncIssueTests
{
private readonly CsvExporter _csvExporter = MiniExcel.Exporters.GetCsvExporter();
private readonly CsvImporter _csvImporter = MiniExcel.Importers.GetCsvImporter();

/// <summary>
/// Csv SaveAs by datareader with encoding default show messy code #253
/// </summary>
[Fact]
public async Task Issue253()
{
{
var value = new[] { new { col1 = "世界你好" } };
using var path = AutoDeletingPath.Create(ExcelType.Csv);

await _csvExporter.ExportAsync(path.ToString(), value);
const string expected =
"""
col1
世界你好

""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}

{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var value = new[] { new { col1 = "世界你好" } };
using var path = AutoDeletingPath.Create(ExcelType.Csv);

var config = new CsvConfiguration
{
StreamWriterFunc = stream => new StreamWriter(stream, Encoding.GetEncoding("gb2312"))
};

await _csvExporter.ExportAsync(path.ToString(), value, configuration: config);
const string expected =
"""
col1
�������

""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}

await using var cn = Db.GetConnection();

{
var value = await cn.ExecuteReaderAsync("select '世界你好' col1");
using var path = AutoDeletingPath.Create(ExcelType.Csv);
await _csvExporter.ExportAsync(path.ToString(), value);
const string expected =
"""
col1
世界你好

""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}
}

/// <summary>
/// [CSV SaveAs support datareader · Issue #251 · mini-software/MiniExcel](https://github.com/mini-software/MiniExcel/issues/251)
/// </summary>
[Fact]
public async Task Issue251()
{
await using var cn = Db.GetConnection();
var reader = await cn.ExecuteReaderAsync(@"select '""<>+-*//}{\\n' a,1234567890 b union all select '<test>Hello World</test>',-1234567890");

using var path = AutoDeletingPath.Create(ExcelType.Csv);
var rowsWritten = await _csvExporter.ExportAsync(path.ToString(), reader);

Assert.Equal(2, rowsWritten);

const string expected =
""""
a,b
"""<>+-*//}{\\n",1234567890
"<test>Hello World</test>",-1234567890

"""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}

private class Issue89Dto
{
public WorkState State { get; set; }

public enum WorkState
{
OnDuty,
Leave,
Fired
}
}

/// <summary>
/// Support Enum Mapping
/// https://github.com/mini-software/MiniExcel/issues/89
/// </summary>
// Support Enum Mapping
[Fact]
public async Task Issue89()
{
Expand Down Expand Up @@ -140,20 +41,6 @@ public async Task Issue89()
Assert.Equal(Issue89Dto.WorkState.Leave, rows2[2].State);
}

private class Issue142VoDuplicateColumnName
{
[MiniExcelColumnIndex("A")]
public int MyProperty1 { get; set; }

[MiniExcelColumnIndex("A")]
public int MyProperty2 { get; set; }

public int MyProperty3 { get; set; }
[MiniExcelColumnIndex("B")]

public int MyProperty4 { get; set; }
}

[Fact]
public async Task Issue142()
{
Expand All @@ -180,10 +67,7 @@ public async Task Issue142()
Assert.Equal("MyProperty3", rows[0].MyProperty3);
}

/// <summary>
/// DataTable recommended to use Caption for column name first, then use columname
/// https://github.com/mini-software/MiniExcel/issues/217
/// </summary>
// DataTable recommended to use Caption for column name first, then use columname
[Fact]
public async Task Issue217()
{
Expand All @@ -203,10 +87,7 @@ public async Task Issue217()
}


/// <summary>
/// Csv QueryAsync split comma not correct #237
/// https://github.com/mini-software/MiniExcel/issues/237
/// </summary>
// Csv QueryAsync split comma not correct
[Fact]
public async Task Issue237()
{
Expand All @@ -223,10 +104,7 @@ public async Task Issue237()
Assert.Equal("1,2,3", rows[1].id);
}


/// <summary>
/// Support Custom Datetime format #241
/// </summary>
// Support Custom Datetime format
[Fact]
public async Task Issue241()
{
Expand All @@ -252,9 +130,7 @@ public async Task Issue241()
}


/// <summary>
/// Csv type mapping QueryAsync error "cannot be converted to xxx type" #243
/// </summary>
// Csv type mapping QueryAsync error "cannot be converted to xxx type"
[Fact]
public async Task Issue243()
{
Expand All @@ -279,36 +155,83 @@ public async Task Issue243()
Assert.Equal(new DateTime(2020, 05, 03), rows[1].InDate);
}

#region Duplicated
private class Issue142Dto
{
[MiniExcelColumnName("CustomColumnName")]
public string? MyProperty1 { get; set; } //index = 1
[MiniExcelIgnore]
public string? MyProperty7 { get; set; } //index = null
public string? MyProperty2 { get; set; } //index = 3
[MiniExcelColumnIndex(6)]
public string? MyProperty3 { get; set; } //index = 6
[MiniExcelColumnIndex("A")] // equal column index 0
public string? MyProperty4 { get; set; }
[MiniExcelColumnIndex(2)]
public string? MyProperty5 { get; set; } //index = 2
public string? MyProperty6 { get; set; } //index = 4
}

private class Issue241Dto
// CSV support export from datareader
[Fact]
public async Task Issue251()
{
public string? Name { get; set; }
await using var cn = Db.GetConnection();
var reader = await cn.ExecuteReaderAsync(@"select '""<>+-*//}{\\n' a,1234567890 b union all select '<test>Hello World</test>',-1234567890");

using var path = AutoDeletingPath.Create(ExcelType.Csv);
var rowsWritten = await _csvExporter.ExportAsync(path.ToString(), reader);

Assert.Equal(2, rowsWritten);

const string expected =
""""
a,b
"""<>+-*//}{\\n",1234567890
"<test>Hello World</test>",-1234567890

[MiniExcelFormat("MM dd, yyyy")]
public DateTime InDate { get; set; }
"""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}

private class Issue243Dto

// Csv export from datareader with default encoding shows incorrect result
[Fact]
public async Task Issue253()
{
public string? Name { get; set; }
public int Age { get; set; }
public DateTime InDate { get; set; }
{
var value = new[] { new { col1 = "世界你好" } };
using var path = AutoDeletingPath.Create(ExcelType.Csv);

await _csvExporter.ExportAsync(path.ToString(), value);
const string expected =
"""
col1
世界你好

""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}

{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var value = new[] { new { col1 = "世界你好" } };
using var path = AutoDeletingPath.Create(ExcelType.Csv);

var config = new CsvConfiguration
{
StreamWriterFunc = stream => new StreamWriter(stream, Encoding.GetEncoding("gb2312"))
};

await _csvExporter.ExportAsync(path.ToString(), value, configuration: config);
const string expected =
"""
col1
�������

""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}

await using var cn = Db.GetConnection();

{
var value = await cn.ExecuteReaderAsync("select '世界你好' col1");
using var path = AutoDeletingPath.Create(ExcelType.Csv);
await _csvExporter.ExportAsync(path.ToString(), value);
const string expected =
"""
col1
世界你好

""";

Assert.Equal(expected, await File.ReadAllTextAsync(path.ToString()));
}
}
#endregion
}
Loading
Loading