public void export_all(excel_model sum, List<excel_model> list, string date, string hospital_name, string source_type) { HSSFWorkbook hssfworkbook; using (FileStream file = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "excel/model_all.xls", FileMode.Open, FileAccess.Read)) { hssfworkbook = new HSSFWorkbook(file); } int strat_row = 6; ISheet sheet = hssfworkbook.GetSheet("汇总及清单"); sheet = CreateCell(sheet, list.Count(), 16, strat_row); //日期及医院名称 sheet.GetRow(0).GetCell(0).SetCellValue("日期:" + date); sheet.GetRow(0).GetCell(3).SetCellValue(hospital_name); //汇总表 sheet.GetRow(3).GetCell(0).SetCellValue(sum.record_count); sheet.GetRow(3).GetCell(1).SetCellValue(sum.hospital_days); sheet.GetRow(3).GetCell(2).SetCellValue(sum.akc264); sheet.GetRow(3).GetCell(3).SetCellValue(sum.akc305); sheet.GetRow(3).GetCell(4).SetCellValue(sum.personal_payment); sheet.GetRow(3).GetCell(5).SetCellValue(sum.akc260); sheet.GetRow(3).GetCell(6).SetCellValue(sum.akc253); sheet.GetRow(3).GetCell(7).SetCellValue(sum.swap_amount); sheet.GetRow(3).GetCell(8).SetCellValue(sum.bkc287); //清单表 ICell cell = null; ICellStyle cell_style = SetCellStyle(sheet); for (int i = 0; i < list.Count(); i++) { cell = sheet.GetRow(strat_row + i).GetCell(0); cell.SetCellValue(list[i].akc190); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(1); cell.SetCellValue(list[i].AAC003); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(2); cell.SetCellValue(QueryPersonType(list[i].AAC041.Trim().Length > 0 ? int.Parse(list[i].AAC041) : 0)); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(3); cell.SetCellValue(list[i].AKC192); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(4); cell.SetCellValue(list[i].AKC194); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(5); cell.SetCellValue(list[i].AKC195); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(6); cell.SetCellValue(list[i].AKC198); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(7); cell.SetCellValue(list[i].hospital_days); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(8); cell.SetCellValue(list[i].akc264); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(9); cell.SetCellValue(list[i].akc305); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(10); cell.SetCellValue(list[i].disease_cost_limits); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(11); cell.SetCellValue(list[i].personal_payment); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(12); cell.SetCellValue(list[i].akc260); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(13); cell.SetCellValue(list[i].akc253); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(14); cell.SetCellValue(list[i].akc280); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(15); cell.SetCellValue(list[i].swap_amount); cell.CellStyle = cell_style; cell = sheet.GetRow(strat_row + i).GetCell(16); cell.SetCellValue(list[i].bkc287); cell.CellStyle = cell_style; } ResponseExcel(hssfworkbook, date, hospital_name, source_type); }
public void export_to_excel(string hospital_id, string area_code, string state, DateTime start_time, DateTime end_time, string hospital_name, int source_type) { db_context = new query_entities(); IQueryable<TB0004> source_t04 = null; if (string.IsNullOrEmpty(state)) { source_t04 = db_context.TB0004.Where( t => t.aae040 >= start_time && t.aae040 <= end_time && t.akb020 == hospital_id && t.AKC197 == source_type); } else { source_t04 = db_context.TB0004.Where( t => t.aae040 >= start_time && t.aae040 <= end_time && t.akb020 == hospital_id && t.aae117 == state && t.AKC197 == source_type); } if (!string.IsNullOrEmpty(area_code)) { source_t04 = source_t04.Where(t => t.aab324 == area_code); } var list = (from t04 in source_t04 join t12 in db_context.TB0012 on new {AKB020 = t04.akb020, AKC190 = t04.akc190, AAC001 = t04.aac001} equals new {AKB020 = t12.AKB020, AKC190 = t12.AKC190, AAC001 = t12.AAC001} into _group from g in _group.DefaultIfEmpty() join t01 in db_context.TB0001 on t04.aac001 equals t01.AAC001 select new excel_model { AAC003 = t01.AAC003, AAC041 = t01.AAC041, _AKC192 = g == null ? null : g.AKC192, _AKC194 = g == null ? null : g.AKC194, AKC195 = g == null ? "" : g.AKC195, AKC198 = g == null ? "" : g.AKC198, _hospital_days = t04.akc336, _akc264 = t04.akc264, _akc305 = t04.AKC305, akc190 = t04.akc190, _akc253 = t04.akc253, _akc280 = t04.akc280, disease_cost_limits = "", //病种费用限额 //disease_cost_limits = (t04.akc261 == null ? 0 : t04.akc261) + (t04.akc260 == null ? 0 : t04.akc260) //+ (t04.akc283 == null ? 0 : t04.akc283), //病种费用限额 _personal_payment = (t04.akc264 == null ? 0 : t04.akc264) - (t04.akc260 == null ? 0 : t04.akc260), //个人支付 _akc260 = t04.akc260, swap_amount = "", //调剂金额 _bkc287 = t04.bkc287 }).OrderByDescending(t => t._AKC194).ToList(); if (source_type == 1) { var sum = new excel_model { record_count = source_t04.Count().ToString(), _hospital_days = source_t04.Sum(t => t.akc336), _akc253 = source_t04.Sum(t => t.akc253), _akc264 = list.Sum(t => t._akc264), _akc305 = list.Sum(t => t._akc305), _personal_payment = list.Sum(t => t._personal_payment), _akc260 = list.Sum(t => t._akc260), swap_amount = "", //调剂金额 _bkc287 = list.Sum(t => t._bkc287) }; new ExcelOper().export_all(sum, list, start_time.ToString("yyyy年M月"), hospital_name, source_type.ToString()); }else if (source_type == 0) { new ExcelOper().export_list(list, start_time.ToString("yyyy年M月"), hospital_name, source_type.ToString()); } }