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, 9); excel.SetCellValue(0, 0, String.Format("{0}\r\n承辦{1}\r\n『{2}』\r\n{3}", 公司名稱, 客戶名稱, 專案名稱, 報表名稱), headerStyle); excel.SetCellValue(1, 0, "月份:", titleStyleRightNoBorder); excel.MergeCell(1, 1, 1, 2); excel.SetCellValue(1, 1, 報表時間.ToString("MM月"), titleStyleLeftNoBorder); excel.SetCellValue(1, 3, "單位:", titleStyleRightNoBorder); excel.SetCellValue(1, 4, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["站別"]), titleStyleLeftNoBorder); excel.SetCellValue(1, 5, "職稱:", titleStyleRightNoBorder); excel.SetCellValue(1, 6, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["職稱"]), titleStyleLeftNoBorder); excel.SetCellValue(1, 7, "姓名:", titleStyleRightNoBorder); excel.SetCellValue(1, 8, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["BPNME"]), titleStyleLeftNoBorder); excel.SetRowHeight(0, HeaderRowHeight * 4); excel.SetRowHeight(1, BodyRowHeight); excel.MergeCell(2, 0, 2, 2); excel.SetRangeOuterBorder(2, 0, 2, 2, BorderStyle.Thin); excel.SetCellValue(2, 0, "公差日期", 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.SetRowHeight(2, BodyRowHeight); #endregion #region 報表資料 int rowId = 3; foreach (DataRow r in 資料來源.Tables[0].Rows) { excel.SetCellValue(rowId, 0, WDAC.GetDateTimeValue(r["RPRDT"]).ToString("MM月dd日"), titleStyleCenter); excel.SetCellValue(rowId, 1, "~", titleStyleCenter); excel.SetCellValue(rowId, 2, WDAC.GetDateTimeValue(r["RPEDT"]).ToString("MM月dd日"), titleStyleCenter); excel.SetCellValue(rowId, 3, WDAC.GetStringValue(r["類別"]), titleStyleCenter); excel.SetCellValue(rowId, 4, WDAC.GetStringValue(r["RPRTM"]), titleStyleCenter); excel.SetCellValue(rowId, 5, WDAC.GetStringValue(r["RPETM"]), titleStyleCenter); excel.SetCellValue(rowId, 6, MinuteToTime(WDAC.GetInt32Value(r["RPTCT"])), titleStyleCenter); excel.SetCellValue(rowId, 7, WDAC.GetStringValue(r["RPPLC"]), titleStyleCenter); excel.SetCellValue(rowId, 8, WDAC.GetStringValue(r["RPRSN"]), bodyStyleCenterS); excel.SetCellValue(rowId, 9, WDAC.GetStringValue(r["RPDOC"]), bodyStyleCenterS); excel.SetRowHeight(rowId, BodyRowHeight); rowId++; } #endregion #region 表尾批示 //excel.MergeCell(rowId + 2, 0, rowId + 2, 9); //excel.SetCellValue(rowId + 2, 0, "申請人:               計畫督導:               人事單位:", titleStyleLeftNoBorder); //excel.SetRowHeight(rowId + 2, BodyRowHeight); //excel.MergeCell(rowId + 1, 1, rowId + 1, 3); //excel.MergeCell(rowId + 2, 1, rowId + 2, 3); //excel.SetCellValue(rowId + 1, 1, "申請人", titleStyleCenter); //excel.SetRangeOuterBorder(rowId + 1, 1, rowId + 1, 3, BorderStyle.Thin); //excel.SetRangeOuterBorder(rowId + 2, 1, rowId + 2, 3, BorderStyle.Thin); //excel.MergeCell(rowId + 1, 4, rowId + 1, 6); //excel.MergeCell(rowId + 2, 4, rowId + 2, 6); //excel.SetCellValue(rowId + 1, 4, "公司計畫督導", titleStyleCenter); //excel.SetRangeOuterBorder(rowId + 1, 4, rowId + 1, 6, BorderStyle.Thin); //excel.SetRangeOuterBorder(rowId + 2, 4, rowId + 2, 6, BorderStyle.Thin); //excel.MergeCell(rowId + 1, 7, rowId + 1, 8); //excel.MergeCell(rowId + 2, 7, rowId + 2, 8); //excel.SetCellValue(rowId + 1, 7, "公司計畫主持人", titleStyleCenter); //excel.SetRangeOuterBorder(rowId + 1, 7, rowId + 1, 8, BorderStyle.Thin); //excel.SetRangeOuterBorder(rowId + 2, 7, rowId + 2, 8, BorderStyle.Thin); //excel.SetRowHeight(rowId + 1, BodyRowHeight); //excel.SetRowHeight(rowId + 2, BodyRowHeight); #endregion excel.SetColumnWidth(0, 11); excel.SetColumnWidth(1, 4); excel.SetColumnWidth(2, 11); excel.SetColumnWidth(3, 11); excel.SetColumnWidth(4, 11); excel.SetColumnWidth(5, 11); excel.SetColumnWidth(6, 12); excel.SetColumnWidth(7, 12); excel.SetColumnWidth(8, 30); excel.SetColumnWidth(9, 15); MemoryStream ms = new MemoryStream(); workbook.Write(ms); return ms; } }