chore: 首次簽入 Thinkyu ASP.NET 專案

- 加入 Visual Studio / ASP.NET .gitignore
- 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
2026-09-10 09:42:37 +08:00
commit 577060bc78
2496 changed files with 501389 additions and 0 deletions
@@ -0,0 +1 @@

@@ -0,0 +1,265 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
private string ;
public string ;
public string ;
public string ;
public string ;
public string ;
public string ;
public DataTable data;
public List<DateTime> List;
//public MemoryStream DoReport()
//{
// int 序號 = 1;
// int 工作表序號 = 1;
// workbook.RemoveSheetAt(0);
// bodyStyleCenter.VerticalAlignment = VerticalAlignment.Justify;
// foreach (DataRow r in data.Rows)
// {
// string data計畫名稱 = DAC.GetString(r["計畫年度名稱"]);
// string data站別名稱 = DAC.GetString(r["站別名稱"]);
// string data職務名稱 = DAC.GetString(r["職務名稱"]);
// string data學員姓名 = DAC.GetString(r["學員姓名"]);
// int 簽到格數 = 訓練日期List.Count * 2 - 1;
// if (簽到格數 < 0)
// 簽到格數 = 0;
// // 是否要換頁
// if (計畫名稱 != data計畫名稱)
// {
// 計畫名稱 = data計畫名稱;
// sheet = workbook.CreateSheet("Sheet" + 工作表序號.ToString()) as HSSFSheet;
// SetPaperAndMargin(sheet);
// sheet.RepeatingRows = new CellRangeAddress(0, 3, -1, -1);
// // workbook.SetRepeatingRowsAndColumns(workbook.GetSheetIndex(sheet), -1, -1, 0, 3);
// excel.Sheet = sheet;
// 工作表序號++;
// // 報表抬頭
// excel.MergeCell(0, 0, 0, 7 + 簽到格數);
// excel.SetCellValue(0, 0, String.Format("{0}\n{1}\n教育訓練簽到表", 公司名稱, 計畫名稱), titleStyleCenter);
// excel.SetRowHeightInPoints(0, HeaderRowHeight * 3);
// excel.MergeCell(1, 0, 1, 7 + 簽到格數);
// excel.SetCellValue(1, 0, String.Format("辦理時間:{0}\n辦理地點:{1}\n訓練名稱:{2}\n講師姓名:{3}\n承辦人員:{4}",
// 訓練日期, 辦理地點, 訓練企劃名稱, 講師姓名, 承辦人員),
// bodyStyleLeft);
// excel.SetRowHeightInPoints(1, BodyRowHeight * 5);
// excel.SetRangeOuterBorder(1, 0, 1, 7 + 簽到格數, BorderStyle.Thin);
// excel.MergeCell(2, 0, 4, 0);
// excel.SetCellValue(2, 0, "序號", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 0, 4, 0, BorderStyle.Thin);
// excel.MergeCell(2, 1, 4, 1);
// excel.SetCellValue(2, 1, "單位", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 1, 4, 1, BorderStyle.Thin);
// excel.MergeCell(2, 2, 4, 2);
// excel.SetCellValue(2, 2, "職務名稱", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 2, 4, 2, BorderStyle.Thin);
// excel.MergeCell(2, 3, 4, 3);
// excel.SetCellValue(2, 3, "姓名", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 3, 4, 3, BorderStyle.Thin);
// excel.MergeCell(2, 4, 2, 4 + 簽到格數);
// excel.SetCellValue(2, 4, "簽到", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 4, 2, 4 + 簽到格數, BorderStyle.Thin);
// for (int i = 0; i < 訓練日期List.Count; i++)
// {
// excel.MergeCell(3, 4 + i * 2, 3, 5 + i * 2);
// excel.SetCellValue(3, 4 + i * 2, 訓練日期List[i].ToString("yyyy-MM-dd"), bodyStyleCenter);
// excel.SetRangeOuterBorder(3, 4 + i * 2, 3, 5 + i * 2, BorderStyle.Thin);
// excel.SetCellValue(4, 4 + i * 2, "上午", bodyStyleCenter);
// excel.SetCellValue(4, 5 + i * 2, "下午", bodyStyleCenter);
// }
// excel.MergeCell(2, 5 + 簽到格數, 3, 6 + 簽到格數);
// excel.SetCellValue(2, 5 + 簽到格數, "用餐別", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 5 + 簽到格數, 3, 6 + 簽到格數, BorderStyle.Thin);
// excel.SetCellValue(4, 5 + 簽到格數, "葷", bodyStyleCenter);
// excel.SetCellValue(4, 6 + 簽到格數, "素", bodyStyleCenter);
// excel.MergeCell(2, 7 + 簽到格數, 4, 7 + 簽到格數);
// excel.SetCellValue(2, 7 + 簽到格數, "備註", bodyStyleCenter);
// excel.SetRangeOuterBorder(2, 7 + 簽到格數, 4, 7 + 簽到格數, BorderStyle.Thin);
// // 設定各欄寬度
// excel.SetColumnWidthInChars(0, 8);
// excel.SetColumnWidthInChars(1, 26);
// excel.SetColumnWidthInChars(2, 16);
// excel.SetColumnWidthInChars(3, 16);
// for (int i = 0; i < 訓練日期List.Count; i++)
// {
// excel.SetColumnWidthInChars(4 + i * 2, 8);
// excel.SetColumnWidthInChars(5 + i * 2, 8);
// }
// excel.SetColumnWidthInChars(5 + 簽到格數, 8);
// excel.SetColumnWidthInChars(6 + 簽到格數, 8);
// excel.SetColumnWidthInChars(7 + 簽到格數, 16);
// excel.SetRowHeightInPoints(2, BodyRowHeight);
// excel.SetRowHeightInPoints(3, BodyRowHeight);
// excel.SetRowHeightInPoints(4, BodyRowHeight);
// 序號 = 1;
// }
// // 報表內容
// excel.SetCellValue(序號 + 4, 0, 序號, bodyStyleCenter);
// excel.SetCellValue(序號 + 4, 1, data站別名稱, bodyStyleCenter);
// excel.SetCellValue(序號 + 4, 2, data職務名稱, bodyStyleCenter);
// excel.SetCellValue(序號 + 4, 3, data學員姓名, bodyStyleCenter);
// for (int i = 0; i < 訓練日期List.Count; i++)
// {
// excel.SetCellValue(序號 + 4, 4 + i * 2, "", bodyStyleCenter);
// excel.SetCellValue(序號 + 4, 5 + i * 2, "", bodyStyleCenter);
// }
// excel.SetCellValue(序號 + 4, 5 + 簽到格數, "", bodyStyleCenter);
// excel.SetCellValue(序號 + 4, 6 + 簽到格數, "", bodyStyleCenter);
// excel.SetCellValue(序號 + 4, 7 + 簽到格數, "", bodyStyleCenter);
// excel.SetRowHeightInPoints(序號 + 4, (int)Math.Truncate(BodyRowHeight * 1.5));
// 序號++;
// }
// MemoryStream ms = new MemoryStream();
// workbook.Write(ms);
// return ms;
//}
public MemoryStream DoReport()
{
int = 1;
int = 1;
workbook.RemoveSheetAt(0);
bodyStyleCenter.VerticalAlignment = VerticalAlignment.Justify;
for (int i = 0; i < List.Count; i++)
{
= null;
foreach (DataRow r in data.Rows)
{
string data計畫名稱 = DAC.GetString(r["計畫年度名稱"]);
string data站別名稱 = DAC.GetString(r["站別名稱"]);
string data職務名稱 = DAC.GetString(r["職務名稱"]);
string data學員姓名 = DAC.GetString(r["學員姓名"]);
// 是否要換頁
if ( != data計畫名稱)
{
= data計畫名稱;
sheet = workbook.CreateSheet("Sheet" + .ToString());
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 3, -1, -1);
// workbook.SetRepeatingRowsAndColumns(workbook.GetSheetIndex(sheet), -1, -1, 0, 3);
excel.Sheet = sheet;
++;
// 報表抬頭
excel.MergeCell(0, 0, 0, 8);
excel.SetCellValue(0, 0, String.Format("{0}\n{1}\n教育訓練簽到表", , ), titleStyleCenter);
excel.SetRowHeightInPoints(0, HeaderRowHeight * 3);
excel.MergeCell(1, 0, 1, 8);
excel.SetCellValue(1, 0, String.Format("辦理時間:{0:yyyy年MM月dd日(dddd)}\n辦理地點:{1}\n訓練名稱:{2}\n講師姓名:{3}\n承辦人員:{4}",
List[i], , , , ),
bodyStyleLeft);
excel.SetRowHeightInPoints(1, BodyRowHeight * 5);
excel.SetRangeOuterBorder(1, 0, 1, 8, BorderStyle.Thin);
excel.MergeCell(2, 0, 3, 0);
excel.SetCellValue(2, 0, "序號", bodyStyleCenter);
excel.SetRangeOuterBorder(2, 0, 3, 0, BorderStyle.Thin);
excel.MergeCell(2, 1, 3, 1);
excel.SetCellValue(2, 1, "單位", bodyStyleCenter);
excel.SetRangeOuterBorder(2, 1, 3, 1, BorderStyle.Thin);
excel.MergeCell(2, 2, 3, 2);
excel.SetCellValue(2, 2, "職務名稱", bodyStyleCenter);
excel.SetRangeOuterBorder(2, 2, 3, 2, BorderStyle.Thin);
excel.MergeCell(2, 3, 3, 3);
excel.SetCellValue(2, 3, "姓名", bodyStyleCenter);
excel.SetRangeOuterBorder(2, 3, 3, 3, BorderStyle.Thin);
excel.MergeCell(2, 4, 2, 5);
excel.SetCellValue(2, 4, List[i].ToString("yyyy-MM-dd"), bodyStyleCenter);
excel.SetRangeOuterBorder(2, 4, 2, 5, BorderStyle.Thin);
excel.SetCellValue(3, 4, "簽到", bodyStyleCenter);
excel.SetCellValue(3, 5, "簽退", bodyStyleCenter);
excel.MergeCell(2, 6, 2, 7);
excel.SetCellValue(2, 6, "用餐別", bodyStyleCenter);
excel.SetRangeOuterBorder(2, 6, 2, 7, BorderStyle.Thin);
excel.SetCellValue(3, 6, "葷", bodyStyleCenter);
excel.SetCellValue(3, 7, "素", bodyStyleCenter);
excel.MergeCell(2, 8, 3, 8);
excel.SetCellValue(2, 8, "備註", bodyStyleCenter);
excel.SetRangeOuterBorder(2, 8, 3, 8, BorderStyle.Thin);
// 設定各欄寬度
excel.SetColumnWidthInChars(0, 8);
excel.SetColumnWidthInChars(1, 26);
excel.SetColumnWidthInChars(2, 16);
excel.SetColumnWidthInChars(3, 16);
excel.SetColumnWidthInChars(4, 16);
excel.SetColumnWidthInChars(5, 16);
excel.SetColumnWidthInChars(6, 8);
excel.SetColumnWidthInChars(7, 8);
excel.SetColumnWidthInChars(8, 16);
excel.SetRowHeightInPoints(2, BodyRowHeight);
excel.SetRowHeightInPoints(3, BodyRowHeight);
= 1;
}
// 報表內容
excel.SetCellValue( + 3, 0, , bodyStyleCenter);
excel.SetCellValue( + 3, 1, data站別名稱, bodyStyleCenter);
excel.SetCellValue( + 3, 2, data職務名稱, bodyStyleCenter);
excel.SetCellValue( + 3, 3, data學員姓名, bodyStyleCenter);
excel.SetCellValue( + 3, 4, "", bodyStyleCenter);
excel.SetCellValue( + 3, 5, "", bodyStyleCenter);
excel.SetCellValue( + 3, 6, "", bodyStyleCenter);
excel.SetCellValue( + 3, 7, "", bodyStyleCenter);
excel.SetCellValue( + 3, 8, "", bodyStyleCenter);
excel.SetRowHeightInPoints( + 3, (int)Math.Truncate(BodyRowHeight * 1.5));
++;
}
}
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,104 @@
using System;
using System.IO;
using System.Data;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public string ;
public int ;
public bool ;
public DataTable data;
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("報表");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 報表抬頭
excel.MergeCell(0, 0, 0, 10);
excel.SetCellValue(0, 0, , titleStyleCenter);
excel.MergeCell(1, 0, 1, 10);
if (!)
excel.SetCellValue(1, 0, String.Format("{0}年度教育訓練課程執行狀況", ), titleStyleCenter);
else
excel.SetCellValue(1, 0, String.Format("{0}年度教育訓練課程狀況", ), titleStyleCenter);
excel.SetRowHeightInPoints(0, HeaderRowHeight);
excel.SetRowHeightInPoints(1, HeaderRowHeight);
// excel.SetRangeOuterBorder(1, 0, 1, 7, BorderStyle.Thin);
excel.SetCellValue(2, 0, "", bodyStyleCenter);
excel.SetCellValue(2, 1, "訓練日期", bodyStyleCenter);
excel.SetCellValue(2, 2, "課程企劃編號名稱", bodyStyleCenter);
excel.SetCellValue(2, 3, "訓練計畫別", bodyStyleCenter);
excel.SetCellValue(2, 4, "訓練時數", bodyStyleCenter);
excel.SetCellValue(2, 5, "訓練場地", bodyStyleCenter);
excel.SetCellValue(2, 6, "訓練人數", bodyStyleCenter);
excel.SetCellValue(2, 7, "預估經費", bodyStyleCenter);
excel.SetCellValue(2, 8, "實際經費", bodyStyleCenter);
excel.SetCellValue(2, 9, "學員出席率", bodyStyleCenter);
excel.SetCellValue(2, 10, "整體滿意度", bodyStyleCenter);
excel.SetColumnWidthInChars(0, 12);
excel.SetColumnWidthInChars(1, 12);
excel.SetColumnWidthInChars(2, 45);
excel.SetColumnWidthInChars(3, 26);
excel.SetColumnWidthInChars(4, 12);
excel.SetColumnWidthInChars(5, 30);
excel.SetColumnWidthInChars(6, 12);
excel.SetColumnWidthInChars(7, 15);
excel.SetColumnWidthInChars(8, 15);
excel.SetColumnWidthInChars(9, 15);
excel.SetColumnWidthInChars(10, 15);
excel.SetRowHeightInPoints(2, (int)Math.Truncate(BodyRowHeight * 2.0));
int rowId = 1;
int beginRow = 3;
foreach (DataRow r in data.Rows)
{
// 報表內容
excel.SetCellValue(rowId + 2, 0, rowId, bodyStyleCenter);
excel.SetCellValue(rowId + 2, 1, .Get訓練日期Str(DAC.GetDateTime(r["訓練日期"]), DAC.GetDateTime(r["訓練日期迄"]), "yyyyMMdd"), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 2, String.Format("[{0:000000}]{1}", r["編號"], r["訓練名稱"]), bodyStyleLeft);
excel.SetCellValue(rowId + 2, 3, DAC.GetString(r["訓練計畫別"]), bodyStyleLeft);
excel.SetCellValue(rowId + 2, 4, DAC.GetInt32(r["訓練時數"]), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 5, DAC.GetString(r["訓練場地"]), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 6, DAC.GetInt32(r["訓練人數"]), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 7, DAC.GetInt32(r["預估經費"]), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 8, DAC.GetInt32(r["實際經費"]), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 9, DAC.GetDouble(r["學員出席率"]), bodyPercentStyle);
excel.SetCellValue(rowId + 2, 10, DAC.GetDouble(r["整體滿意度"]), bodyPercentStyle);
// excel.SetRowHeightInPoints(rowId + 2, (int)Math.Truncate(BodyRowHeight * 1.5));
rowId++;
}
// 報表結尾統計
excel.SetCellValue(rowId + 2, 0, "統計結果", bodyStyleCenter);
excel.SetCellValue(rowId + 2, 1, "", bodyStyleCenter);
excel.SetCellValue(rowId + 2, 2, "", bodyStyleLeft);
excel.SetCellValue(rowId + 2, 3, "", bodyStyleLeft);
excel.SetCellFormula(rowId + 2, 4, String.Format("SUM({0}:{1})", Excel.RCtoA1(beginRow, 4), Excel.RCtoA1(rowId + 1, 4)), bodyStyleCenter);
excel.SetCellValue(rowId + 2, 5, "", bodyStyleCenter);
excel.SetCellFormula(rowId + 2, 6, String.Format("SUM({0}:{1})", Excel.RCtoA1(beginRow, 6), Excel.RCtoA1(rowId + 1, 6)), bodyStyleCenter);
excel.SetCellFormula(rowId + 2, 7, String.Format("SUM({0}:{1})", Excel.RCtoA1(beginRow, 7), Excel.RCtoA1(rowId + 1, 7)), bodyStyleCenter);
excel.SetCellFormula(rowId + 2, 8, String.Format("SUM({0}:{1})", Excel.RCtoA1(beginRow, 8), Excel.RCtoA1(rowId + 1, 8)), bodyStyleCenter);
excel.SetCellFormula(rowId + 2, 9, String.Format("AVERAGE({0}:{1})", Excel.RCtoA1(beginRow, 9), Excel.RCtoA1(rowId + 1, 9)), bodyPercentStyle);
excel.SetCellFormula(rowId + 2, 10, String.Format("AVERAGE({0}:{1})", Excel.RCtoA1(beginRow, 10), Excel.RCtoA1(rowId + 1, 10)), bodyPercentStyle);
excel.SetRowHeightInPoints(rowId + 2, (int)Math.Truncate(BodyRowHeight * 2.0));
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public List<Item> data;
public List<string> export_columns;
public DateTime? ;
public DateTime? ;
public string ;
public string ;
private List<ExportColumn> columns = new List<ExportColumn>() {
new ExportColumn() { Key="領款人姓名" , Title="領款人姓名" , Width=20 , FieldName="領款人姓名" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="身分證字號" , Title="身分證字號" , Width=20 , FieldName="身分證字號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="戶籍地址" , Title="戶籍地址" , Width=50 , FieldName="戶籍地址" },
new ExportColumn() { Key="扣繳類別" , Title="扣繳類別" , Width=25 , FieldName="扣繳類別名稱" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="扣繳金額" , Title="扣繳金額" , Width=15 , FieldName="講師勞務費合計" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="應扣繳稅額" , Title="應扣繳稅額" , Width=15 , FieldName="應扣繳稅額合計" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="服務費" , Title="服務費" , Width=15 , FieldName="服務費合計" , Align=HorizontalAlignment.Right, MoneyFormat=true },
};
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("扣繳彙整表");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 1. 預先過濾出需要匯出的欄位
var activeColumns = columns.Where(c => true).ToList();
// 報表抬頭
int rowId = 0;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "活動日期:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if ( != null && != null)
excel.SetCellValue(rowId, 2, string.Format("{0:yyyy-MM-dd} ~ {1:yyyy-MM-dd}", , ), bodyStyleLeft);
else if ( != null && == null)
excel.SetCellValue(rowId, 2, string.Format("{0:yyyy-MM-dd} ~ ", ), bodyStyleLeft);
else if ( == null && != null)
excel.SetCellValue(rowId, 2, string.Format("~ {0:yyyy-MM-dd}", ), bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
rowId++;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "身分別:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if (string.IsNullOrEmpty())
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, , bodyStyleLeft);
rowId++;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "憑證類別:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if (string.IsNullOrEmpty())
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, , bodyStyleLeft);
rowId++;
// 表頭
excel.SetCellValue(rowId, 0, "序號", bodyStyleCenter);
excel.SetColumnWidthInChars(0, 8);
int col = 1;
int colCount = 1;
foreach (var column in activeColumns)
{
excel.SetCellValue(3, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
colCount++;
}
rowId++;
// 報表內容
foreach (var r in data)
{
// 序號
col = 0;
excel.SetCellValue(rowId, col++, rowId - 3, bodyStyleCenter);
// 其它欄位內容
foreach (var column in activeColumns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = r.FieldValue(column.FieldName);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
excel.MergeCell(rowId, 0, rowId, 4);
excel.SetCellValue(rowId, 0, "合計", bodyStyleLeft);
excel.SetCellValue(rowId, 5, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle);
excel.SetCellValue(rowId, 6, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle);
excel.SetCellValue(rowId, 7, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public List<Item> data;
public List<string> export_columns;
public DateTime? ;
public DateTime? ;
public string ;
public string ;
private List<ExportColumn> columns = new List<ExportColumn>() {
new ExportColumn() { Key="計畫代號" , Title="計畫代號" , Width=20 , FieldName="計畫代號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="活動日期" , Title="活動日期" , Width=20 , FieldName="活動日期" , Align=HorizontalAlignment.Center, Format="{0:yyyy/MM/dd}" },
new ExportColumn() { Key="領款人姓名" , Title="領款人姓名" , Width=20 , FieldName="領款人姓名" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="身分證字號" , Title="身分證字號" , Width=20 , FieldName="身分證字號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="憑證類型" , Title="憑證類型" , Width=20 , FieldName="憑證類別" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="領據編號" , Title="領據編號" , Width=20 , FieldName="領據編號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="活動名稱/事由" , Title="活動名稱/事由" , Width=50 , FieldName="活動名稱事由" },
new ExportColumn() { Key="費用別" , Title="費用別" , Width=20 , FieldName="費用別" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="單價" , Title="單價" , Width=20 , FieldName="單價" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="數量" , Title="數量" , Width=20 , FieldName="數量" , Align=HorizontalAlignment.Right, MoneyFormat=true, MondyDigits=2 },
new ExportColumn() { Key="單位" , Title="單位" , Width=20 , FieldName="單位" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="扣繳類別" , Title="扣繳類別" , Width=25 , FieldName="扣繳類別名稱" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="合計金額" , Title="合計金額" , Width=15 , FieldName="講師勞務費" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="應扣繳稅額" , Title="應扣繳稅額" , Width=15 , FieldName="應扣繳稅額" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="服務費" , Title="服務費" , Width=15 , FieldName="服務費" , Align=HorizontalAlignment.Right, MoneyFormat=true },
};
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("扣繳明細表");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 1. 預先過濾出需要匯出的欄位
var activeColumns = columns.Where(c => true).ToList();
// 報表抬頭
int rowId = 0;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "活動日期:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if ( != null && != null)
excel.SetCellValue(rowId, 2, string.Format("{0:yyyy-MM-dd} ~ {1:yyyy-MM-dd}", , ), bodyStyleLeft);
else if ( != null && == null)
excel.SetCellValue(rowId, 2, string.Format("{0:yyyy-MM-dd} ~ ", ), bodyStyleLeft);
else if ( == null && != null)
excel.SetCellValue(rowId, 2, string.Format("~ {0:yyyy-MM-dd}", ), bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
rowId++;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "身分別:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if (string.IsNullOrEmpty())
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, , bodyStyleLeft);
rowId++;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "憑證類別:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if (string.IsNullOrEmpty())
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, , bodyStyleLeft);
rowId++;
// 表頭
excel.SetCellValue(rowId, 0, "項次", bodyStyleCenter);
excel.SetColumnWidthInChars(0, 8);
int col = 1;
int colCount = 1;
foreach (var column in activeColumns)
{
excel.SetCellValue(3, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
colCount++;
}
rowId++;
// 報表內容
foreach (var r in data)
{
// 序號
col = 0;
excel.SetCellValue(rowId, col++, rowId - 3, bodyStyleCenter);
// 其它欄位內容
foreach (var column in activeColumns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = r.FieldValue(column.FieldName);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
//excel.MergeCell(rowId, 0, rowId, 4);
//excel.SetCellValue(rowId, 0, "合計", bodyStyleLeft);
//excel.SetCellValue(rowId, 5, string.Format("{0:###,###,##0}", data.Sum(p => p.講師勞務費合計)), bodyStyleRight);
//excel.SetCellValue(rowId, 6, string.Format("{0:###,###,##0}", data.Sum(p => p.應扣繳稅額合計)), bodyStyleRight);
//excel.SetCellValue(rowId, 7, string.Format("{0:###,###,##0}", data.Sum(p => p.服務費合計)), bodyStyleRight);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public List<Item> data;
public DateTime? ;
public DateTime? ;
private List<ExportColumn> columns = new List<ExportColumn>() {
new ExportColumn() { Key="計畫代號" , Title="計畫代號" , Width=20 , FieldName="計畫代號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="活動日期" , Title="活動日期" , Width=20 , FieldName="活動日期" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="活動名稱事由" , Title="活動名稱/事由" , Width=40 , FieldName="活動名稱事由" },
new ExportColumn() { Key="扣繳類別" , Title="扣繳類別" , Width=20 , FieldName="扣繳類別名稱" },
new ExportColumn() { Key="扣繳金額" , Title="扣繳金額" , Width=15 , FieldName="講師勞務費" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="應扣繳稅額" , Title="應扣繳稅額" , Width=15 , FieldName="應扣繳稅額" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="服務費" , Title="服務費" , Width=15 , FieldName="服務費" , Align=HorizontalAlignment.Right, MoneyFormat=true }
};
public byte[] DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("扣繳領據明細");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 1. 預先過濾出需要匯出的欄位
var activeColumns = columns.Where(c => true).ToList();
// 報表抬頭
int rowId = 0;
excel.MergeCell(rowId, 0, rowId, 6, BorderStyle.None);
excel.SetCellValue(rowId, 0, PublicVariable.CompanyName, headerStyle);
excel.SetRowHeightInPoints(rowId, 20);
rowId++;
excel.MergeCell(rowId, 0, rowId, 6, BorderStyle.None);
if ( != null && != null)
excel.SetCellValue(rowId, 0,
string.Format("[日期:{0:yyyy-MM-dd} ~ {1:yyyy-MM-dd}] 扣繳領據明細", , ), headerStyle);
else if ( != null && == null)
excel.SetCellValue(rowId, 0,
string.Format("[日期:{0:yyyy-MM-dd} ~ ] 扣繳領據明細", ), headerStyle);
else if ( == null && != null)
excel.SetCellValue(rowId, 0,
string.Format("[日期:~ {0:yyyy-MM-dd}] 扣繳領據明細", ), headerStyle);
else
excel.SetCellValue(rowId, 0, "[日期:全部] 扣繳領據明細", headerStyle);
excel.SetRowHeightInPoints(rowId, 20);
rowId++;
excel.MergeCell(rowId, 0, rowId, 6, BorderStyle.None);
excel.SetCellValue(rowId, 0,
string.Format("領款人姓名:{0} 身分證字號:{1}",
data.FirstOrDefault()?.,
data.FirstOrDefault()?.),
titleStyleLeftNoBorder);
excel.SetRowHeightInPoints(rowId, 16);
rowId++;
// 表頭
int col = 0;
foreach (var column in activeColumns)
{
excel.SetCellValue(rowId, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
}
rowId++;
// 報表內容
foreach (var r in data)
{
col = 0;
foreach (var column in activeColumns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = r.FieldValue(column.FieldName);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
excel.MergeCell(rowId, 0, rowId, 3, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "總計", bodyStyleRight);
excel.SetCellValue(rowId, 4, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle2);
excel.SetCellValue(rowId, 5, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle2);
excel.SetCellValue(rowId, 6, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms.ToArray();
}
}
}
@@ -0,0 +1,209 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 這段程式碼是由工具產生的。
// 執行階段版本:4.0.30319.18444
//
// 對這個檔案所做的變更可能會造成錯誤的行為,而且如果重新產生程式碼,
// 變更將會遺失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Education.Report {
using System;
using System.ComponentModel;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
public class : ReportClass {
public () {
}
public override string ResourceName {
get {
return "教育訓練簽到表.rpt";
}
set {
// Do nothing
}
}
public override bool NewGenerator {
get {
return true;
}
set {
// Do nothing
}
}
public override string FullResourceName {
get {
return "Education.Report.教育訓練簽到表.rpt";
}
set {
// Do nothing
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section ReportHeaderSection1 {
get {
return this.ReportDefinition.Sections[0];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section PageHeaderSection1 {
get {
return this.ReportDefinition.Sections[1];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section GroupHeaderSection1 {
get {
return this.ReportDefinition.Sections[2];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section GroupHeaderSection2 {
get {
return this.ReportDefinition.Sections[3];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section DetailSection1 {
get {
return this.ReportDefinition.Sections[4];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section GroupFooterSection1 {
get {
return this.ReportDefinition.Sections[5];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section ReportFooterSection1 {
get {
return this.ReportDefinition.Sections[6];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.CrystalReports.Engine.Section PageFooterSection1 {
get {
return this.ReportDefinition.Sections[7];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.Shared.IParameterField Parameter_公司名稱 {
get {
return this.DataDefinition.ParameterFields[0];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.Shared.IParameterField Parameter_辦理地點 {
get {
return this.DataDefinition.ParameterFields[1];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.Shared.IParameterField Parameter_講師姓名 {
get {
return this.DataDefinition.ParameterFields[2];
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public CrystalDecisions.Shared.IParameterField Parameter_承辦人員 {
get {
return this.DataDefinition.ParameterFields[3];
}
}
}
[System.Drawing.ToolboxBitmapAttribute(typeof(CrystalDecisions.Shared.ExportOptions), "report.bmp")]
public class Cached教育訓練簽到表 : Component, ICachedReport {
public Cached教育訓練簽到表() {
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual bool IsCacheable {
get {
return true;
}
set {
//
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual bool ShareDBLogonInfo {
get {
return false;
}
set {
//
}
}
[Browsable(false)]
[DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public virtual System.TimeSpan CacheTimeOut {
get {
return CachedReportConstants.DEFAULT_TIMEOUT;
}
set {
//
}
}
public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport() {
rpt = new ();
rpt.Site = this.Site;
return rpt;
}
public virtual string GetCustomizedCacheKey(RequestContext request) {
String key = null;
// // The following is the code used to generate the default
// // cache key for caching report jobs in the ASP.NET Cache.
// // Feel free to modify this code to suit your needs.
// // Returning key == null causes the default cache key to
// // be generated.
//
// key = RequestContext.BuildCompleteCacheKey(
// request,
// null, // sReportFilename
// this.GetType(),
// this.ShareDBLogonInfo );
return key;
}
}
}
@@ -0,0 +1,120 @@
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;
}
}
}
@@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public List data;
public List<string> export_columns;
public DateTime? ;
public DateTime? ;
public string ;
public string ;
private List<ExportColumn> columns = new List<ExportColumn>() {
new ExportColumn() { Key="領款人姓名" , Title="領款人姓名" , Width=20 , FieldName="領款人姓名" },
new ExportColumn() { Key="身分證字號" , Title="身分證字號" , Width=20 , FieldName="身分證字號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="堂數" , Title="堂數" , Width=10 , FieldName="堂數" , Align=HorizontalAlignment.Right, MoneyFormat=true, MondyDigits=2 },
new ExportColumn() { Key="扣繳類別" , Title="扣繳類別" , Width=50 , FieldName="扣繳類別名稱" },
new ExportColumn() { Key="帳戶名" , Title="帳戶名" , Width=20 , FieldName="帳戶名" },
new ExportColumn() { Key="付款金額" , Title="付款金額" , Width=15 , FieldName="付款金額" , Align=HorizontalAlignment.Right, MoneyFormat=true },
new ExportColumn() { Key="匯款帳號" , Title="匯款帳號" , Width=20 , FieldName="匯款帳號" },
new ExportColumn() { Key="銀行分行代碼" , Title="銀行分行代碼" , Width=20 , FieldName="銀行分行代碼" },
new ExportColumn() { Key="銀行分行" , Title="銀行/分行" , Width=20 , FieldName="銀行分行" }
};
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("講師個人費用彙整表");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 1. 預先過濾出需要匯出的欄位
var activeColumns = columns.Where(c => true).ToList();
// 報表抬頭
int rowId = 0;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "活動日期:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if ( != null && != null)
excel.SetCellValue(rowId, 2, string.Format("{0:yyyy-MM-dd} ~ {1:yyyy-MM-dd}", , ), bodyStyleLeft);
else if ( != null && == null)
excel.SetCellValue(rowId, 2, string.Format("{0:yyyy-MM-dd} ~ ", ), bodyStyleLeft);
else if ( == null && != null)
excel.SetCellValue(rowId, 2, string.Format("~ {0:yyyy-MM-dd}", ), bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
rowId++;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "身分別:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if (string.IsNullOrEmpty())
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, , bodyStyleLeft);
rowId++;
excel.MergeCell(rowId, 0, rowId, 1, BorderStyle.Thin);
excel.SetCellValue(rowId, 0, "付款方式:", bodyStyleLeft);
excel.MergeCell(rowId, 2, rowId, 3, BorderStyle.Thin);
if (string.IsNullOrEmpty())
excel.SetCellValue(rowId, 2, "全部", bodyStyleLeft);
else
excel.SetCellValue(rowId, 2, , bodyStyleLeft);
rowId++;
// 表頭
excel.SetCellValue(rowId, 0, "序號", bodyStyleCenter);
excel.SetColumnWidthInChars(0, 8);
int col = 1;
int colCount = 1;
foreach (var column in activeColumns)
{
excel.SetCellValue(3, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
colCount++;
}
rowId++;
// 報表內容
foreach (var r in data)
{
// 序號
col = 0;
excel.SetCellValue(rowId, col++, rowId - 3, bodyStyleCenter);
// 其它欄位內容
foreach (var column in activeColumns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = r.FieldValue(column.FieldName);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
excel.MergeCell(rowId, 0, rowId, 1);
excel.SetCellValue(rowId, 0, "合計", bodyStyleCenter);
excel.SetCellValue(rowId, 2, "", bodyStyleCenter);
excel.SetCellValue(rowId, 3, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle2);
excel.SetCellValue(rowId, 4, "", bodyStyleCenter);
excel.SetCellValue(rowId, 5, "", bodyStyleCenter);
excel.SetCellValue(rowId, 6, DAC.GetDouble(data.Sum(p => p.)), bodyNumberStyle);
excel.SetCellValue(rowId, 7, "", bodyStyleCenter);
excel.SetCellValue(rowId, 8, "", bodyStyleCenter);
excel.SetCellValue(rowId, 9, "", bodyStyleCenter);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public List<> data;
public List<string> export_columns;
private List<ExportColumn> columns = new List<ExportColumn>() {
new ExportColumn() { Key="姓名" , Title="姓名" , Width=20 , FieldName="姓名" },
new ExportColumn() { Key="出生日期" , Title="出生日期" , Width=20 , FieldName="出生日期" , Align=HorizontalAlignment.Center, Format="{0:yyyy-MM-dd}" },
new ExportColumn() { Key="性別" , Title="性別" , Width=10 , FieldName="性別" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="身份證字號" , Title="身份證字號" , Width=20 , FieldName="身份證字號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="電話" , Title="電話" , Width=20 , FieldName="電話" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="手機" , Title="手機" , Width=20 , FieldName="手機" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="電子郵件" , Title="電子郵件" , Width=30 , FieldName="電子郵件" },
new ExportColumn() { Key="戶籍地址" , Title="戶籍地址" , Width=50 , FieldName="戶籍地址" },
new ExportColumn() { Key="居住地址" , Title="居住地址" , Width=50 , FieldName="居住地址" },
new ExportColumn() { Key="現職" , Title="現職" , Width=50 , FieldName="現職" },
new ExportColumn() { Key="最高學歷" , Title="最高學歷" , Width=100 , FieldName="學歷" },
new ExportColumn() { Key="授課區域" , Title="授課區域" , Width=100 , FieldName="授課區域TXT" },
new ExportColumn() { Key="授課專長領域" , Title="授課專長領域" , Width=100 , FieldName="授課專長領域" },
new ExportColumn() { Key="授課經歷概述" , Title="授課經歷概述" , Width=100 , FieldName="授課經歷概述" },
new ExportColumn() { Key="重要經歷" , Title="重要經歷" , Width=100 , FieldName="重要經歷" },
new ExportColumn() { Key="重要研究與著作" , Title="重要研究與著作" , Width=100 , FieldName="重要研究與著作" },
new ExportColumn() { Key="合作狀態" , Title="合作狀態" , Width=100 , FieldName="合作狀態RPT" },
new ExportColumn() { Key="合作方式" , Title="合作方式" , Width=100 , FieldName="合作方式" },
new ExportColumn() { Key="證照資料" , Title="證照資料" , Width=100 , FieldName="證照資料" },
new ExportColumn() { Key="異常標註" , Title="異常標註" , Width=100 , FieldName="異常標註" },
new ExportColumn() { Key="講師來源" , Title="講師來源" , Width=100 , FieldName="講師來源" },
new ExportColumn() { Key="推薦授課主題" , Title="推薦授課主題" , Width=100 , FieldName="推薦授課主題" },
new ExportColumn() { Key="TTQS滿意度" , Title="TTQS滿意度" , Width=20 , FieldName="平均滿意度" , Align=HorizontalAlignment.Right, Format="{0:F2}" },
new ExportColumn() { Key="講師評鑑(跟課)" , Title="講師評鑑(跟課)" , Width=20 , FieldName="講師評鑑" , Align=HorizontalAlignment.Right, Format="{0:F2}" },
new ExportColumn() { Key="講師評鑑(學員)" , Title="講師評鑑(學員)" , Width=20 , FieldName="學員滿意度" , Align=HorizontalAlignment.Right, Format="{0:F2}" },
};
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("講師資料匯出");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 1. 預先過濾出需要匯出的欄位
var activeColumns = columns.Where(c => export_columns.Contains(c.Key)).ToList();
// 報表抬頭
excel.SetCellValue(0, 0, "序號", bodyStyleCenter);
excel.SetColumnWidthInChars(0, 10);
int col = 1;
int colCount = 1;
foreach (var column in activeColumns)
{
excel.SetCellValue(0, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
colCount++;
}
int rowId = 1;
foreach (var r in data)
{
// 報表內容
col = 0;
excel.SetCellValue(rowId, col++, rowId, bodyStyleCenter);
foreach (var column in activeColumns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = r.FieldValue(column.FieldName);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
excel.SetCellValue(rowId+1, 0, "總筆數", bodyStyleCenter);
excel.SetCellValue(rowId+1, 1, data.Count, bodyStyleCenter);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,100 @@
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using WebLib;
namespace Education.Report
{
public class : ReportBase
{
public List<Item> data;
public List<string> export_columns;
private List<ExportColumn> columns = new List<ExportColumn>() {
new ExportColumn() { Key="編號" , Title="編號" , Width=10 , FieldName="編號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="姓名" , Title="姓名" , Width=10 , FieldName="姓名" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="身分證字號" , Title="身分證字號" , Width=16 , FieldName="身分證字號" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="藝名網名" , Title="藝名網名" , Width=10 , FieldName="藝名網名" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="聯絡電話" , Title="聯絡電話" , Width=16 , FieldName="聯絡電話" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="電子郵件" , Title="電子郵件" , Width=25 , FieldName="電子郵件" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="戶籍地址" , Title="戶籍地址_郵編" , Width=10 , FieldName="戶籍地址_郵編" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="戶籍地址" , Title="戶籍地址_縣市" , Width=10 , FieldName="戶籍地址_縣市" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="戶籍地址" , Title="戶籍地址_鄉鎮市區" , Width=10 , FieldName="戶籍地址_鄉鎮市區" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="戶籍地址" , Title="戶籍地址_街道地址" , Width=30 , FieldName="戶籍地址_街道地址" },
new ExportColumn() { Key="居住地址" , Title="居住地址_郵編" , Width=10 , FieldName="居住地址_郵編" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="居住地址" , Title="居住地址_縣市" , Width=10 , FieldName="居住地址_縣市" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="居住地址" , Title="居住地址_鄉鎮市區" , Width=10 , FieldName="居住地址_鄉鎮市區" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="居住地址" , Title="居住地址_街道地址" , Width=30 , FieldName="居住地址_街道地址" , Align=HorizontalAlignment.Center },
new ExportColumn() { Key="職務內容" , Title="職務內容" , Width=100 , FieldName="職務內容" },
new ExportColumn() { Key="合作滿意度" , Title="合作滿意度" , Width=100 , FieldName="合作滿意度" },
new ExportColumn() { Key="窗口" , Title="窗口", Width=100 },
new ExportColumn() { Key="是否接受邀約" , Title="是否接受邀約", Width=10, FieldName= "接受邀約", Format = "{0}", Align=HorizontalAlignment.Center },
new ExportColumn() { Key="聯繫狀況與報價" , Title="聯繫狀況與報價", Width=100 },
new ExportColumn() { Key="備註" , Title="備註", Width=100 }
};
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet("非講師資料匯出");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 1. 預先過濾出需要匯出的欄位
var activeColumns = columns.Where(c => export_columns.Contains(c.Key)).ToList();
// 報表抬頭
int col = 0;
int colCount = 0;
foreach (var column in activeColumns)
{
excel.SetCellValue(0, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
colCount++;
}
int rowId = 1;
foreach (var r in data)
{
// 報表內容
col = 0;
foreach (var column in activeColumns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = r.FieldValue(column.FieldName);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
excel.SetCellValue(rowId + 1, 0, "總筆數", bodyStyleCenter);
excel.SetCellValue(rowId + 1, 1, data.Count, bodyStyleCenter);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}
}
@@ -0,0 +1,442 @@
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using WebLib;
namespace Education.Report
{
public class
{
private const string TEMPLATE_FILE_NAME = "領據列印模版.xlsx";
private const string LABOR_SHEET_NAME = "勞務費";
private const string TRAVEL_SHEET_NAME = "差旅費";
public System.IO.MemoryStream DoReport(List<Education.Services.PrintData> printDataList)
{
// 載入模版檔案
string templatePath = GetTemplatePath();
if (!File.Exists(templatePath))
{
throw new FileNotFoundException(string.Format("模版檔案不存在: {0}", templatePath));
}
XSSFWorkbook templateWorkbook = null;
XSSFWorkbook outputWorkbook = null;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
try
{
// 從模版載入 workbook (唯讀)
using (FileStream templateStream = new FileStream(templatePath, FileMode.Open, FileAccess.Read))
{
templateWorkbook = new XSSFWorkbook(templateStream);
}
// 建立產出工作簿
outputWorkbook = new XSSFWorkbook();
// 取得模版工作表
ISheet laborTemplateSheet = templateWorkbook.GetSheet(LABOR_SHEET_NAME);
ISheet travelTemplateSheet = templateWorkbook.GetSheet(TRAVEL_SHEET_NAME);
if (laborTemplateSheet == null)
{
throw new Exception(string.Format("模版檔案中找不到工作表: {0}", LABOR_SHEET_NAME));
}
if (travelTemplateSheet == null)
{
throw new Exception(string.Format("模版檔案中找不到工作表: {0}", TRAVEL_SHEET_NAME));
}
// 處理每筆領據
int sheetCount = 0;
foreach (var data in printDataList)
{
// 勞務費單據
if (data.Labor != null && !data.Labor.IsEmpty)
{
ProcessLaborSheet(outputWorkbook, laborTemplateSheet, data.Main, data.Labor, data., data., ref sheetCount);
}
// 差旅費單據
if (data.Travel != null && !data.Travel.IsEmpty)
{
ProcessTravelSheet(outputWorkbook, travelTemplateSheet, data.Main, data.Travel, data., data., ref sheetCount);
}
}
// 寫入 MemoryStream
outputWorkbook.Write(ms);
return ms;
}
finally
{
if (templateWorkbook != null)
{
templateWorkbook.Close();
}
}
}
private string GetTemplatePath()
{
// 模版檔案應位於應用程式根目錄下的 Template 資料夾
string appPath = System.AppDomain.CurrentDomain.BaseDirectory;
string templatesFolder = Path.Combine(appPath, "Template");
return Path.Combine(templatesFolder, TEMPLATE_FILE_NAME);
}
private void ProcessLaborSheet(XSSFWorkbook outputWorkbook, ISheet templateSheet, Item mainData, Item laborData, , Item , ref int sheetCount)
{
// 複製模版工作表到產出工作簿
ISheet newSheet = CopySheetToWorkbook(outputWorkbook, templateSheet, string.Format("{0}_講師勞務費_{1}", mainData., laborData.));
sheetCount++;
// 建立替換字典
var replacements = new Dictionary<string, string>
{
{ "[領據編號]", laborData. },
{ "[領款人姓名]", mainData. },
{ "[計畫名稱]", mainData. },
{ "[費用別]", laborData. },
{ "[單價]", string.Format("{0:###,##0}", laborData.) },
{ "[數量]", string.Format("{0:###,##0.##}", laborData.) },
{ "[單位]", laborData. },
{ "[身分證字號]", mainData. },
{ "[聯絡電話]", mainData. == "講師" ? . : . },
{ "[戶籍地址]", mainData. == "講師" ? . : . },
{ "[電子郵件]", mainData. == "講師" ? . : . },
{ "[扣繳類別]", .GetName(laborData.) },
{ "[合計]", string.Format("{0:###,##0}", laborData.) },
{ "[應扣繳稅額]", string.Format("{0:###,##0}", laborData.) },
{ "[活動名稱事由]", mainData. },
{ "[活動日期年]", (mainData..Year - 1911).ToString() },
{ "[活動日期月]", mainData..Month.ToString() },
{ "[活動日期日]", mainData..Day.ToString() }
};
// 執行字串取代
ReplaceInSheet(newSheet, replacements);
}
private void ProcessTravelSheet(XSSFWorkbook outputWorkbook, ISheet templateSheet, Item mainData, Item travelData, , Item , ref int sheetCount)
{
// 複製模版工作表到產出工作簿
ISheet newSheet = CopySheetToWorkbook(outputWorkbook, templateSheet, string.Format("{0}_差旅費_{1}", mainData., travelData.));
sheetCount++;
// 建立替換字典
var replacements = new Dictionary<string, string>
{
{ "[領據編號]", travelData. },
{ "[計畫名稱]", mainData. },
{ "[領款人姓名]", mainData. },
{ "[起點]", travelData. },
{ "[訖點]", travelData. },
{ "[捷公]", string.Format("{0:###,##0}", travelData.) },
{ "[火車]", string.Format("{0:###,##0}", travelData.) },
{ "[計程]", string.Format("{0:###,##0}", travelData.) },
{ "[高飛]", string.Format("{0:###,##0}", travelData.) },
{ "[開車]", string.Format("{0:###,##0}", travelData.) },
{ "[過停]", string.Format("{0:###,##0}", travelData.) },
{ "[住宿]", string.Format("{0:###,##0}", travelData.宿) },
{ "[合計]", string.Format("{0:###,##0}", travelData.) },
{ "[活動名稱事由]", mainData. },
{ "[活動日期年]", (mainData..Year - 1911).ToString() },
{ "[活動日期月]", mainData..Month.ToString() },
{ "[活動日期日]", mainData..Day.ToString() }
};
// 執行字串取代
ReplaceInSheet(newSheet, replacements);
}
/// <summary>
/// 複製工作表到另一個 workbook 中
/// </summary>
private ISheet CopySheetToWorkbook(XSSFWorkbook targetWorkbook, ISheet sourceSheet, string newSheetName)
{
ISheet newSheet = targetWorkbook.CreateSheet(newSheetName);
// 建立樣式快取和字體快取
Dictionary<int, ICellStyle> styleCache = new Dictionary<int, ICellStyle>();
Dictionary<string, IFont> fontCache = new Dictionary<string, IFont>();
// 複製所有行
for (int rowIndex = 0; rowIndex <= sourceSheet.LastRowNum; rowIndex++)
{
IRow sourceRow = sourceSheet.GetRow(rowIndex);
if (sourceRow == null)
continue;
IRow newRow = newSheet.CreateRow(rowIndex);
CopyRow(targetWorkbook, sourceRow, newRow, styleCache, fontCache);
}
// 複製列寬(只複製來源工作表實際有內容的欄位)
int maxCol = 0;
for (int r = 0; r <= sourceSheet.LastRowNum; r++)
{
var row = sourceSheet.GetRow(r);
if (row != null && row.LastCellNum > maxCol)
maxCol = row.LastCellNum;
}
for (int colIndex = 0; colIndex < maxCol; colIndex++)
{
newSheet.SetColumnWidth(colIndex, sourceSheet.GetColumnWidth(colIndex));
}
// 複製合併儲存格
CopyMergedRegions(sourceSheet, newSheet);
// 複製列印設定(加上驗證)
CopyPrintSetup(sourceSheet, newSheet);
// 複製頁面邊界: 天地上下左右
newSheet.SetMargin(MarginType.TopMargin, sourceSheet.GetMargin(MarginType.TopMargin));
newSheet.SetMargin(MarginType.BottomMargin, sourceSheet.GetMargin(MarginType.BottomMargin));
newSheet.SetMargin(MarginType.LeftMargin, sourceSheet.GetMargin(MarginType.LeftMargin));
newSheet.SetMargin(MarginType.RightMargin, sourceSheet.GetMargin(MarginType.RightMargin));
newSheet.SetMargin(MarginType.HeaderMargin, sourceSheet.GetMargin(MarginType.HeaderMargin));
newSheet.SetMargin(MarginType.FooterMargin, sourceSheet.GetMargin(MarginType.FooterMargin));
// 複製顯示格線設定
newSheet.DisplayGridlines = sourceSheet.DisplayGridlines;
newSheet.IsPrintGridlines = sourceSheet.IsPrintGridlines;
return newSheet;
}
/// <summary>
/// 複製列印設定(帶驗證)
/// </summary>
private void CopyPrintSetup(ISheet sourceSheet, ISheet targetSheet)
{
if (sourceSheet.PrintSetup == null)
return;
try
{
IPrintSetup sourcePrintSetup = sourceSheet.PrintSetup;
IPrintSetup targetPrintSetup = targetSheet.PrintSetup;
// 複製方向
targetPrintSetup.Landscape = sourcePrintSetup.Landscape;
// 複製紙張大小
targetPrintSetup.PaperSize = sourcePrintSetup.PaperSize;
// 複製符合頁面設定
// targetPrintSetup.FitWidth = sourcePrintSetup.FitWidth;
// targetPrintSetup.FitHeight = sourcePrintSetup.FitHeight;
// 複製水平置中與垂直置中
targetSheet.HorizontallyCenter = sourceSheet.HorizontallyCenter;
targetSheet.VerticallyCenter = sourceSheet.VerticallyCenter;
// 將工作表放入單一頁面
// targetSheet.FitToPage = true;
}
catch (Exception ex)
{
// 如果複製列印設定失敗,記錄但不中斷流程
System.Diagnostics.Debug.WriteLine(string.Format("複製列印設定失敗: {0}", ex.Message));
}
}
/// <summary>
/// 複製合併儲存格區域
/// </summary>
private void CopyMergedRegions(ISheet sourceSheet, ISheet targetSheet)
{
int mergedRegionCount = sourceSheet.NumMergedRegions;
for (int i = 0; i < mergedRegionCount; i++)
{
CellRangeAddress mergedRegion = sourceSheet.GetMergedRegion(i);
if (mergedRegion != null)
{
targetSheet.AddMergedRegion(new CellRangeAddress(
mergedRegion.FirstRow,
mergedRegion.LastRow,
mergedRegion.FirstColumn,
mergedRegion.LastColumn
));
}
}
}
/// <summary>
/// 複製行及其樣式到目標工作簿(使用快取避免重複建立樣式)
/// </summary>
private void CopyRow(XSSFWorkbook targetWorkbook, IRow sourceRow, IRow targetRow,
Dictionary<int, ICellStyle> styleCache, Dictionary<string, IFont> fontCache)
{
targetRow.Height = sourceRow.Height;
for (int colIndex = 0; colIndex < sourceRow.LastCellNum; colIndex++)
{
ICell sourceCell = sourceRow.GetCell(colIndex);
if (sourceCell == null)
continue;
ICell targetCell = targetRow.CreateCell(colIndex);
// 複製樣式(使用快取)
if (sourceCell.CellStyle != null)
{
short styleIndex = sourceCell.CellStyle.Index;
ICellStyle targetStyle;
if (!styleCache.TryGetValue(styleIndex, out targetStyle))
{
// 第一次遇到這個樣式,建立並快取
targetStyle = CreateCellStyle(targetWorkbook, sourceCell.CellStyle, fontCache);
styleCache[styleIndex] = targetStyle;
}
targetCell.CellStyle = targetStyle;
}
// 複製值
CopyCellValue(sourceCell, targetCell);
}
}
/// <summary>
/// 建立儲存格樣式(包含字體)
/// </summary>
private ICellStyle CreateCellStyle(XSSFWorkbook targetWorkbook, ICellStyle sourceStyle, Dictionary<string, IFont> fontCache)
{
ICellStyle newStyle = targetWorkbook.CreateCellStyle();
// 先複製基本樣式(對齊、邊框、背景等)
newStyle.Alignment = sourceStyle.Alignment;
newStyle.VerticalAlignment = sourceStyle.VerticalAlignment;
newStyle.WrapText = sourceStyle.WrapText;
newStyle.BorderTop = sourceStyle.BorderTop;
newStyle.BorderBottom = sourceStyle.BorderBottom;
newStyle.BorderLeft = sourceStyle.BorderLeft;
newStyle.BorderRight = sourceStyle.BorderRight;
newStyle.TopBorderColor = sourceStyle.TopBorderColor;
newStyle.BottomBorderColor = sourceStyle.BottomBorderColor;
newStyle.LeftBorderColor = sourceStyle.LeftBorderColor;
newStyle.RightBorderColor = sourceStyle.RightBorderColor;
newStyle.FillPattern = sourceStyle.FillPattern;
newStyle.FillForegroundColor = sourceStyle.FillForegroundColor;
newStyle.FillBackgroundColor = sourceStyle.FillBackgroundColor;
newStyle.DataFormat = sourceStyle.DataFormat;
// 複製字體(使用快取,但不包含底線)
XSSFCellStyle xssfSourceStyle = sourceStyle as XSSFCellStyle;
if (xssfSourceStyle != null)
{
XSSFFont sourceFont = xssfSourceStyle.GetFont() as XSSFFont;
if (sourceFont != null)
{
// 建立字體的唯一鍵
string fontKey = string.Format("{0}_{1}_{2}_{3}_{4}_{5}",
sourceFont.FontName ?? "",
sourceFont.FontHeightInPoints,
sourceFont.IsBold,
sourceFont.IsItalic,
sourceFont.IsStrikeout,
sourceFont.Color);
IFont targetFont;
if (!fontCache.TryGetValue(fontKey, out targetFont))
{
// 第一次遇到這個字體,建立並快取
targetFont = targetWorkbook.CreateFont();
targetFont.FontName = sourceFont.FontName;
targetFont.FontHeightInPoints = sourceFont.FontHeightInPoints;
targetFont.IsBold = sourceFont.IsBold;
targetFont.IsItalic = sourceFont.IsItalic;
targetFont.IsStrikeout = sourceFont.IsStrikeout;
targetFont.Color = sourceFont.Color;
// 不複製底線:targetFont.Underline = sourceFont.Underline;
fontCache[fontKey] = targetFont;
}
newStyle.SetFont(targetFont);
}
}
return newStyle;
}
/// <summary>
/// 複製儲存格的值
/// </summary>
private void CopyCellValue(ICell sourceCell, ICell targetCell)
{
switch (sourceCell.CellType)
{
case CellType.String:
targetCell.SetCellValue(sourceCell.StringCellValue);
break;
case CellType.Numeric:
if (DateUtil.IsCellDateFormatted(sourceCell))
{
targetCell.SetCellValue(sourceCell.DateCellValue);
}
else
{
targetCell.SetCellValue(sourceCell.NumericCellValue);
}
break;
case CellType.Boolean:
targetCell.SetCellValue(sourceCell.BooleanCellValue);
break;
case CellType.Formula:
targetCell.SetCellFormula(sourceCell.CellFormula);
break;
case CellType.Blank:
targetCell.SetCellType(CellType.Blank);
break;
default:
break;
}
}
/// <summary>
/// 在工作表中執行字串取代
/// </summary>
private void ReplaceInSheet(ISheet sheet, Dictionary<string, string> replacements)
{
for (int rowIndex = 0; rowIndex <= sheet.LastRowNum; rowIndex++)
{
IRow row = sheet.GetRow(rowIndex);
if (row == null)
continue;
for (int colIndex = 0; colIndex < row.LastCellNum; colIndex++)
{
ICell cell = row.GetCell(colIndex);
if (cell == null || cell.CellType != CellType.String)
continue;
string cellValue = cell.StringCellValue;
string newValue = cellValue;
// 逐個替換
foreach (var kvp in replacements)
{
newValue = newValue.Replace(kvp.Key, kvp.Value ?? "");
}
// 如果有變化,更新單元格
if (newValue != cellValue)
{
cell.SetCellValue(newValue);
}
}
}
}
}
}
@@ -0,0 +1,225 @@
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
namespace Education.Report
{
public class : ReportBase
{
public List data;
public bool = false;
public List<ExportColumn> Columns = new List<ExportColumn>() {
new ExportColumn() { Key="活動日期" , Title="活動日期" , Width=14 , FieldName="活動日期", Format="{0:yyyy-MM-dd}" },
new ExportColumn() { Key="身分別" , Title="身分別" , Width=12 , FieldName="身分別", Comment="講師\n非講師" },
new ExportColumn() { Key="領款人姓名" , Title="領款人姓名" , Width=12 , FieldName="領款人姓名" },
new ExportColumn() { Key="身分證字號" , Title="身分證字號" , Width=16 , FieldName="身分證字號" },
new ExportColumn() { Key="憑證類別" , Title="憑證類別" , Width=10 , FieldName="憑證類別" , Comment="領據\n發票\n收據"},
new ExportColumn() { Key="講師評價" , Title="講師評價" , Width=10 , FieldName="講師評價" },
new ExportColumn() { Key="計畫代號" , Title="計畫代號" , Width=14 , FieldName="計畫代號" },
new ExportColumn() { Key="活動地點" , Title="活動地點" , Width=30 , FieldName="活動地點" },
new ExportColumn() { Key="活動類別" , Title="活動類別" , Width=12 , FieldName="活動類別" },
new ExportColumn() { Key="付款方式" , Title="付款方式" , Width=12 , FieldName="付款方式" , Comment="匯款\n支票\n現金"},
new ExportColumn() { Key="活動名稱/事由" , Title="活動名稱/事由" , Width=40 , FieldName="活動名稱事由" },
new ExportColumn() { Key="領據作廢" , Title="領據作廢" , Width=10 , FieldName="作廢", Align = HorizontalAlignment.Center },
new ExportColumn() { Key="勞務費領據編號" , Title="勞務費領據編號" , Width=16 , FieldName="勞務費_編號" },
new ExportColumn() { Key="勞務費費用別" , Title="勞務費費用別" , Width=12 , FieldName="勞務費_費用別" , Comment="講師費\n諮詢費\n工作人員費\n勞務費\n主持人費\n出席費\n演講費\n撰稿費"},
new ExportColumn() { Key="扣繳類別" , Title="扣繳類別" , Width=12 , FieldName="勞務費_扣繳類別名稱" , Comment="50 薪資\n9A55 執行業務所得-心理師\n9A70 執行業務所得-表演人\n9A90 執行業務所得-其他\n9A92 執行業務所得-程式設計師\n9B98A 執行業務所得-稿費\n9B98B 執行業務所得-演講之鐘點費"},
new ExportColumn() { Key="單價" , Title="單價" , Width=12 , FieldName="勞務費_單價", MoneyFormat=true },
new ExportColumn() { Key="數量" , Title="數量" , Width=12 , FieldName="勞務費_數量", MoneyFormat=true, MondyDigits=2 },
new ExportColumn() { Key="單位" , Title="單位" , Width=12 , FieldName="勞務費_單位" },
new ExportColumn() { Key="勞務費合計" , Title="勞務費合計" , Width=12 , FieldName="勞務費_合計金額", MoneyFormat=true },
new ExportColumn() { Key="應扣繳稅額" , Title="應扣繳稅額" , Width=12 , FieldName="勞務費_應扣繳稅額", MoneyFormat=true },
new ExportColumn() { Key="服務費" , Title="服務費" , Width=12 , FieldName="勞務費_服務費", MoneyFormat=true },
new ExportColumn() { Key="勞務費作廢" , Title="勞務費作廢" , Width=10 , FieldName="勞務費_作廢", Align = HorizontalAlignment.Center },
new ExportColumn() { Key="差旅費領據編號" , Title="差旅費領據編號" , Width=16 , FieldName="差旅費_編號" },
new ExportColumn() { Key="差旅費費用別" , Title="差旅費費用別" , Width=12 , FieldName="差旅費_費用別" },
new ExportColumn() { Key="差旅票價資訊" , Title="差旅票價資訊" , Width=20 , FieldName="差旅費_票價資訊" },
new ExportColumn() { Key="起點" , Title="起點" , Width=12 , FieldName="差旅費_起點" },
new ExportColumn() { Key="訖點" , Title="訖點" , Width=12 , FieldName="差旅費_訖點" },
new ExportColumn() { Key="捷運公車" , Title="捷運/公車" , Width=12 , FieldName="差旅費_捷運公車", MoneyFormat=true },
new ExportColumn() { Key="火車" , Title="火車" , Width=12 , FieldName="差旅費_火車", MoneyFormat=true },
new ExportColumn() { Key="計程車" , Title="計程車" , Width=12 , FieldName="差旅費_計程車", MoneyFormat=true },
new ExportColumn() { Key="高鐵飛機" , Title="高鐵/飛機" , Width=12 , FieldName="差旅費_高鐵飛機", MoneyFormat=true },
new ExportColumn() { Key="自行開車" , Title="自行開車" , Width=12 , FieldName="差旅費_自行開車", MoneyFormat=true },
new ExportColumn() { Key="過路費停車費" , Title="過路費/停車費" , Width=12 , FieldName="差旅費_過路費停車費", MoneyFormat=true },
new ExportColumn() { Key="住宿費" , Title="住宿費" , Width=12 , FieldName="差旅費_住宿費", MoneyFormat=true },
new ExportColumn() { Key="差旅費合計" , Title="差旅費合計" , Width=12 , FieldName="差旅費_合計", MoneyFormat=true },
new ExportColumn() { Key="差旅費作廢" , Title="差旅費作廢" , Width=10 , FieldName="差旅費_作廢", Align = HorizontalAlignment.Center },
};
public MemoryStream DoReport()
{
workbook.RemoveSheetAt(0);
sheet = workbook.CreateSheet( ? "領據匯入範本" : "領據匯出");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
if ()
{
Columns.RemoveAll(x => x.Key == "勞務費領據編號");
Columns.RemoveAll(x => x.Key == "差旅費領據編號");
Columns.RemoveAll(x => x.Key == "勞務費合計");
Columns.RemoveAll(x => x.Key == "應扣繳稅額");
Columns.RemoveAll(x => x.Key == "差旅費費用別");
Columns.RemoveAll(x => x.Key == "差旅費合計");
Columns.RemoveAll(x => x.Key == "講師評價");
Columns.RemoveAll(x => x.Key == "領據作廢");
Columns.RemoveAll(x => x.Key == "勞務費作廢");
Columns.RemoveAll(x => x.Key == "差旅費作廢");
}
// 報表抬頭
int col = 0;
int colCount = 0;
foreach (var column in Columns)
{
excel.SetCellValue(0, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
if (!string.IsNullOrEmpty(column.Comment))
{
excel.SetCellComment(0, col, column.Comment);
}
col++;
colCount++;
}
if (!)
{
int rowId = 1;
foreach (var r in data)
{
// 報表內容
col = 0;
foreach (var column in Columns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = GetColumnValue(r, column);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
// 報表尾
excel.SetCellValue(rowId + 1, 0, "總筆數", bodyStyleCenter);
excel.SetCellValue(rowId + 1, 1, data.Count, bodyStyleCenter);
}
else
{
// 範本要做另一個工作表,內容是資料填寫範例
sheet = workbook.CreateSheet("填寫範例 (本工作表不會匯入)");
SetPaperAndMargin(sheet);
sheet.RepeatingRows = new CellRangeAddress(0, 2, -1, -1);
excel.Sheet = sheet;
// 報表抬頭
col = 0;
colCount = 0;
foreach (var column in Columns)
{
excel.SetCellValue(0, col, column.Title, bodyStyleCenter);
excel.SetColumnWidthInChars(col, column.Width);
col++;
colCount++;
}
var demoData = new List();
demoData.Add(new Item()
{
= new DateTime(2026, 6, 1),
= "非講師",
= "貓老大",
= "A123456789",
= "領據",
= "115AG115001",
= "新譽總公司",
= "課程",
= "匯款",
= "領據系統說明會",
_費用別 = "講師費",
_扣繳類別 = "9B98B 執行業務所得-演講之鐘點費",
_單價 = 3600,
_數量 = 1,
_單位 = "時",
_服務費 = 0,
_票價資訊 = "高雄=桃園",
_起點 = "高雄",
_訖點 = "桃園",
_捷運公車 = 0,
_火車 = 0,
_計程車 = 0,
_高鐵飛機 = 1290,
_自行開車 = 0,
_過路費停車費 = 0,
_住宿費 = 0
});
int rowId = 1;
foreach (var r in demoData)
{
// 報表內容
col = 0;
foreach (var column in Columns)
{
var cellStyle = bodyStyleLeft;
switch (column.Align)
{
case HorizontalAlignment.Center:
cellStyle = bodyStyleCenter;
break;
case HorizontalAlignment.Right:
cellStyle = bodyStyleRight;
break;
}
var value = GetColumnValue(r, column);
SetDataValue(rowId, col, column, value, cellStyle);
col++;
}
rowId++;
}
}
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
object GetColumnValue(Item r, ExportColumn column)
{
switch (column.Key)
{
case "領據作廢":
return r..GetValueOrDefault() == 1 ? "V" : string.Empty;
case "勞務費作廢":
return r._作廢.GetValueOrDefault() == 1 ? "V" : string.Empty;
case "差旅費作廢":
return r._作廢.GetValueOrDefault() == 1 ? "V" : string.Empty;
default:
return r.FieldValue(column.FieldName);
}
}
}
}