. Net core is an excel export Class Based on NPOI. It supports customizing which fields to export and corenpoi
/// <Summary> /// export Excel /// </summary> /// <param name = "lists"> </param> /// <param name = "head"> English-Chinese column name </param> // <param name = "workbookFile"> Save path </param> public static void getExcel <T> (List <T> lists, dictionary <string, string> head, string workbookFile) {try {XSSFWorkbook workbook = new XSSFWorkbook (); using (MemoryStream MS = new MemoryStream () {var sheet = workbook. createSheet (); var heade RRow = sheet. createRow (0); bool h = false; int j = 1; Type type = typeof (T); PropertyInfo [] properties = type. getProperties (); foreach (T item in lists) {var dataRow = sheet. createRow (j); int I = 0; foreach (PropertyInfo column in properties) {if (! H) {if (head. Keys. Contains (column. Name) {headerRow. CreateCell (I). SetCellValue (head [column. Name] = null? Column. Name: head [column. Name]. ToString (); dataRow. CreateCell (I). SetCellValue (column. GetValue (item, null) = null? "": Column. getValue (item, null ). toString ();} else {I-= 1 ;}} else {if (head. keys. contains (column. name) {dataRow. createCell (I ). setCellValue (column. getValue (item, null) = null? "": Column. getValue (item, null ). toString () ;}else {I-= 1 ;}} I ++ ;}h = true; j ++ ;} workbook. write (MS); using (FileStream fs = new FileStream (workbookFile, FileMode. create, FileAccess. write) {byte [] data = ms. toArray (); fs. write (data, 0, data. length); fs. flush () ;}sheet = null; headerRow = null; workbook = null ;}} catch (Exception ee) {string see = ee. message ;}}