ExcelToolKit 1.0.3
dotnet add package ExcelToolKit --version 1.0.3
NuGet\Install-Package ExcelToolKit -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ExcelToolKit" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ExcelToolKit" Version="1.0.3" />
<PackageReference Include="ExcelToolKit" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ExcelToolKit --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ExcelToolKit, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ExcelToolKit@1.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ExcelToolKit&version=1.0.3
#tool nuget:?package=ExcelToolKit&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ExcelTools
基于NPOI快捷读取和输出excel的小工具
- nuget地址 https://www.nuget.org/packages/ExcelToolKit/
- 安装命令
dotnet add package ExcelToolKit --version 1.0.0
- 安装命令
- github地址 https://github.com/myhubo/ExcelTools/tree/main
实现功能
- 支持读取.xlsx和.xls格式的excel文件为对象列表
- 支持将对象列表输出为.xlsx和.xls格式的excel文件
- 如果读取的excel有错误,可在原文件最后增加具体错误信息
快速开始
1.定义实体类
- 定义实体对象,通过
ExcelTemplateAttribute
指定读取方式,按标题读取或按位置读取; - 通过
ExcelColumnAttribute
自定义列信息
/// <summary>
/// 测试数据1
/// 按字段名读取,读取第0个sheet
/// </summary>
[ExcelTemplate]
[MyExcelRowMessage]
public class TestData1
{
[Required]
/// <summary>
/// 编码
/// </summary>
[ExcelColumn("编码")]
public string Code { get; set; }
/// <summary>
/// 商品名称
/// </summary>
[ExcelColumn("商品名称")]
public string Name { get; set; }
/// …… 省略其他属性
}
2.读取Excel
- 读取Excel文件,并返回对象列表
var data = ExcelHelper.ReadData<TestData1>(path);
- 读取Excel文件,在原excel文件中加入错误信息列
(_,var stream) = ExcelHelper.ReadDataAndExport<TestData1>(path);
3.生成excel
var data = new List<TestData1>();
data.Add(new TestData1() { Code = "123", Name = "测试" });
data.Add(new TestData1() { Code = "123", Name = "测试" });
var bytes = data.Export();
其他配置
- 自定义数据转换
DataConvertAttribute
/// <summary>
/// decimal类型转换
/// </summary>
public class DecimalDataConvertAttribute : DataConvertAttribute
{
public override object ConvertValue(object value)
{
if (value == null)
return value;
return decimal.Parse(value.ToString());
}
}
- 自定义错误提示格式
ExcelRowMessageAttribute
public class MyExcelRowMessageAttribute : ExcelRowMessageAttribute
{
public override string GetMessage(ExcelRowInfo excelRowInfo)
{
return $"读取错误:{JsonConvert.SerializeObject(excelRowInfo)}";
}
}
- 使用示例
[ExcelTemplate]
[MyExcelRowMessage]
public class TestData1
{
/// <summary>
/// 价格
/// </summary>
[ExcelColumn("价格")]
[DecimalDataConvert]
public decimal Price { get; set; }
}
具体用法可参照TestProject
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- NPOI (>= 2.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.