1. Create an object property tag
CellAttribute( displayName, Type hander = DisplayName = Hander = DisplayName { ; Type Hander { ; }
2. Create a common Processing Method
XlsFileHandler <T> T: Dictionary <, CellAttribute> Dictionary <,> XlsFileHandler (_ path = _ cellAttributes = Dictionary <, CellAttribute> _ propDictionary = Dictionary <,> (prop (CellAttribute cellMapper prop. getCustomAttributes (). ofType <CellAttribute> List <T> dataList = List <T> (FileStream stream = IWorkbook workbook = ISheet sheet = workbook. getSheetAt (rows = lastCell = I = IRow headRow = r Ow = (I = headRow = sheet. getRow (lastCell = T t = I ++ T GetData (IWorkbook workbook, IRow headRow, IRow currentRow, T t = (j =; j <lastCell; j ++ displayName = (! _ CellAttributes. ContainsKey (displayName) |! CurrentAttr = propName = ICell currentCell = value = currentCell! =? GetCellValue (workbook, currentCell): (currentAttr. Hander! = SetValue (InvokeHandler (Type type, System. reflection. constructorInfo constructor = (constructor =) ArgumentNullException (mgConstructor = constructor. invoke (System. reflection. methodInfo method = type. getMethod (method. invoke (mgConstructor ,(! File. exists (_ path) FileNotFoundException (HSSFFormulaEvaluator evaluator = value = SetValue (T t, propName, typeName = property. setValue (t, Convert. toInt32 (value), property. setValue (t, Convert. toDateTime (value), property. setValue (t, Convert. toDecimal (value), property. setValue (t, value ,}View Code
3. Create an Execl file ing Class
[CellAttribute( Code { ; [CellAttribute( Name { ; [CellAttribute(, Group { ; [CellAttribute( DateTime AddTime { ; }
4. Specify the Execl file path and export the ing object through common processing methods
filePath = XlsFileHandler<ReadMapper> handler = XlsFileHandler<ReadMapper> List<ReadMapper> readMappers = Assert.AreEqual(readMappers.Count, }