65 Star 326 Fork 83

magicodes / Magicodes.IE

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
Sync branch
Notice: Creating folder will generate an empty file .keep, because not support in Git

Magicodes.IE | 简体中文

Member project of .NET Core Community nuget Build Status stats License

Stargazers over time

Azure DevOps tests (master) Azure DevOps coverage (branch) Financial Contributors on Open Collective


Import and export general library, support Dto import and export, template export, fancy export and dynamic export, support Excel, Csv, Word, Pdf and Html.

General description

Azure DevOps

  • Build Status:Build Status
  • Azure DevOps coverage (master): Azure DevOps coverage (branch)
  • Azure DevOps tests (master): Azure DevOps tests (master)

For details, see: https://dev.azure.com/xinlaiopencode/Magicodes.IE/_build?definitionId=4&_a=summary


Stable version (recommended)

Name NuGet
Magicodes.IE.Core NuGet
Magicodes.IE.Excel NuGet
Magicodes.IE.Excel.NPOI NuGet
Magicodes.IE.Excel.AspNetCore NuGet
Magicodes.IE.Pdf NuGet
Magicodes.IE.Word NuGet
Magicodes.IE.Html NuGet
Magicodes.IE.Csv NuGet
Magicodes.IE.AspNetCore NuGet
Magicodes.IE.EPPlus NuGet
Magicodes.IE.Excel.Abp NuGet
Magicodes.IE.Csv.Abp NuGet
Magicodes.IE.Html.Abp NuGet
Magicodes.IE.Pdf.Abp NuGet
Magicodes.IE.Word.Abp NuGet
Magicodes.IE.Stash NuGet


  • Excel import does not support ".xls" files, that is, Excel97-2003 is not supported.
  • For use in Docker, please refer to the section "Use in Docker" in the documentation.
  • Relevant functions have been compiled with unit tests. You can refer to unit tests during the use process.


  1. Basic tutorial of importing student data
  2. Basic tutorial of export Excel
  3. Basic tutorial of export Pdf receipts
  4. Use in Docker
  5. Dynamic Export
  6. Import Multi-Sheet Tutorial
  7. Import and export Excel as pictures
  8. Excel template export-Export textbook order form
  9. Excel Merge Row Cells Import
  10. Exporting multiple formats in NETCore via request headers
  11. Performance Measurement
  12. Excel Merge Row Cells Import
  13. Excel template export - dynamic export

See below for other tutorials or unit tests

