Giter Site home page Giter Site logo

magicodes.exporterandimporter's Introduction

Magicodes.ExporterAndImporter

导入导出通用库

特点

  • 封装导入导出业务,目前仅支持Excel,后续将支持CSV以及其他业务
  • 配置特性即可控制相关逻辑和显示结果,无需修改逻辑代码
  • 推荐配合DTO使用
  • 导出支持列头自定义处理以便支持多语言等场景
  • 导出支持文本自定义过滤或处理
  • 导入支持验证逻辑(即将支持)
  • 导入支持自定义过滤或处理(即将支持)
  • 导入支持自动根据DTO生成导入模板(即将支持)

导出Demo

Demo1

普通导出

public class ExportTestData
{
    public string Name1 { get; set; }
    public string Name2 { get; set; }
    public string Name3 { get; set; }
    public string Name4 { get; set; }
}

var result = await Exporter.Export(filePath, new List<ExportTestData>()
{
    new ExportTestData()
    {
        Name1 = "1",
        Name2 = "test",
        Name3 = "12",
        Name4 = "11",
    },
    new ExportTestData()
    {
        Name1 = "1",
        Name2 = "test",
        Name3 = "12",
        Name4 = "11",
    }
});

Demo2

特性导出

[ExcelExporter(Name = "测试", TableStyle = "Light10")]
public class ExportTestDataWithAttrs
{
    [ExporterHeader(DisplayName = "加粗文本", IsBold = true)]
    public string Text { get; set; }

    [ExporterHeader(DisplayName = "普通文本")]
    public string Text2 { get; set; }

    [ExporterHeader(DisplayName = "忽略", IsIgnore = true)]
    public string Text3 { get; set; }

    [ExporterHeader(DisplayName = "数值", Format = "#,##0")]
    public double Number { get; set; }

    [ExporterHeader(DisplayName = "名称", IsAutoFit = true)]
    public string Name { get; set; }
}
        var result = await Exporter.Export(filePath, new List<ExportTestDataWithAttrs>()
        {
            new ExportTestDataWithAttrs()
            {
                Text = "啊实打实大苏打撒",
                Name="aa",
                Number =5000,
                Text2 = "w萨达萨达萨达撒",
                Text3 = "sadsad打发打发士大夫的"
            },
           new ExportTestDataWithAttrs()
            {
                Text = "啊实打实大苏打撒",
                Name="啊实打实大苏打撒",
                Number =6000,
                Text2 = "w萨达萨达萨达撒",
                Text3 = "sadsad打发打发士大夫的"
            },
           new ExportTestDataWithAttrs()
            {
                Text = "啊实打实速度大苏打撒",
                Name="萨达萨达",
                Number =6000,
                Text2 = "突然他也让他人",
                Text3 = "sadsad打发打发士大夫的"
            },
        });

Demo3

列头处理或者多语言支持

[ExcelExporter(Name = "测试", TableStyle = "Light10")]
public class AttrsLocalizationTestData
{
    [ExporterHeader(DisplayName = "加粗文本", IsBold = true)]
    public string Text { get; set; }

    [ExporterHeader(DisplayName = "普通文本")]
    public string Text2 { get; set; }

    [ExporterHeader(DisplayName = "忽略", IsIgnore = true)]
    public string Text3 { get; set; }

    [ExporterHeader(DisplayName = "数值", Format = "#,##0")]
    public double Number { get; set; }

    [ExporterHeader(DisplayName = "名称", IsAutoFit = true)]
    public string Name { get; set; }
}
        ExcelBuilder.Create().WithLocalStringFunc((key) =>
        {
            if (key.Contains("文本"))
            {
                return "Text";
            }
            return "未知语言";
        }).Build();

        var filePath = Path.Combine(Directory.GetCurrentDirectory(), "testAttrsLocalization.xlsx");
        if (File.Exists(filePath)) File.Delete(filePath);

        var result = await Exporter.Export(filePath, new List<AttrsLocalizationTestData>()
        {
            new AttrsLocalizationTestData()
            {
                Text = "啊实打实大苏打撒",
                Name="aa",
                Number =5000,
                Text2 = "w萨达萨达萨达撒",
                Text3 = "sadsad打发打发士大夫的"
            },
           new AttrsLocalizationTestData()
            {
                Text = "啊实打实大苏打撒",
                Name="啊实打实大苏打撒",
                Number =6000,
                Text2 = "w萨达萨达萨达撒",
                Text3 = "sadsad打发打发士大夫的"
            },
           new AttrsLocalizationTestData()
            {
                Text = "啊实打实速度大苏打撒",
                Name="萨达萨达",
                Number =6000,
                Text2 = "突然他也让他人",
                Text3 = "sadsad打发打发士大夫的"
            },
        });

magicodes.exporterandimporter's People

Contributors

codelove1314 avatar xl-wenqiang avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.