using System; using System.Collections.Generic; using System.Web; using System.Data; using System.Data.Common; using NPOI.SS.UserModel; using NPOI.HSSF.UserModel; using NPOI.HSSF.Util; using System.IO; using NPOI.SS.Util; using Wellan.Data; /// /// 差勤月報表 /// public class 差勤月報表 : ExcelReportBase { public 差勤月報表() { 報表名稱 = "差勤月報表"; } public override MemoryStream 產生報表() { BodyRowHeight = 35; #region 報表抬頭 excel.MergeCell(0, 0, 0, 10); excel.SetCellValue(0, 0, String.Format("{0}\r\n承辦{1}\r\n『{2}』\r\n{3}", 公司名稱, 客戶名稱, 專案名稱, 報表名稱), headerStyle); excel.SetCellValue(1, 0, "月份:", titleStyleRightNoBorder); excel.SetCellValue(1, 1, 報表時間.ToString("MM月"), titleStyleLeftNoBorder); excel.SetCellValue(1, 2, "單位:", titleStyleRightNoBorder); excel.SetCellValue(1, 3, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["單位"]), titleStyleLeftNoBorder); excel.SetCellValue(1, 4, "職稱:", titleStyleRightNoBorder); excel.SetCellValue(1, 5, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["職稱"]), titleStyleLeftNoBorder); excel.SetCellValue(1, 6, "姓名:", titleStyleRightNoBorder); excel.SetCellValue(1, 7, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["姓名"]), titleStyleLeftNoBorder); excel.SetRowHeight(0, HeaderRowHeight * 4); excel.SetRowHeight(1, BodyRowHeight); excel.MergeCell(2, 0, 2, 1); excel.SetRangeOuterBorder(2, 0, 2, 1, BorderStyle.Thin); excel.SetCellValue(2, 0, "日期", titleStyleCenter); excel.SetCellValue(2, 2, "出勤別", titleStyleCenter); excel.SetCellValue(2, 3, "實際上班", titleStyleCenter); excel.SetCellValue(2, 4, "出差外出", titleStyleCenter); excel.SetCellValue(2, 5, "出差返回", titleStyleCenter); excel.SetCellValue(2, 6, "實際下班", titleStyleCenter); excel.SetCellValue(2, 7, "請假", titleStyleCenter); excel.SetCellValue(2, 8, "加班", titleStyleCenter); excel.SetCellValue(2, 9, "公差", titleStyleCenter); excel.SetCellValue(2, 10, "備註", titleStyleCenter); excel.SetRowHeight(2, BodyRowHeight); #endregion #region 報表資料 int rowId = 3; ICellStyle rowStyle; foreach (DataRow r in 資料來源.Tables[0].Rows) { string 請假 = WDAC.GetStringValue(r["請假"]); string 加班 = WDAC.GetStringValue(r["加班"]); string 公差 = WDAC.GetStringValue(r["公差"]); string 出勤別 = WDAC.GetStringValue(r["出勤別"]); if (出勤別 == "上班") rowStyle = titleStyleCenter; else rowStyle = titleStyleCenterYellowBGC; excel.SetCellValue(rowId, 0, WDAC.GetDateTimeValue(r["日期"]).ToString("MM月dd日"), rowStyle); excel.SetCellValue(rowId, 1, WDAC.GetDateTimeValue(r["日期"]).ToString("dddd"), rowStyle); excel.SetCellValue(rowId, 2, 出勤別, rowStyle); excel.SetCellValue(rowId, 3, WDAC.GetStringValue(r["上班"]), rowStyle); excel.SetCellValue(rowId, 4, WDAC.GetStringValue(r["出差外出"]), rowStyle); excel.SetCellValue(rowId, 5, WDAC.GetStringValue(r["出差返回"]), rowStyle); excel.SetCellValue(rowId, 6, WDAC.GetStringValue(r["下班"]), rowStyle); if (請假 != "0:00") excel.SetCellValue(rowId, 7, 請假, rowStyle); else excel.SetCellValue(rowId, 7, "", rowStyle); if (加班 != "0:00") excel.SetCellValue(rowId, 8, 加班, rowStyle); else excel.SetCellValue(rowId, 8, "", rowStyle); if (公差 != "0:00") excel.SetCellValue(rowId, 9, 公差, rowStyle); else excel.SetCellValue(rowId, 9, "", rowStyle); excel.SetCellValue(rowId, 10, string.Format("{0} {1} {2}", r["班別名稱"], r["班別時間"], r["出勤異常"]), rowStyle); excel.SetRowHeight(rowId, BodyRowHeight); rowId++; } #endregion #region 表尾批示 //excel.MergeCell(rowId + 2, 0, rowId + 2, 8); //excel.SetCellValue(rowId + 2, 0, "申請人:             計畫督導:             人事單位:", titleStyleLeftNoBorder); //excel.SetRowHeight(rowId + 2, BodyRowHeight); #endregion excel.SetColumnWidth(0, 11); excel.SetColumnWidth(1, 11); excel.SetColumnWidth(2, 10); excel.SetColumnWidth(3, 15); excel.SetColumnWidth(4, 15); excel.SetColumnWidth(5, 15); excel.SetColumnWidth(6, 15); excel.SetColumnWidth(7, 15); excel.SetColumnWidth(8, 15); excel.SetColumnWidth(9, 15); excel.SetColumnWidth(10, 15); MemoryStream ms = new MemoryStream(); workbook.Write(ms); return ms; } }