Use of. net Excel plug-in Npoi for export,. netexcel plug-in npoi
1. Search for Npoi and install NuGet
2. add reference to reference the package
3. Reference in Controller
4. Use
Public ActionResult ExportExcel () {plist = Data Source HSSFWorkbook hssfworkbook = new HSSFWorkbook (); HSSFSheet sheet1 = (HSSFSheet) hssfworkbook. createSheet ("Sheet1"); HSSFRow row = (HSSFRow) sheet1.CreateRow (0); row. createCell (0 ). setCellValue ("name"); row. createCell (1 ). setCellValue ("Serial Number"); row. createCell (2 ). setCellValue ("group"); row. createCell (3 ). setCellValue ("mobile phone number"); row. createCell (4 ). setCellValue ("title"); row. createCell (5 ). setCellValue ("chain"); row. createCell (6 ). setCellValue ("Store"); row. createCell (7 ). setCellValue ("Province"); row. createCell (8 ). setCellValue ("city"); HSSFRow [] rowList = new HSSFRow [plist. count ()]; int I = 0; foreach (var item in plist) {sheet1.SetColumnWidth (I, 30*256); rowList [I] = (HSSFRow) sheet1.CreateRow (I + 1); sheet1.SetColumnWidth (0, 8*256); // set the width of the cell in the first column to 8 characters rowList [I]. createCell (0 ). setCellValue (item. weiXinUser3.Name); rowList [I]. createCell (1 ). setCellValue (item. weiXinUser3.SerialNum. toString (); rowList [I]. createCell (2 ). setCellValue (item. groupName); rowList [I]. createCell (3 ). setCellValue (item. weiXinUser3.MobilePhone); rowList [I]. createCell (4 ). setCellValue (item. weiXinUser3.WorkDuty); rowList [I]. createCell (5 ). setCellValue (item. weiXinUser3.ChainStoreName); rowList [I]. createCell (6 ). setCellValue (item. weiXinUser3.ShopName); rowList [I]. createCell (7 ). setCellValue (item. weiXinUser3.Province. name); rowList [I]. createCell (8 ). setCellValue (item. weiXinUser3.City. name); I ++;} System. IO. memoryStream MS = new System. IO. memoryStream (); hssfworkbook. write (ms); return File (ms. toArray (), "application/ms-excel", area. areaName + "2.16.xls ");}