using System.Collections.Generic; using System.IO; using System.Linq; using NPOI.SS.UserModel; using WebLib; using System.Data; namespace Education.Report { public class 滿意度匯出 : ReportBase { public DataTable 學員Table; public List<訓練課程內容> 課程List; public List<滿意度調查> 課程滿意度List; public List<滿意度調查> 整體滿意度List; public List<心得報告> 心得List; public MemoryStream DoReport() { excel.WorkBook.RemoveSheetAt(0); 課程List.ForEach(c => { var sheetName = $"{c.課程序號}-{c.課程名稱}".Replace(".", "-") .Replace("\\", "-") .Replace("/", "-") .Replace("?", "-") .Replace("*", "-") .Replace("[", "-") .Replace("]", "-"); if (sheetName.Length > 31) sheetName = sheetName.Substring(0, 31); sheet = workbook.CreateSheet(sheetName); excel.Sheet = sheet; var 課堂滿意度List = 課程滿意度List.FindAll(x => x.課程序號 == c.課程序號).ToList(); // 報表抬頭 excel.MergeCell(0, 2, 0, 5); excel.SetCellValue(0, 2, "課程評價", bodyStyleCenter); excel.SetRangeOuterBorder(0, 2, 0, 5, BorderStyle.Thin); excel.MergeCell(0, 6, 0, 9); excel.SetCellValue(0, 6, "其他評價", bodyStyleCenter); excel.SetRangeOuterBorder(0, 6, 0, 9, BorderStyle.Thin); excel.SetCellValue(1, 0, "員工編號", bodyStyleCenter); excel.SetCellValue(1, 1, "學員姓名", bodyStyleCenter); excel.SetCellValue(1, 2, "1.課程的實用性", bodyStyleCenter); excel.SetCellValue(1, 3, "2.講師的授課方式", bodyStyleCenter); excel.SetCellValue(1, 4, "3.講師的專業知識", bodyStyleCenter); excel.SetCellValue(1, 5, "4.課程時數安排", bodyStyleCenter); excel.SetCellValue(1, 6, "1.行政服務品質", bodyStyleCenter); excel.SetCellValue(1, 7, "2.餐點及茶飲", bodyStyleCenter); excel.SetCellValue(1, 8, "3.場地滿意度", bodyStyleCenter); excel.SetCellValue(1, 9, "4.對整體活動表現", bodyStyleCenter); excel.MergeCell(0, 10, 1, 10); excel.SetCellValue(0, 10, "針對未來相關課程,煩請提供建議以做為我們後續課程之規劃", bodyStyleCenter); excel.SetRangeOuterBorder(0, 10, 1, 10, BorderStyle.Thin); excel.MergeCell(0, 11, 1, 11); excel.SetCellValue(0, 11, "上課心得摘要", bodyStyleCenter); excel.SetRangeOuterBorder(0, 11, 1, 11, BorderStyle.Thin); excel.SetRowHeightInPoints(0, BodyRowHeight); excel.SetRowHeightInPoints(1, BodyRowHeight * 3); // 設定各欄寬度 excel.SetColumnWidthInChars(0, 12); excel.SetColumnWidthInChars(1, 12); excel.SetColumnWidthInChars(2, 10); excel.SetColumnWidthInChars(3, 10); excel.SetColumnWidthInChars(4, 10); excel.SetColumnWidthInChars(5, 10); excel.SetColumnWidthInChars(6, 10); excel.SetColumnWidthInChars(7, 10); excel.SetColumnWidthInChars(8, 10); excel.SetColumnWidthInChars(9, 10); excel.SetColumnWidthInChars(10, 50); excel.SetColumnWidthInChars(11, 100); // 報表內容 int row = 2; foreach (DataRow r in 學員Table.Rows) { int col = 0; var 學員編號 = DAC.GetString(r["學員編號"]); var 學員姓名 = DAC.GetString(r["學員姓名"]); var 學員課程滿意度List = 課堂滿意度List.FindAll(x => x.學員編號 == 學員編號) .OrderBy(x => x.題目編號) .ToList(); var 學員整體滿意度List = 整體滿意度List.FindAll(x => x.學員編號 == 學員編號) .OrderBy(x => x.題目編號) .ToList(); var 心得Item = 心得List.FirstOrDefault(x => x.學員編號 == 學員編號); excel.SetCellValue(row, col++, 學員編號, bodyStyleCenter); excel.SetCellValue(row, col++, 學員姓名, bodyStyleCenter); for (var i = 0; i < 4; i++) { excel.SetCellValue(row, col++, 學員課程滿意度List.Count >= i + 1 ? DAC.GetString(學員課程滿意度List[i].分數) : "", bodyStyleCenter); } for (var i = 0; i < 4; i++) { excel.SetCellValue(row, col++, 學員整體滿意度List.Count >= i + 1 ? DAC.GetString(學員整體滿意度List[i].分數) : "", bodyStyleCenter); } excel.SetCellValue(row, col++, DAC.GetString(心得Item?.建議), bodyStyleLeft); excel.SetCellValue(row, col++, DAC.GetString(心得Item?.心得), bodyStyleLeft); row++; } }); MemoryStream ms = new MemoryStream(); workbook.Write(ms); return ms; } } }