# ExcelImportKit
**Repository Path**: frankwei/ExcelImportKit
## Basic Information
- **Project Name**: ExcelImportKit
- **Description**: 导入excel的类库。使用xml映射C#类和导入模板,可以很轻松地应对模板的修改。
- **Primary Language**: C#
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 1
- **Created**: 2020-08-04
- **Last Updated**: 2021-11-29
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ExcelImportKit
import excel data(.xlsx file) with epplus by an easy way
## Overview
### Support
.Net Framework 4.5+
### Get Started
1. add *ErrorMessage.cfg.xml* and *ExcelImport.cfg.xml* to *Configs* folder under root directory of project
2. map importing class fields to *ExcelImport.cfg.xml*
C# class, import class should inherit *ImportEntityBase*
```C#
public class SampleImport : ImportEntityBase
{
public SampleImport()
{ }
public int Age { get; set; }
public string Name { get; set; }
public DateTime Birthday { get; set; }
public float Height { get; set; }
public decimal Money { get; set; }
public bool Gender { get; set; }
public string GenderName => Gender ? "Male" : "Female";
///
/// 1: Student 2: Staff 3: Soldier
///
public int State { get; set; }
public string StateName { get { return State == 1 ? "Student" : State == 2 ? "Staff" : State == 3 ? "Soldier" : "not set"; } }
}
```
cfg.xml
```xml
```
node name "Sample" can be any word you like, and all can put multi nodes in cfg file.
3. use it as simple as sample below:
```C#
IList errors = new List();
IList importList;
var filePath = RootDirectoryHelper.GetFilePath("./Excels/sampleImport.xlsx");
var cfgNodeName = "Sample";
using (var fs = new FileStream(filePath, FileMode.Open))
{
importList = new ExcelImportService().GetParsedPositionImport(fs, errors, cfgNodeName);
}
```
4. *ErrorMessage.cfg.xml* contains general errors in it. you can custom them of course.