ExcelToData 2.0.1
dotnet add package ExcelToData --version 2.0.1
NuGet\Install-Package ExcelToData -Version 2.0.1
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="ExcelToData" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ExcelToData" Version="2.0.1" />
<PackageReference Include="ExcelToData" />
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 ExcelToData --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ExcelToData, 2.0.1"
#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 ExcelToData@2.0.1
#: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=ExcelToData&version=2.0.1
#tool nuget:?package=ExcelToData&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ExcelToData - Excel数据处理与ORM集成库
一个功能强大的.NET库,专门用于Excel数据处理、ORM实体类生成、CSV导出以及Entity Framework Core集成。
🚀 主要特性
Excel处理
- ✅ Excel文件读取: 支持.xlsx和.xls格式
- ✅ 配置驱动: 通过Excel配置表自动解析数据结构
- ✅ 批量处理: 支持文件夹内多个Excel文件批量处理
- ✅ 数据验证: 内置数据类型验证和格式检查
ORM集成
- ✅ 自动生成实体类: 从Excel数据结构自动生成C#实体类
- ✅ Entity Framework Core支持: 完整的EF Core集成
- ✅ MySQL数据库支持: 专门优化的MySQL连接器
- ✅ 数据库表管理: 自动检查和创建数据库表
数据导出
- ✅ CSV导出: 将ORM实体类反向导出为CSV格式
- ✅ Excel导出: 支持数据库表导出为Excel文件
- ✅ 格式转换: CSV与Excel格式互相转换
安全与性能
- ✅ 安全访问: 内置Excel文件安全访问机制
- ✅ 内存优化: 大文件处理的内存优化
- ✅ 异常处理: 完善的错误处理和日志记录
📦 安装
NuGet包管理器
Install-Package ExcelToData
.NET CLI
dotnet add package ExcelToData
PackageReference
<PackageReference Include="ExcelToData" Version="1.0.7" />
🛠️ 依赖项
- Microsoft.EntityFrameworkCore (9.0.5)
- Pomelo.EntityFrameworkCore.MySql (9.0.0-preview.3)
- ExcelDataReader (3.7.0)
- NPOI (2.7.3)
- Newtonsoft.Json (13.0.3)
- MySqlConnector (2.4.0)
📖 快速开始
1. 从Excel生成ORM实体类
using SaveDataService.Service.Excel;
// 从单个Excel文件生成实体类
string classCode = ExcelToORMIntegration.GenerateORMFromExcelFile(
"path/to/your/excel/file.xlsx",
"config", // 配置工作表名称
"data", // 数据工作表名称
"output" // 输出目录
);
Console.WriteLine("生成的实体类代码:");
Console.WriteLine(classCode);
2. 批量处理Excel文件夹
// 批量处理整个文件夹的Excel文件
var results = ExcelToORMIntegration.BatchProcessExcelFolder(
"path/to/excel/folder",
"output/directory",
"*.xlsx"
);
foreach (var result in results)
{
Console.WriteLine($"类名: {result.Key}");
Console.WriteLine($"代码: {result.Value}");
}
3. 数据库表管理
using ExcelToData.ORM;
// 创建数据库表管理器
var tableManager = new EFCoreTableManage(dbContext);
try
{
// 检查并创建表
bool success = tableManager.EnsureTableExists<YourEntityClass>();
if (success)
{
Console.WriteLine("表创建成功或已存在");
}
// 批量创建多个表
int count = tableManager.EnsureTablesExist(
typeof(Entity1),
typeof(Entity2),
typeof(Entity3)
);
Console.WriteLine($"成功处理 {count} 个表");
}
finally
{
tableManager.Dispose();
}
4. ORM实体类导出为CSV
using ExcelToData.ORM;
// 将实体类结构导出为CSV
string csvPath = ORMEntityToCSV.GenerateEntityCsv(
typeof(YourEntityClass),
"output/directory"
);
Console.WriteLine($"CSV文件已生成: {csvPath}");
5. MySQL模型生成器
using SaveDataService.Service.Excel;
// 从MySQL数据库生成实体类
var generator = new MySqlModelGenerator(connectionString);
generator.Generate(generateExcel: true); // 同时生成Excel文件
📁 项目结构
ExcelToData/
├── Excel/ # Excel处理核心模块
│ ├── ExcelToORMIntegration.cs # Excel到ORM集成
│ ├── ExcelToORMManager.cs # ORM管理器
│ ├── EnhancedExcelToORMExporter.cs # 增强型导出器
│ ├── CSVToExcelConverter.cs # CSV转Excel转换器
│ ├── MySqlModelGenerator.cs # MySQL模型生成器
│ └── SafeExcelAccess.cs # 安全Excel访问
├── ORM/ # ORM相关模块
│ ├── EFCoreTableManage.cs # EF Core表管理
│ ├── ORMEntityToCSV.cs # 实体类转CSV
│ ├── EntityBase.cs # 实体基类
│ └── DBBase.cs # 数据库基类
└── ExcelToData.csproj # 项目文件
🔧 配置说明
Excel配置表格式
Excel文件需要包含一个配置工作表(默认名称"config"),格式如下:
| 配置项 | 值 |
|---|---|
| fileName | 生成的类名 |
| dataTable | 数据工作表名称 |
| tableName | 数据库表名 |
数据工作表格式
数据工作表需要包含以下行:
- 第一行: 字段名称
- 第二行: 数据类型(如:int,string,DateTime等)
- 第三行: 字段描述
- 第四行及以后: 实际数据
🎯 使用场景
- 游戏开发: 配置表数据处理和实体类生成
- 数据迁移: Excel数据导入数据库
- 报表系统: 数据库数据导出为Excel
- 配置管理: 配置文件的Excel化管理
- 数据分析: Excel数据的结构化处理
📝 许可证
本项目采用 MIT 许可证。
🤝 贡献
欢迎提交Issue和Pull Request来帮助改进这个项目。
📞 支持
如果你在使用过程中遇到问题,请:
- 查看项目文档
- 搜索已有的Issues
- 创建新的Issue描述问题
🔄 更新日志
v1.0.7
- 增强Excel数据处理功能
- 优化ORM实体类生成
- 改进错误处理机制
- 添加MySQL数据库支持
注意: 本库主要针对.NET 10.0平台开发,确保你的项目环境支持该版本。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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.
-
net8.0
- ExcelDataReader (>= 3.7.0)
- ExcelDataReader.DataSet (>= 3.7.0)
- Microsoft.EntityFrameworkCore (>= 9.0.5)
- Microsoft.Extensions.Logging.Console (>= 9.0.5)
- MySqlConnector (>= 2.4.0)
- Newtonsoft.Json (>= 13.0.3)
- NPOI (>= 2.7.3)
- Pomelo.EntityFrameworkCore.MySql (>= 9.0.0-preview.3.efcore.9.0.0)
- StackExchange.Redis (>= 2.8.37)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net9.0
- ExcelDataReader (>= 3.7.0)
- ExcelDataReader.DataSet (>= 3.7.0)
- Microsoft.EntityFrameworkCore (>= 9.0.5)
- Microsoft.Extensions.Logging.Console (>= 9.0.5)
- MySqlConnector (>= 2.4.0)
- Newtonsoft.Json (>= 13.0.3)
- NPOI (>= 2.7.3)
- Pomelo.EntityFrameworkCore.MySql (>= 9.0.0-preview.3.efcore.9.0.0)
- StackExchange.Redis (>= 2.8.37)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.