<summary>///export Excel///</summary>//<param name= "lists" ></PARAM&G T <param name= "Head" > English Chinese Column name control </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 headerrow = 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; } }
. NET core Npoi-based Excel export classes that support customizing which fields to export