添加excel模块

This commit is contained in:
橙子
2023-01-16 23:05:01 +08:00
parent 46b176fc59
commit 034abb06ad
159 changed files with 328 additions and 97 deletions

View File

@@ -0,0 +1,47 @@
using OEM.Core;
namespace Yi.Framework.Office.Excel
{
public class ExcelManager
{
private IExcelFactory _excelFactory;
public ExcelManager(IExcelFactory excelFactory)
{
_excelFactory = excelFactory;
}
public List<T> ReadListByNameManager<T>(string path, string sheet) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
return excelAppService.ReadListByNameManager<T>(sheet);
}
}
public T ReadByNameManager<T>(string path, string sheet) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
return excelAppService.ReadByNameManager<T>(sheet);
}
}
public void WriteListByNameManager<T>(List<T> objcts, string sheet, string oldPath, string newPath) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(oldPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
excelAppService.WriteListByNameManager(objcts, sheet);
excelAppService.Write(newPath);
}
}
public void WriteByNameManager<T>(T objct, string sheet, string oldPath, string newPath) where T : class, new()
{
using (var excelAppService = _excelFactory.Create(System.IO.File.Open(oldPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
excelAppService.WriteByNameManager(objct, sheet);
excelAppService.Write(newPath);
}
}
}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExcelToObject.Npoi" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Core\Yi.Framework.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Office.Excel
{
public class YiFrameworkOfficeExcelModule : IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.AddExcelToObjectNpoiService();
}
}
}