using System; using System.Collections.Generic; using System.Data; using NPOI.SS.UserModel; using System.IO; using Wellan.Data; using Wellan.Common; /// /// 薪資清冊 的摘要描述 /// public class 薪資清冊 : ExcelReportBase { public 薪資清冊() { } protected override void Init() { base.Init(); titleStyleCenterNoBorder.SetFont(bodyFont); bodyStyleCenterNoBorder.SetFont(bodyFont); bodyNumberStyleNoBorder.SetFont(bodyFont); titleStyleRightNoBorder.SetFont(bodyFont); titleStyleLeftNoBorder.SetFont(bodyFont); } public override MemoryStream 產生報表() { #region 報表抬頭 var row = 0; excel.MergeCell(row, 0, row, 20, BorderStyle.None); excel.SetCellValue(row, 0, 公司名稱, headerStyle); excel.SetRowHeight(row, 20); row++; excel.MergeCell(row, 0, row, 20, BorderStyle.None); excel.SetCellValue(row, 0, string.Format("承辦{0}", 客戶名稱), headerStyle); excel.SetRowHeight(row, 20); row++; excel.MergeCell(row, 0, row, 20, BorderStyle.None); excel.SetCellValue(row, 0, string.Format("『{0}』", 專案名稱.Trim()), headerStyle); excel.SetRowHeight(row, 20); row++; excel.MergeCell(row, 0, row, 20, BorderStyle.None); excel.SetCellValue(row, 0, string.Format("{0}【{1}{2}】", 報表名稱, 年度, 月份), headerStyle); excel.SetRowHeight(row, 20); row++; excel.SetCellValue(row, 0, "序號", titleStyleCenterNoBorder); excel.SetCellValue(row, 1, "站別", titleStyleCenterNoBorder); excel.SetCellValue(row, 2, "職務", titleStyleCenterNoBorder); excel.SetCellValue(row, 3, "姓名", titleStyleCenterNoBorder); excel.SetCellValue(row, 4, "到職日", titleStyleCenterNoBorder); excel.SetCellValue(row, 5, "派遣開始日", titleStyleCenterNoBorder); excel.SetCellValue(row, 6, "核定薪資", titleStyleCenterNoBorder); excel.SetCellValue(row, 7, "本薪", titleStyleCenterNoBorder); excel.SetCellValue(row, 8, "其他津貼", titleStyleCenterNoBorder); excel.SetCellValue(row, 9, "事假", titleStyleCenterNoBorder); excel.SetCellValue(row, 10, "病假", titleStyleCenterNoBorder); excel.SetCellValue(row, 11, "其他假別(一)", titleStyleCenterNoBorder); excel.SetCellValue(row, 12, "應領薪資", titleStyleCenterNoBorder); excel.SetCellValue(row, 13, "加班費", titleStyleCenterNoBorder); excel.SetCellValue(row, 14, "外勤工作費", titleStyleCenterNoBorder); excel.SetCellValue(row, 15, "勞保", titleStyleCenterNoBorder); excel.SetCellValue(row, 16, "健保", titleStyleCenterNoBorder); excel.SetCellValue(row, 17, "福利金", titleStyleCenterNoBorder); excel.SetCellValue(row, 18, "個人提繳勞退金", titleStyleCenterNoBorder); excel.SetCellValue(row, 19, "其他加扣款", titleStyleCenterNoBorder); excel.SetCellValue(row, 20, "實領薪資", titleStyleCenterNoBorder); excel.SetRowHeight(row, 26); row++; #endregion #region 報表資料 int beginRow = row; int serial = 1; foreach (DataRow r in 資料來源.Tables[0].Rows) { var 月薪 = WDAC.GetInt32Value(r["SSP00"]) + WDAC.GetInt32Value(r["SSP02"]); var 應領薪資 = 月薪 + WDAC.GetInt32Value(r["SSP01"]) + WDAC.GetInt32Value(r["SSP03"]) + WDAC.GetInt32Value(r["SSP04"]) + WDAC.GetInt32Value(r["SSP05"]) - WDAC.GetInt32Value(r["SSS01"]) - WDAC.GetInt32Value(r["SSS02"]) - WDAC.GetInt32Value(r["SSS09"]); var 加班費 = WDAC.GetInt32Value(r["SSP06"]) + WDAC.GetInt32Value(r["SSP07"]) + WDAC.GetInt32Value(r["SSP08"]) + WDAC.GetInt32Value(r["SSP13"]) + WDAC.GetInt32Value(r["SSP14"]); var 外勤工作費 = WDAC.GetInt32Value(r["SSP09"]) + WDAC.GetInt32Value(r["SSP10"]) + WDAC.GetInt32Value(r["SSP12"]); var 其他加扣 = WDAC.GetInt32Value(r["SSP99"]) - WDAC.GetInt32Value(r["SSS99"]); var 實領薪資 = 應領薪資 + 外勤工作費 + 加班費 + WDAC.GetInt32Value(r["SSP11"]) - WDAC.GetInt32Value(r["SSS04"]) - WDAC.GetInt32Value(r["SSS05"]) - WDAC.GetInt32Value(r["SSS06"]) - WDAC.GetInt32Value(r["SSS07"]) + 其他加扣; excel.SetCellValue(row, 0, serial, bodyStyleCenterNoBorder); excel.SetCellValue(row, 1, WDAC.GetStringValue(r["SSBRHX"]), bodyStyleCenterNoBorder); excel.SetCellValue(row, 2, WDAC.GetStringValue(r["BPJME"]), bodyStyleCenterNoBorder); excel.SetCellValue(row, 3, WDAC.GetStringValue(r["BPNME"]), bodyStyleCenterNoBorder); excel.SetCellValue(row, 4, string.Format("{0:yyyy/MM/dd}", r["BPSDY"], WGuard1.TaiwanCulture), bodyStyleCenterNoBorder); excel.SetCellValue(row, 5, string.Format("{0:yyyy/MM/dd}", r["RASDT"], WGuard1.TaiwanCulture), bodyStyleCenterNoBorder); excel.SetCellValue(row, 6, WDAC.GetInt32Value(r["BPSRM"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 7, 月薪, bodyNumberStyleNoBorder); excel.SetCellValue(row, 8, WDAC.GetInt32Value(r["SSP05"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 9, WDAC.GetInt32Value(r["SSS02"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 10, WDAC.GetInt32Value(r["SSS01"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 11, WDAC.GetInt32Value(r["SSS09"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 12, 應領薪資, bodyNumberStyleNoBorder); excel.SetCellValue(row, 13, 加班費, bodyNumberStyleNoBorder); excel.SetCellValue(row, 14, 外勤工作費, bodyNumberStyleNoBorder); excel.SetCellValue(row, 15, WDAC.GetInt32Value(r["SSS04"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 16, WDAC.GetInt32Value(r["SSS05"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 17, WDAC.GetInt32Value(r["SSS07"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 18, WDAC.GetInt32Value(r["SSS06"]), bodyNumberStyleNoBorder); excel.SetCellValue(row, 19, 其他加扣, bodyNumberStyleNoBorder); excel.SetCellValue(row, 20, 實領薪資, bodyNumberStyleNoBorder); row++; serial++; } #endregion #region 合計及表尾批示 excel.MergeCell(row, 0, row, 1, BorderStyle.None); excel.SetCellValue(row, 0, "合計", titleStyleLeftNoBorder); excel.SetCellFormula(row, 7, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 7), excel.RCtoA1(row - 1, 7)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 8, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 8), excel.RCtoA1(row - 1, 8)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 9, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 9), excel.RCtoA1(row - 1, 9)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 10, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 10), excel.RCtoA1(row - 1, 10)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 11, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 11), excel.RCtoA1(row - 1, 11)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 12, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 12), excel.RCtoA1(row - 1, 12)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 13, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 13), excel.RCtoA1(row - 1, 13)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 14, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 14), excel.RCtoA1(row - 1, 14)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 15, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 15), excel.RCtoA1(row - 1, 15)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 16, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 16), excel.RCtoA1(row - 1, 16)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 17, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 17), excel.RCtoA1(row - 1, 17)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 18, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 18), excel.RCtoA1(row - 1, 18)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 19, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 19), excel.RCtoA1(row - 1, 19)), bodyNumberStyleNoBorder); excel.SetCellFormula(row, 20, String.Format("SUM({0}:{1})", excel.RCtoA1(beginRow, 20), excel.RCtoA1(row - 1, 20)), bodyNumberStyleNoBorder); row++; excel.MergeCell(row, 0, row, 6, BorderStyle.None); excel.SetCellValue(row, 0, "承辦人:", titleStyleLeftNoBorder); excel.MergeCell(row, 7, row, 13, BorderStyle.None); excel.SetCellValue(row, 7, "業務主管:", titleStyleLeftNoBorder); excel.MergeCell(row, 14, row, 20, BorderStyle.None); excel.SetCellValue(row, 14, "公司章:", titleStyleLeftNoBorder); #endregion excel.SetColumnWidth(0, 6); excel.SetColumnWidth(1, 10); excel.SetColumnWidth(2, 14); excel.SetColumnWidth(3, 10); excel.SetColumnWidth(4, 12); excel.SetColumnWidth(5, 12); excel.SetColumnWidth(6, 10); excel.SetColumnWidth(7, 10); excel.SetColumnWidth(8, 10); excel.SetColumnWidth(9, 10); excel.SetColumnWidth(10, 10); excel.SetColumnWidth(11, 10); excel.SetColumnWidth(12, 10); excel.SetColumnWidth(13, 10); excel.SetColumnWidth(14, 10); excel.SetColumnWidth(15, 10); excel.SetColumnWidth(16, 10); excel.SetColumnWidth(17, 10); excel.SetColumnWidth(18, 10); excel.SetColumnWidth(19, 10); excel.SetColumnWidth(20, 10); MemoryStream ms = new MemoryStream(); workbook.Write(ms); return ms; } }