//每月机票明细 private void MonthlyDetail(int Year, int Month, int DepCode) { //read the template via FileStream, it is suggested to use FileAccess.Read to prevent file lock. FileStream file = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Invoice\\Ticket_Monthly_Template.xls", FileMode.Open, FileAccess.Read); HSSFWorkbook hssfworkbook = new HSSFWorkbook(file); HSSFSheet sheet1 = hssfworkbook.GetSheetAt(0); DataTable dt; int[] arrDep = { 21, 22, 23, 24, 25 }; int startRow = 0; if (DepCode == 0) { foreach (int iDep in arrDep) { dt = Ticket.GetTicketReportDetail(Year, Month, iDep); FillExcelMonthly(sheet1, dt, startRow); startRow += dt.Rows.Count + 1; //set break line............. if (dt.Rows.Count > 0) { HSSFCellStyle style = hssfworkbook.CreateCellStyle(); style.FillPattern = HSSFCellStyle.SOLID_FOREGROUND; style.FillForegroundColor = HSSFColor.BRIGHT_GREEN.index; for (int j = 0; j < 10; j++) { sheet1.Items((startRow), j).CellStyle = style; } } } } else { dt = Ticket.GetTicketReportDetail(Year, Month, DepCode); FillExcelMonthly(sheet1, dt, startRow); } //Excel文件在被打开的时候自动将焦点定位在单元格 sheet1.GetRow(0).GetCell(0).SetAsActiveCell(); //Force excel to recalculate all the formula while open sheet1.ForceFormulaRecalculation = true; string FullFileName = AppDomain.CurrentDomain.BaseDirectory + "Upload\\Excel\\Ticket_Monthly_" + Year.ToString() + Month.ToString("00") + ".xls"; file = new FileStream(FullFileName, FileMode.Create); hssfworkbook.Write(file); file.Close(); DownloadFileAsAttachment(FullFileName); }