mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-06 09:40:51 +08:00
添加excel模块
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user