zoukankan      html  css  js  c++  java
  • Asp.net MVC 利用 Nopi 导出 Excel

    /// <summary>
    		/// 导出认账流水
    		/// </summary>
    		/// <returns></returns>
    		public ActionResult ExportAdmitBankTrans(BankTransQueryModel queryModel)
    		{
    			HSSFWorkbook workBook = new HSSFWorkbook();
    			ISheet sheet = workBook.CreateSheet("商务报表"); 
    			IRow row = sheet.CreateRow(0);
    
    			// 获取样式
    			Func<ICellStyle> getCellStyle = () =>
    			{
    				ICellStyle cellStyle = workBook.CreateCellStyle();
    				cellStyle.Alignment = HorizontalAlignment.Center;
    				return cellStyle;
    			};
    
    			ICellStyle headerStyle = getCellStyle();
    			IFont fontHeade = workBook.CreateFont();
    			fontHeade.FontHeightInPoints = 11;
    			fontHeade.FontName = "微软雅黑";
    			fontHeade.Boldweight = (short)FontBoldWeight.Bold;
    			headerStyle.SetFont(fontHeade);
    
    			Func<string, int, ICell> setCellStyle = (string cellText, int colindex) =>
    			{
    				ICell cell = row.CreateCell(colindex);
    				sheet.SetColumnWidth(colindex, 9000);
    				cell.SetCellValue(cellText);
    				cell.CellStyle = headerStyle;
    				return cell;
    			};
    			setCellStyle("供应商名称", 0);
    			setCellStyle("采购编号", 1);
    			setCellStyle("实际到账", 2);
    			setCellStyle("到账日期", 3);
    			int rowStart = 1;
    
    			var list = BankTransBll.Instance.GetAllBankTransRealList(queryModel);
    			if (list != null)
    			{
    				foreach (var item in list)
    				{
    					IRow myrow = sheet.CreateRow(rowStart);
    					myrow.CreateCell(0).SetCellValue(item.CompanyName);
    					myrow.CreateCell(1).SetCellValue(item.ContractNo);
    					myrow.CreateCell(2).SetCellValue(item.Amount.ToString("f2"));
    					myrow.CreateCell(3).SetCellValue(item.REC_CREATETIME.ToShortDateString());
    
    					rowStart++;
    				}
    			}
    
    			using (MemoryStream ms = new MemoryStream())
    			{
    				workBook.Write(ms);
    				byte[] buffers = ms.ToArray();
    
    				return File(buffers, "application/vnd.ms-excel", string.Format("{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmss")));
    
    			}
    		}
    

      

  • 相关阅读:
    Python正课48 —— 匿名函数及其应用
    Python正课47 —— 面向过程编程思想
    Python正课46 —— 二分法
    Python正课45 —— 函数的递归调用
    Python正课44 —— 生成式
    Python正课43 —— 三元表达式
    SQL数据库操作命令大全
    css 高度写死 下滚动时ios 滚动不协调处理
    记录:js删除数组中某一项或几项的几种方法
    本次存储存数组对象
  • 原文地址:https://www.cnblogs.com/AskySun/p/5067509.html
Copyright © 2011-2022 走看看