See below for update history.


  • Need to be used in conjunction with related import and export DTO models, support import and export through DTO and related characteristics. Configure features to control related logic and display results without modifying the logic code;
  • Support various filters to support scenarios such as multi-language, dynamic control column display, etc. For specific usage, see unit test:
    • Import column header filter (you can dynamically specify the imported column and imported value mapping relationship)
    • Export column header filter (can dynamically control the export column, support dynamic export (DataTable))
    • Export column headers filter (can dynamically control the export column, support dynamic export (DataTable))
    • Import result filter (can modify annotation file)
  • Export supports text custom filtering or processing;
  • Import supports automatic skipping of blank lines in the middle;
  • Import supports automatically generate import templates based on DTO, and automatically mark required items;
  • Import supports data drop-down selection, currently only supports enumerated types;
  • Imported data supports the processing of leading and trailing spaces and intermediate spaces, allowing specific columns to be set;
  • Import supports automatic template checking, automatic data verification, unified exception handling, and unified error encapsulation, including exceptions, template errors and row data errors;
  • Support import header position setting, the default is 1;
  • Support import columns out of order, no need to correspond one to one in order;
  • Support to import the specified column index, automatic recognition by default;
  • Exporting Excel supports splitting of Sheets, only need to set the value of [MaxRowNumberOnASheet] of the characteristic [ExporterAttribute]. If it is 0, no splitting is required. See unit test for details;
  • Support importing into Excel for error marking;
  • Import supports cutoff column setting, if not set, blank cutoff will be encountered by default;
  • Support exporting HTML, Word, Pdf, support custom export template; -Export HTML -Export Word -Export Pdf, support settings, see the update log for details -Export receipt
  • Import supports repeated verification;
  • Support single data template export, often used to export receipts, credentials and other businesses
  • *Support dynamic column export (based on DataTable), and the Sheet will be split automatically if it exceeds 100W. (Thanks to teacher Zhang Shanyou (https://github.com/xin-lai/Magicodes.IE/pull/8 )) *
  • Support dynamic/ExpandoObject dynamic column export
        [Fact(DisplayName = "DTO export supports dynamic types")]
        public async Task ExportAsByteArraySupportDynamicType_Test()
            IExporter exporter = new ExcelExporter();

            var filePath = GetTestFilePath($"{nameof(ExportAsByteArraySupportDynamicType_Test)}.xlsx");


            var source = GenFu.GenFu.ListOf<ExportTestDataWithAttrs>();
            string fields = "text,number,name";
            var shapedData = source.ShapeData(fields) as ICollection<ExpandoObject>;

            var result = await exporter.ExportAsByteArray<ExpandoObject>(shapedData);
            File.WriteAllBytes(filePath, result);
  • **Support value mapping, support setting value mapping relationship through "ValueMappingAttribute" feature. It is used to generate data validation constraints for import templates and perform data conversion. **
        /// <summary>
        /// Gender
        /// </summary>
        [ImporterHeader(Name = "Gender")]
        [Required(ErrorMessage = "Gender cannot be empty.")]
        [ValueMapping(text: "Male", 0)]
        [ValueMapping(text: "Female", 1)]
        public Genders Gender { get; set; }
  • Support the generation of imported data verification items of enumeration and Bool type, and related data conversion

    • Enumeration will automatically obtain the description, display name, name and value of the enumeration by default to generate data items

       	/// <summary>
       	/// Student Status
       	/// </summary>
       	public enum StudentStatus
       		/// <summary>
       		/// Normal
       		/// </summary>
       		[Display(Name = "正常")]
       		Normal = 0,
       		/// <summary>
       		/// Pupils away
       		/// </summary>
       		PupilsAway = 1,
       		/// <summary>
       		/// Suspension
       		/// </summary>
       		[Display(Name = "休学")]
       		Suspension = 2,
       		/// <summary>
       		/// Work-study
       		/// </summary>
       		[Display(Name = "勤工俭学")]
       		WorkStudy = 3,
       		/// <summary>
       		/// Internships
       		/// </summary>
       		[Display(Name = "顶岗实习")]
       		PostPractice = 4,
       		/// <summary>
       		/// Graduate
       		/// </summary>
       		[Display(Name = "毕业")]
       		Graduation = 5,
       		/// <summary>
       		/// Join the army
       		/// </summary>
       		[Display(Name = "参军")]
       		JoinTheArmy = 6,

    • The bool type will generate "yes" and "no" data items by default

    • If custom value mapping has been set, no default options will be generated

  • Support excel multi-sheet import

  • Support Excel template export, and support image rendering

    The rendering syntax is as follows:

      {{Company}}  //Cell rendering
      {{Table>>BookInfos|RowNo}} //Table rendering start syntax
      {{Remark|>>Table}}//Table rendering end syntax
      {{Image::ImageUrl?Width=50&Height=120&Alt=404}} //Picture rendering
      {{Image::ImageUrl?w=50&h=120&Alt=404}} //Picture rendering
      {{Image::ImageUrl?Alt=404}} //Picture rendering

    Custom pipelines will be supported in the future.

  • Support Excel import template to generate annotation

  • Support Excel image import and export

    • Picture import
      • Import as Base64
      • Import to temporary directory
      • Import to the specified directory
    • Picture export
    • Export file path as picture
    • Export network path as picture
  • Support multiple entities to export multiple Sheets

  • Support using some features under the System.ComponentModel.DataAnnotations namespace to control import and export #63

  • Support the use of custom formatter in ASP.NET Core Web API to export content such as Excel, Pdf, Csv #64

  • Support export by column, sheet, and additional rows


For details, see the above tutorial "Magicodes.IE Fancy Export"

  • Support cell export width setting
[ExporterHeader(Width = 100)]
public DateTime Time3 { get; set; }
  • **Excel export supports HeaderRowIndex. Add the HeaderRowIndex attribute to the ExcelExporterAttribute export attribute class, so that it is convenient to specify the export from the first row when exporting. **

  • Excel generated import template supports built-in data verification

The support for the built-in data validation can be turned on through the IsInterValidation attribute, and it should be noted that only MaxLengthAttribute, MinLengthAttribute, StringLengthAttribute, and RangeAttribute support the opening operation of the built-in data validation.

Support display operations for input prompts:

  • Excel import supports merging row data #239


  • Add packaging for Abp module, see #318 for details.


Question List

Update history

Update history


Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]



Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

MIT License Copyright (c) 2019 李文强 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.


导入导出通用库,支持Dto导入导出以及动态导出,支持Excel、Word、Pdf和Html。 本库不维护。提Issue、PR请访问:https://github.com/dotnetcore/Magicodes.IE expand collapse
C# and 2 more languages


No release




Load More
can not load any more


F2647f8d 8189591 Bbdfb06e 8189591