2 Star 9 Fork 2

橙子 / ExcelSugar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

一套以用户体验出发的.netstandard2.1 Excel开源工具包

支持查询、导出、模板等常用功能,语法与Sqlsugar类似

Excel快速上手的不二之选

ExcelSugar 介绍

ORM To Excel,像操作对象一样操作Excel,支持查询、导出、模板等常用功能;

使用方式类比于SqlsugarORM,优雅简单,excel快速上手的不二之选;

具备的完整的单元测试,可以在仓库中查看及详细使用;

正在持续迭代中,支持的功能会越来越多~~!

优势

  1. 将Excel当作对象操作,使用简单,1分钟上手
  2. 语法与SqlsugarORM基本类似,两者都可以兼得
  3. 支持where表达式查询
  4. 支持来自模板导出
  5. 支持动态表头功能
  6. 支持单元格存储对象操作
  7. 完善的单元测试,可以查看详细使用操作
  8. 作者24小时在线,可QQ联系:454313500

安装教程

Nuget包管理器直接搜索ExcelSugar.Npoi安装即可(后续可更换实现)

  • ExcelSugar.Core(核心包-自动依赖)
  • ExcelSugar.Npoi(实现包,下载)
  • ExcelSugar.AspNetCore(正在开发)

使用说明

  1. 创建ExcelClient
IExcelSugarClient excelSugarClient = new ExcelSugarClient(new ExcelSugarConfig { Path = "../../../TempExcel/Test.xlsx", HandlerType = ExcelHandlerType.Npoi });
  1. 定义模型,并打上对应的特性
    [SugarSheet("测试表")]
    public class TestModel
    {
        [SugarHead("姓名")]
        public string Name { get; set; }
        [SugarHead("描述")]
        public string Description { get; set; }

        /// <summary>
        /// 导出可支持动态列模型
        /// </summary>
        [SugarDynamicHead]
        public List<DynamicModel> DynamicModels { get; set; } = new List<DynamicModel>();

        [SugarHead("字典列", IsJson = true)]
        public Dictionary<int, string> Dic { get; set; } = new Dictionary<int, string>();

        [SugarHead("对象列", IsJson = true)]

        public ObjectModel ObjectModel { get; set; } = new ObjectModel();
    }
    /// <summary>
    /// 动态表头,需具备IsCode、IsValue、IsName 3个字段
    /// </summary>
    public class DynamicModel
    {
        [SugarDynamicHead(IsCode = true)]
        public string DataCode { get; set; }

        [SugarDynamicHead(IsValue = true)]
        public int DataValue { get; set; }

        [SugarDynamicHead(IsName = true)]
        public string DataName { get; set; }
    }


    public class ObjectModel
    {
        public string Test1 { get; set; }
        public int Test2 { get; set; }
        public List<string> Test3 { get; set; } = new List<string>();
        public List<int> Test4 { get; set; }
    }
  1. 使用client操作即可

//创建实体
var testModel = new List<TestModel> {
                new TestModel { Description = "男的", Name = "张三",
                    Dic=new Dictionary<int, string>{ { 10,"OK"},{20,"NO" } },
                    ObjectModel=new ObjectModel{ Test1="1",Test2=2,Test3=new List<string>{ "1","2","3"},Test4=new List<int>{ 6,7,8,9} },
                    DynamicModels = new List<DynamicModel>{
                        new DynamicModel { DataCode="height",DataName="身高",DataValue=188},
                } },
                new TestModel { Description = "女的", Name = "李四",
                    ObjectModel=new ObjectModel{ Test1="11",Test2=222,Test3=new List<string>{ "11","22","33"},Test4=new List<int>{ 66,77,88,99} },
                    DynamicModels=new List<DynamicModel>{
                        new DynamicModel { DataCode="height",DataName="身高",DataValue=168},
                        new DynamicModel { DataCode="age",DataName="年龄",DataValue=18},
                } }
            };



//从excel中查询出实体
var data = await client.Queryable<TestModel>().ToListAsync();

//从excel中查询出实体,支持where表达式
var data = await client.Queryable<TestModel>().Where(x => x.Name == "张三").ToListAsync();

//将实体直接导出excel
await client.Exportable(testModel).ExecuteCommandAsync();

//将实体根据给定的模板进行导出excel
await client.Exportable(testModel).From("../../../TempExcel/Template.xlsx").ExecuteCommandAsync();
//Or await client.Exportable("../../../Test.xlsx").ExecuteCommandAsync();

效果: 效果

致谢

联系我们

  • 可通过QQ进行联系:454313500
  • 可通过本仓库进行联系
MIT License Copyright (c) 2023 橙子 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🔥爽🔥ORM To Excel,像操作对象一样操作Excel,支持查询、导出、模板等常用功能; 使用方式类比于SqlsugarORM,优雅简单,excel快速上手的不二之选; 具备的完整的单元测试,可以在仓库中查看及详细使用; 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/ccnetcore/excelsugar.git
git@gitee.com:ccnetcore/excelsugar.git
ccnetcore
excelsugar
ExcelSugar
master

搜索帮助