Introduction to Warship+NPOI Import and Export Components [Objectification]

1. Overview

1) Standard import and export refers to the function of import and export based on standard components, which does not require extended development.At the same time, both import and export are entity-based and can be operated on by Excel through entity operations.

2) Feature introduction

_2.1) ExcelHead: ExcelHead is the cell header corresponding to Excel, which allows you to lock cells inside Excel for property value setting, and lock, hide, header color, column color, column type (text, options, date, amount, etc.) formatting for Excel.

_2.2) Required: Adding the Required attribute is a required check that sets the ErrorMessage prompt when the check fails

_2.3) Length: Add the Length feature to perform a length check, which sets the message ErrorMessage when the check fails

_2.4) Range: Add Range feature to control range and set ErrorMessage as a hint when check fails

_2.5) Format: Add the Format feature, which is the input format of the restriction field, to set the prompt message ErrorMessage when the check fails. Format check has four built-in standards: Mailbox, Phone, Mobile Phone, ID card. If the built-in is not enough, it can be set by regular, and the overload function of the feature can be used.

3) Introduction to ExcelGlobalDTO

_3.1) ExcelGlobalDTO is Excel-level global information that contains Excel file information, all Sheet start rows, all Sheet start columns, and a collection of Sheet entities

_3.2) Excel GlobalDTO allows you to set Sheet-related settings such as disable Sheet, set active Sheet

4) Introduction to Excel SheetModel

_4.1) Excel SheetModel is Sheet-level information that contains the name of the shell (SheetName), the serial number (SheetIndex), the starting row (StartRowIndex), the starting column (StartColumnIndex), and the description (AreaBlock)

_4.2) After importing Excel, you can get Sheet Head List, Sheet Entity List

_4.3) Set option values for columns within the Sheet to restrict cell entry through ColumnOptions

5) Introduction to ExcelRowModel

_5.1) All import and export DTO objects must inherit the ExcelRowModel, which is a component-level encapsulation

_5.2) ExcelRowModel is an Excel row object that contains all row-related information, such as the row number, the set of cell information for an undefined column in an entity

_5.3) Attributes in ExcelRowModel can be styled (RowStyleSet), Deleted Row settings (IsDeleteRow), and dynamic column settings (SetDynamicColumns) through entities

_5.3) When a component is invoked for import, the in-line cell validation fails information can be obtained from ColumnErrorMessage in ExcelRowModel. Exception information can also be appended to ColumnErrorMessage based on business checks outside of the component, which will be annotated on the cell when exported.

_5.4) All validation failures for Excel can also be obtained from GetColumnErrorMessages of Excel GlobalDTO.

Code examples

Code Samples

/// <summary>
///Contract
/// </summary>
[Serializable]
public class ContractImportDTO : ExcelRowModel
{

    /// <summary>
    ///Contract Name
    /// </summary>
    [ExcelHead("Contract Name", IsLocked = false, IsHiddenColumn = false, ColumnWidth = 8)]
    [Required(ErrorMessage = "Contract Name Required")]
    [Length(100, ErrorMessage = "Length cannot exceed 100")]
    public string Name { get; set; }

    /// <summary>
    ///Contract Code
    /// </summary>
    [ExcelHead("Contract Code", IsLocked = false, IsHiddenColumn = false, ColumnWidth = 8)]
    [Required(ErrorMessage = "Contract Name Required")]
    [Length(100, ErrorMessage = "Length cannot exceed 100")]
    public string Code { get; set; }

    /// <summary>
    ///Contract Code
    /// </summary>
    [ExcelHead("Party A unit", IsLocked = false, IsHiddenColumn = false, ColumnWidth = 8)]
    [Required(ErrorMessage = "Contract Name Required")]
    [Length(100, ErrorMessage = "Length cannot exceed 100")]
    public string JfProvider { get; set; }

    /// <summary>
    ///Contract Code
    /// </summary>
    [ExcelHead("Party B Unit", IsLocked = false, IsHiddenColumn = false, ColumnWidth = 8)]
    [Required(ErrorMessage = "Contract Name Required")]
    [Length(100, ErrorMessage = "Length cannot exceed 100")]
    public string YfProvider { get; set; }

    /// <summary>
    ///Contract Code
    /// </summary>
    [ExcelHead("Contract Amount", IsLocked = false, IsHiddenColumn = false, ColumnWidth = 8)]
    [Range(0, 999999999, ErrorMessage = "Out of range")]
    public decimal? Amount { get; set; }
    
    [ExcelHead("mailbox")]
    [Format(FormatEnum.Email,ErrorMessage ="Format error")]
    public string Email { get; set; }
}

public class Standard Import Export
{
    public void Execute()
    {
        string excelPath = Directory.GetCurrentDirectory() + "\\..\\Template\\Dynamic Add Feature Enable Disable.xlsx";

        //Import
        Import<Mysoft.Clgyl.Demo.DemoDTO.ContractImportDTO> import = new Import<Mysoft.Clgyl.Demo.DemoDTO.ContractImportDTO>(1);
        import.Execute(excelPath);

        Export<Mysoft.Clgyl.Demo.DemoDTO.ContractImportDTO> export = new Export<Mysoft.Clgyl.Demo.DemoDTO.ContractImportDTO>();
        export.ExportMemoryStream(import.ExcelGlobalDTO);
    }
}                                                
Published an original article with 0 reviews and 0 visits
Private letter follow

Tags: Excel Attribute Mobile shell

Posted on Fri, 10 Jan 2020 18:55:29 -0800 by matt_4013