Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
Imports Microsoft.Office.Interop.Excel.Constants
Imports Microsoft.Office.Interop.Excel.XlBordersIndex
Imports Microsoft.Office.Interop.Excel.XlLineStyle
Imports Microsoft.Office.Interop.Excel.XlBorderWeight
Imports Microsoft.Office.Interop.Excel.XlThemeFont
Imports Microsoft.Office.Interop.Excel.XlThemeColor
Imports Microsoft.Office.Interop.Excel.XlWindowState
Imports Microsoft.Office.Interop.Excel.XlPageOrientation
Imports Microsoft.Office.Interop.Excel
Public Class 薪資表
    Dim 剛開啟 As Boolean : Dim 位置1 As Integer
    Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
    Private Sub 讀取打卡時間1()
        Dim ds1, ds2 As New DataSet
        月清單_dgv.DataSource = Nothing : ds1.Clear()
        月清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月清單_dgv.ColumnHeadersHeight = 45 : 月清單_dgv.AllowUserToAddRows = False
        SQL_薪資表讀取()
        da.Fill(ds1) : 月清單_dgv.DataSource = ds1.Tables(0) : conn.Close()

        合計_dgv.DataSource = Nothing : ds2.Clear()
        合計_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        合計_dgv.ColumnHeadersHeight = 45 : 合計_dgv.AllowUserToAddRows = False : 合計_dgv.ColumnHeadersVisible = False
        SQL_薪資表讀取_合計()
        da.Fill(ds2) : 合計_dgv.DataSource = ds2.Tables(0) : conn.Close()
        格式設定()
    End Sub
    Private Sub 格式設定()
        月清單_dgv.Columns("項").FillWeight = 50 : 月清單_dgv.Columns("實上工時").FillWeight = 80 : 月清單_dgv.Columns("基本時薪").FillWeight = 80
        月清單_dgv.Columns("主管加級").FillWeight = 90 : 月清單_dgv.Columns("職務加級").FillWeight = 90 : 月清單_dgv.Columns("婚假").FillWeight = 80
        月清單_dgv.Columns("喪假").FillWeight = 80 : 月清單_dgv.Columns("其他說明").FillWeight = 150 : 月清單_dgv.Columns("其他").FillWeight = 80
        月清單_dgv.Columns("未到離職").FillWeight = 80 : 月清單_dgv.Columns("一段加班1").FillWeight = 80 : 月清單_dgv.Columns("一段加班2").FillWeight = 80
        月清單_dgv.Columns("二段加班1").FillWeight = 80 : 月清單_dgv.Columns("二段加班2").FillWeight = 80 : 月清單_dgv.Columns("國定假日1").FillWeight = 80
        月清單_dgv.Columns("國定假日2").FillWeight = 80 : 月清單_dgv.Columns("勞保費").FillWeight = 80 : 月清單_dgv.Columns("健保費").FillWeight = 80
        月清單_dgv.Columns("事假").FillWeight = 80 : 月清單_dgv.Columns("病假").FillWeight = 80 : 月清單_dgv.Columns("其他說明減").FillWeight = 150
        月清單_dgv.Columns("其他減").FillWeight = 80 : 月清單_dgv.Columns("姓名").FillWeight = 80

        月清單_dgv.Columns("基本月薪").DefaultCellStyle.BackColor = Color.MistyRose : 月清單_dgv.Columns("主管加級").DefaultCellStyle.BackColor = Color.MistyRose
        月清單_dgv.Columns("職務加級").DefaultCellStyle.BackColor = Color.MistyRose : 月清單_dgv.Columns("婚假").DefaultCellStyle.BackColor = Color.MistyRose
        月清單_dgv.Columns("喪假").DefaultCellStyle.BackColor = Color.MistyRose : 月清單_dgv.Columns("其他").DefaultCellStyle.BackColor = Color.MistyRose
        月清單_dgv.Columns("未到離職").DefaultCellStyle.BackColor = Color.MistyRose : 月清單_dgv.Columns("本薪").DefaultCellStyle.BackColor = Color.MistyRose
        月清單_dgv.Columns("特休補錢").DefaultCellStyle.BackColor = Color.MistyRose

        月清單_dgv.Columns("一段加班1").DefaultCellStyle.BackColor = Color.LightSalmon : 月清單_dgv.Columns("一段加班2").DefaultCellStyle.BackColor = Color.LightSalmon
        月清單_dgv.Columns("二段加班1").DefaultCellStyle.BackColor = Color.LightSalmon : 月清單_dgv.Columns("二段加班2").DefaultCellStyle.BackColor = Color.LightSalmon
        月清單_dgv.Columns("國定假日1").DefaultCellStyle.BackColor = Color.LightSalmon : 月清單_dgv.Columns("國定假日2").DefaultCellStyle.BackColor = Color.LightSalmon
        月清單_dgv.Columns("加班費1").DefaultCellStyle.BackColor = Color.LightSalmon : 月清單_dgv.Columns("加班費2").DefaultCellStyle.BackColor = Color.LightSalmon
        月清單_dgv.Columns("應付小計1").DefaultCellStyle.BackColor = Color.LightSalmon : 月清單_dgv.Columns("應付小計2").DefaultCellStyle.BackColor = Color.LightSalmon

        月清單_dgv.Columns("勞保費").DefaultCellStyle.BackColor = Color.LightCyan : 月清單_dgv.Columns("健保費").DefaultCellStyle.BackColor = Color.LightCyan
        月清單_dgv.Columns("事假").DefaultCellStyle.BackColor = Color.LightCyan : 月清單_dgv.Columns("病假").DefaultCellStyle.BackColor = Color.LightCyan
        月清單_dgv.Columns("其他減").DefaultCellStyle.BackColor = Color.LightCyan : 月清單_dgv.Columns("減項小計1").DefaultCellStyle.BackColor = Color.LightCyan

        月清單_dgv.Columns("實付小計1").DefaultCellStyle.BackColor = Color.LightGreen : 月清單_dgv.Columns("實付小計2").DefaultCellStyle.BackColor = Color.LightGreen

        月清單_dgv.Columns("日期").Visible = False : 月清單_dgv.Columns("到職日").Visible = False : 月清單_dgv.Columns("全勤").Visible = False
        月清單_dgv.Columns("月薪").Visible = False : 月清單_dgv.Columns("時薪").Visible = False : 月清單_dgv.Columns("特休未修").Visible = False
        月清單_dgv.Columns("當月天數").Visible = False : 月清單_dgv.Columns("減項小計2").Visible = False : 月清單_dgv.Columns("實上基數").Visible = False
        月清單_dgv.Columns("時薪特休").Visible = False
        For i As Integer = 4 To 16
            月清單_dgv.Columns(i).DefaultCellStyle.Format = "#,##0" : 月清單_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 18 To 36
            月清單_dgv.Columns(i).DefaultCellStyle.Format = "#,##0" : 月清單_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 23 To 25
            月清單_dgv.Columns(i).DefaultCellStyle.Format = "#,##0.0" : 月清單_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 28 To 30
            月清單_dgv.Columns(i).DefaultCellStyle.Format = "#,##0.0" : 月清單_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 38 To 42
            月清單_dgv.Columns(i).DefaultCellStyle.Format = "#,##0" : 月清單_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next

        If 彈性工時_cb.Checked = True Then
            月清單_dgv.Columns("一段加班2").Visible = True : 月清單_dgv.Columns("二段加班2").Visible = True : 月清單_dgv.Columns("國定假日2").Visible = True
            月清單_dgv.Columns("加班費2").Visible = True : 月清單_dgv.Columns("應付小計2").Visible = True : 月清單_dgv.Columns("實付小計2").Visible = True

            月清單_dgv.Columns("一段加班1").Visible = False : 月清單_dgv.Columns("二段加班1").Visible = False : 月清單_dgv.Columns("國定假日1").Visible = False
            月清單_dgv.Columns("加班費1").Visible = False : 月清單_dgv.Columns("應付小計1").Visible = False : 月清單_dgv.Columns("實付小計1").Visible = False
        Else
            月清單_dgv.Columns("一段加班2").Visible = False : 月清單_dgv.Columns("二段加班2").Visible = False : 月清單_dgv.Columns("國定假日2").Visible = False
            月清單_dgv.Columns("加班費2").Visible = False : 月清單_dgv.Columns("應付小計2").Visible = False : 月清單_dgv.Columns("實付小計2").Visible = False

            月清單_dgv.Columns("一段加班1").Visible = True : 月清單_dgv.Columns("二段加班1").Visible = True : 月清單_dgv.Columns("國定假日1").Visible = True
            月清單_dgv.Columns("加班費1").Visible = True : 月清單_dgv.Columns("應付小計1").Visible = True : 月清單_dgv.Columns("實付小計1").Visible = True
        End If
        For i As Integer = 0 To 月清單_dgv.Rows.Count - 1
            月清單_dgv("項", i).Value = i + 1
            月清單_dgv("特休補錢", i).Value = 月清單_dgv("特休補錢", i).Value + 月清單_dgv("時薪特休", i).Value
        Next

        合計_dgv.Columns("項").FillWeight = 50 : 合計_dgv.Columns("實上工時").FillWeight = 80 : 合計_dgv.Columns("基本時薪").FillWeight = 80
        合計_dgv.Columns("主管加級").FillWeight = 90 : 合計_dgv.Columns("職務加級").FillWeight = 90 : 合計_dgv.Columns("婚假").FillWeight = 80
        合計_dgv.Columns("喪假").FillWeight = 80 : 合計_dgv.Columns("其他說明").FillWeight = 150 : 合計_dgv.Columns("其他").FillWeight = 80
        合計_dgv.Columns("未到離職").FillWeight = 80 : 合計_dgv.Columns("一段加班1").FillWeight = 80 : 合計_dgv.Columns("一段加班2").FillWeight = 80
        合計_dgv.Columns("二段加班1").FillWeight = 80 : 合計_dgv.Columns("二段加班2").FillWeight = 80 : 合計_dgv.Columns("國定假日1").FillWeight = 80
        合計_dgv.Columns("國定假日2").FillWeight = 80 : 合計_dgv.Columns("勞保費").FillWeight = 80 : 合計_dgv.Columns("健保費").FillWeight = 80
        合計_dgv.Columns("事假").FillWeight = 80 : 合計_dgv.Columns("病假").FillWeight = 80 : 合計_dgv.Columns("其他說明減").FillWeight = 150
        合計_dgv.Columns("其他減").FillWeight = 80 : 合計_dgv.Columns("姓名").FillWeight = 80

        合計_dgv.Columns("基本月薪").DefaultCellStyle.BackColor = Color.MistyRose : 合計_dgv.Columns("主管加級").DefaultCellStyle.BackColor = Color.MistyRose
        合計_dgv.Columns("職務加級").DefaultCellStyle.BackColor = Color.MistyRose : 合計_dgv.Columns("婚假").DefaultCellStyle.BackColor = Color.MistyRose
        合計_dgv.Columns("喪假").DefaultCellStyle.BackColor = Color.MistyRose : 合計_dgv.Columns("其他").DefaultCellStyle.BackColor = Color.MistyRose
        合計_dgv.Columns("未到離職").DefaultCellStyle.BackColor = Color.MistyRose : 合計_dgv.Columns("本薪").DefaultCellStyle.BackColor = Color.MistyRose
        合計_dgv.Columns("特休補錢").DefaultCellStyle.BackColor = Color.MistyRose

        合計_dgv.Columns("一段加班1").DefaultCellStyle.BackColor = Color.LightSalmon : 合計_dgv.Columns("一段加班2").DefaultCellStyle.BackColor = Color.LightSalmon
        合計_dgv.Columns("二段加班1").DefaultCellStyle.BackColor = Color.LightSalmon : 合計_dgv.Columns("二段加班2").DefaultCellStyle.BackColor = Color.LightSalmon
        合計_dgv.Columns("國定假日1").DefaultCellStyle.BackColor = Color.LightSalmon : 合計_dgv.Columns("國定假日2").DefaultCellStyle.BackColor = Color.LightSalmon
        合計_dgv.Columns("加班費1").DefaultCellStyle.BackColor = Color.LightSalmon : 合計_dgv.Columns("加班費2").DefaultCellStyle.BackColor = Color.LightSalmon
        合計_dgv.Columns("應付小計1").DefaultCellStyle.BackColor = Color.LightSalmon : 合計_dgv.Columns("應付小計2").DefaultCellStyle.BackColor = Color.LightSalmon

        合計_dgv.Columns("勞保費").DefaultCellStyle.BackColor = Color.LightCyan : 合計_dgv.Columns("健保費").DefaultCellStyle.BackColor = Color.LightCyan
        合計_dgv.Columns("事假").DefaultCellStyle.BackColor = Color.LightCyan : 合計_dgv.Columns("病假").DefaultCellStyle.BackColor = Color.LightCyan
        合計_dgv.Columns("其他減").DefaultCellStyle.BackColor = Color.LightCyan : 合計_dgv.Columns("減項小計1").DefaultCellStyle.BackColor = Color.LightCyan

        合計_dgv.Columns("實付小計1").DefaultCellStyle.BackColor = Color.LightGreen : 合計_dgv.Columns("實付小計2").DefaultCellStyle.BackColor = Color.LightGreen

        合計_dgv.Columns("日期").Visible = False : 合計_dgv.Columns("到職日").Visible = False : 合計_dgv.Columns("全勤").Visible = False
        合計_dgv.Columns("月薪").Visible = False : 合計_dgv.Columns("時薪").Visible = False : 合計_dgv.Columns("特休未修").Visible = False
        合計_dgv.Columns("當月天數").Visible = False : 合計_dgv.Columns("減項小計2").Visible = False : 合計_dgv.Columns("實上基數").Visible = False
        合計_dgv.Columns("時薪特休").Visible = False
        For i As Integer = 4 To 16
            合計_dgv.Columns(i).DefaultCellStyle.Format = "#,##0" : 合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 18 To 36
            合計_dgv.Columns(i).DefaultCellStyle.Format = "#,##0" : 合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 23 To 25
            合計_dgv.Columns(i).DefaultCellStyle.Format = "#,##0.0" : 合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 28 To 30
            合計_dgv.Columns(i).DefaultCellStyle.Format = "#,##0.0" : 合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next
        For i As Integer = 38 To 42
            合計_dgv.Columns(i).DefaultCellStyle.Format = "#,##0" : 合計_dgv.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        Next

        If 彈性工時_cb.Checked = True Then
            合計_dgv.Columns("一段加班2").Visible = True : 合計_dgv.Columns("二段加班2").Visible = True : 合計_dgv.Columns("國定假日2").Visible = True
            合計_dgv.Columns("加班費2").Visible = True : 合計_dgv.Columns("應付小計2").Visible = True : 合計_dgv.Columns("實付小計2").Visible = True

            合計_dgv.Columns("一段加班1").Visible = False : 合計_dgv.Columns("二段加班1").Visible = False : 合計_dgv.Columns("國定假日1").Visible = False
            合計_dgv.Columns("加班費1").Visible = False : 合計_dgv.Columns("應付小計1").Visible = False : 合計_dgv.Columns("實付小計1").Visible = False
        Else
            合計_dgv.Columns("一段加班2").Visible = False : 合計_dgv.Columns("二段加班2").Visible = False : 合計_dgv.Columns("國定假日2").Visible = False
            合計_dgv.Columns("加班費2").Visible = False : 合計_dgv.Columns("應付小計2").Visible = False : 合計_dgv.Columns("實付小計2").Visible = False

            合計_dgv.Columns("一段加班1").Visible = True : 合計_dgv.Columns("二段加班1").Visible = True : 合計_dgv.Columns("國定假日1").Visible = True
            合計_dgv.Columns("加班費1").Visible = True : 合計_dgv.Columns("應付小計1").Visible = True : 合計_dgv.Columns("實付小計1").Visible = True
        End If
        If 合計_dgv.Rows.Count > 0 Then
            合計_dgv("項", 0).Value = "" : 合計_dgv("姓名", 0).Value = "" : 合計_dgv("實上工時", 0).Value = "0" : 合計_dgv("基本月薪", 0).Value = "0"
            合計_dgv("基本時薪", 0).Value = "0" : 合計_dgv("主管加級", 0).Value = "0" : 合計_dgv("其他說明", 0).Value = "" : 合計_dgv("婚假", 0).Value = "0"
            合計_dgv("職務加級", 0).Value = "0" : 合計_dgv("喪假", 0).Value = "0" : 合計_dgv("其他", 0).Value = "0" : 合計_dgv("未到離職", 0).Value = "0"
            合計_dgv("本薪", 0).Value = "0" : 合計_dgv("一段加班1", 0).Value = "0" : 合計_dgv("一段加班2", 0).Value = "0" : 合計_dgv("二段加班1", 0).Value = "0"
            合計_dgv("二段加班2", 0).Value = "0" : 合計_dgv("國定假日1", 0).Value = "0" : 合計_dgv("國定假日2", 0).Value = "0" : 合計_dgv("加班費1", 0).Value = "0"
            合計_dgv("加班費2", 0).Value = "0" : 合計_dgv("應付小計1", 0).Value = "0" : 合計_dgv("應付小計2", 0).Value = "0" : 合計_dgv("其他說明減", 0).Value = ""
            合計_dgv("勞保費", 0).Value = "0" : 合計_dgv("健保費", 0).Value = "0" : 合計_dgv("事假", 0).Value = "0" : 合計_dgv("病假", 0).Value = "0"
            合計_dgv("其他減", 0).Value = "0" : 合計_dgv("減項小計1", 0).Value = "0" : 合計_dgv("實付小計1", 0).Value = "0" : 合計_dgv("實付小計2", 0).Value = "0"
            For i As Integer = 0 To 月清單_dgv.Rows.Count - 1
                合計_dgv("主管加級", 0).Value += 月清單_dgv("主管加級", i).Value : 合計_dgv("職務加級", 0).Value += 月清單_dgv("職務加級", i).Value
                合計_dgv("婚假", 0).Value += 月清單_dgv("婚假", i).Value : 合計_dgv("喪假", 0).Value += 月清單_dgv("喪假", i).Value
                合計_dgv("其他", 0).Value += 月清單_dgv("其他", i).Value : 合計_dgv("未到離職", 0).Value += 月清單_dgv("未到離職", i).Value
                合計_dgv("本薪", 0).Value += 月清單_dgv("本薪", i).Value : 合計_dgv("加班費1", 0).Value += 月清單_dgv("加班費1", i).Value
                合計_dgv("加班費2", 0).Value += 月清單_dgv("加班費2", i).Value : 合計_dgv("應付小計1", 0).Value += 月清單_dgv("應付小計1", i).Value
                合計_dgv("應付小計2", 0).Value += 月清單_dgv("應付小計2", i).Value : 合計_dgv("勞保費", 0).Value += 月清單_dgv("勞保費", i).Value
                合計_dgv("健保費", 0).Value += 月清單_dgv("健保費", i).Value : 合計_dgv("事假", 0).Value += 月清單_dgv("事假", i).Value
                合計_dgv("病假", 0).Value += 月清單_dgv("病假", i).Value : 合計_dgv("其他減", 0).Value += 月清單_dgv("其他減", i).Value
                合計_dgv("減項小計1", 0).Value += 月清單_dgv("減項小計1", i).Value : 合計_dgv("實付小計1", 0).Value += 月清單_dgv("實付小計1", i).Value
                合計_dgv("實付小計2", 0).Value += 月清單_dgv("實付小計2", i).Value
            Next
        End If
    End Sub
    Private Sub 年份_下拉表單資料載入()
        SQL_考勤明細表_年份_下拉()
        年份_cb.Items.Clear()
        While (dr.Read()) : 年份_cb.Items.Add(dr("年份")) : End While
        conn.Close()
    End Sub
    Private Sub 薪資表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        剛開啟 = True
    End Sub
    Private Sub 薪資表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        年份_下拉表單資料載入()
        年份_cb.Text = Year(Today) : 月份_cb.SelectedIndex = Month(Today) - 1
        PA1 = CInt(年份_cb.Text) - 1911 & "-" & 月份_cb.Text
        讀取打卡時間1() : 剛開啟 = False
    End Sub
    Private Sub R_bt_Click(sender As Object, e As EventArgs) Handles R_bt.Click
        PA1 = CInt(年份_cb.Text) - 1911 & "-" & 月份_cb.Text : 讀取打卡時間1()
    End Sub
    Private Sub 年份_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 年份_cb.SelectedIndexChanged
        If 剛開啟 = False Then : PA1 = CInt(年份_cb.Text) - 1911 & "-" & 月份_cb.Text : 讀取打卡時間1() : End If
    End Sub
    Private Sub 月份_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月份_cb.SelectedIndexChanged
        If 剛開啟 = False Then : PA1 = CInt(年份_cb.Text) - 1911 & "-" & 月份_cb.Text : 讀取打卡時間1() : End If
    End Sub
    Private Sub 彈性工時_cb_CheckedChanged(sender As Object, e As EventArgs) Handles 彈性工時_cb.Click
        彈性工時_cb.Checked = True : 正常工時_ch.Checked = False : 格式設定()
    End Sub
    Private Sub 正常工時_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 正常工時_ch.Click
        彈性工時_cb.Checked = False : 正常工時_ch.Checked = True : 格式設定()
    End Sub
    Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
        xlApp = CType(CreateObject("Excel.Application"), Application)
        xlBook = xlApp.Workbooks.Add
        xlApp.DisplayAlerts = True
        xlApp.Visible = True
        xlApp.Application.WindowState = xlMaximized

        xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Select
        xlApp.Sheets(1).Name = "薪資表" : xlBook.Activate() : xlSheet.Activate()

        xlSheet.Cells(1, 1) = "黃柏翰皮膚科診所薪資明細表" : xlSheet.Cells(2, 1) = CInt(年份_cb.Text) - 1911 & "年" & 月份_cb.Text & "月 - 全月"
        xlSheet.Cells(3, 1) = "項" : xlSheet.Cells(3, 2) = "姓名" : xlSheet.Cells(3, 3) = "工時" : xlSheet.Cells(3, 4) = "基本月薪" : xlSheet.Cells(3, 5) = "基本時薪"
        xlSheet.Cells(3, 6) = "主管加級" : xlSheet.Cells(3, 7) = "職務加級" : xlSheet.Cells(3, 8) = "特休" : xlSheet.Cells(3, 9) = "婚假" : xlSheet.Cells(3, 10) = "喪假"
        xlSheet.Cells(3, 11) = "其他說明" : xlSheet.Cells(3, 12) = "其他" : xlSheet.Cells(3, 13) = "未到/離職" : xlSheet.Cells(3, 14) = "本薪" : xlSheet.Cells(3, 15) = "一段加班"
        xlSheet.Cells(3, 16) = "二段加班" : xlSheet.Cells(3, 17) = "國定假日" : xlSheet.Cells(3, 18) = "加班費" : xlSheet.Cells(3, 19) = "應付小計" : xlSheet.Cells(3, 20) = "勞保費"
        xlSheet.Cells(3, 21) = "健保費" : xlSheet.Cells(3, 22) = "事假" : xlSheet.Cells(3, 23) = "病假" : xlSheet.Cells(3, 24) = "其他說明" : xlSheet.Cells(3, 25) = "其他"
        xlSheet.Cells(3, 26) = "減項小計" : xlSheet.Cells(3, 27) = "實付小計"
        For i As Integer = 0 To 月清單_dgv.Rows.Count - 1
            xlSheet.Cells(4 + i, 1) = 月清單_dgv("項", i).Value.ToString : xlSheet.Cells(4 + i, 2) = 月清單_dgv("姓名", i).Value.ToString
            xlSheet.Cells(4 + i, 3) = 月清單_dgv("實上工時", i).Value.ToString : xlSheet.Cells(4 + i, 4) = 月清單_dgv("基本月薪", i).Value.ToString
            xlSheet.Cells(4 + i, 5) = 月清單_dgv("基本時薪", i).Value.ToString : xlSheet.Cells(4 + i, 6) = 月清單_dgv("主管加級", i).Value.ToString
            xlSheet.Cells(4 + i, 7) = 月清單_dgv("職務加級", i).Value.ToString : xlSheet.Cells(4 + i, 8) = 月清單_dgv("特休補錢", i).Value.ToString
            xlSheet.Cells(4 + i, 9) = 月清單_dgv("婚假", i).Value.ToString : xlSheet.Cells(4 + i, 10) = 月清單_dgv("喪假", i).Value.ToString
            xlSheet.Cells(4 + i, 11) = 月清單_dgv("其他說明", i).Value.ToString : xlSheet.Cells(4 + i, 12) = 月清單_dgv("其他", i).Value.ToString
            xlSheet.Cells(4 + i, 13) = 月清單_dgv("未到離職", i).Value.ToString : xlSheet.Cells(4 + i, 14) = 月清單_dgv("本薪", i).Value.ToString
            If 彈性工時_cb.Checked = True Then
                xlSheet.Cells(4 + i, 15) = 月清單_dgv("一段加班2", i).Value.ToString : xlSheet.Cells(4 + i, 16) = 月清單_dgv("二段加班2", i).Value.ToString
                xlSheet.Cells(4 + i, 17) = 月清單_dgv("國定假日2", i).Value.ToString : xlSheet.Cells(4 + i, 18) = 月清單_dgv("加班費2", i).Value.ToString
                xlSheet.Cells(4 + i, 19) = 月清單_dgv("應付小計2", i).Value.ToString : xlSheet.Cells(4 + i, 27) = 月清單_dgv("實付小計2", i).Value.ToString
            Else
                xlSheet.Cells(4 + i, 15) = 月清單_dgv("一段加班1", i).Value.ToString : xlSheet.Cells(4 + i, 16) = 月清單_dgv("二段加班1", i).Value.ToString
                xlSheet.Cells(4 + i, 17) = 月清單_dgv("國定假日1", i).Value.ToString : xlSheet.Cells(4 + i, 18) = 月清單_dgv("加班費1", i).Value.ToString
                xlSheet.Cells(4 + i, 19) = 月清單_dgv("應付小計1", i).Value.ToString : xlSheet.Cells(4 + i, 27) = 月清單_dgv("實付小計1", i).Value.ToString
            End If
            xlSheet.Cells(4 + i, 20) = 月清單_dgv("勞保費", i).Value.ToString : xlSheet.Cells(4 + i, 21) = 月清單_dgv("健保費", i).Value.ToString
            xlSheet.Cells(4 + i, 22) = 月清單_dgv("事假", i).Value.ToString : xlSheet.Cells(4 + i, 23) = 月清單_dgv("病假", i).Value.ToString
            xlSheet.Cells(4 + i, 24) = 月清單_dgv("其他說明", i).Value.ToString : xlSheet.Cells(4 + i, 25) = 月清單_dgv("其他", i).Value.ToString
            xlSheet.Cells(4 + i, 26) = 月清單_dgv("減項小計1", i).Value.ToString
        Next : 位置1 = 4 + 月清單_dgv.Rows.Count - 1

        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 6) = 合計_dgv("主管加級", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 9) = 合計_dgv("婚假", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 7) = 合計_dgv("職務加級", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 26) = 合計_dgv("減項小計1", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 8) = 合計_dgv("特休補錢", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 10) = 合計_dgv("喪假", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 11) = 合計_dgv("其他說明", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 12) = 合計_dgv("其他", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 13) = 合計_dgv("未到離職", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 14) = 合計_dgv("本薪", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 20) = 合計_dgv("勞保費", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 21) = 合計_dgv("健保費", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 22) = 合計_dgv("事假", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 23) = 合計_dgv("病假", 0).Value.ToString
        xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 25) = 合計_dgv("其他", 0).Value.ToString
        If 彈性工時_cb.Checked = True Then
            xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 18) = 合計_dgv("加班費2", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 19) = 合計_dgv("應付小計2", 0).Value.ToString
            xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 27) = 合計_dgv("實付小計2", 0).Value.ToString
        Else
            xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 18) = 合計_dgv("加班費1", 0).Value.ToString : xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 19) = 合計_dgv("應付小計1", 0).Value.ToString
            xlSheet.Cells(5 + 月清單_dgv.Rows.Count, 27) = 合計_dgv("實付小計1", 0).Value.ToString
        End If : AA(xlApp, xlSheet)

        xlSheet.PageSetup.PrintArea = "" : xlApp.Cells.Select() : xlSheet.Range("B1").Select() : xlApp.Application.WindowState = xlMinimized : MsgBox("列印完成")
    End Sub
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
        xlSheet.Cells.Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 3
        xlSheet.Columns("C:AA").Select : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
        xlSheet.Columns("B:AA").Select : myExcel.Columns("B:AA").EntireColumn.AutoFit
        xlSheet.Rows("3:" & 位置1).Select : myExcel.Selection.RowHeight = 25
        myExcel.Range("A3:AA" & 位置1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        xlSheet.Rows(位置1 + 1 & ":" & 位置1 + 1).Select : myExcel.Selection.RowHeight = 5
        myExcel.ActiveWindow.DisplayGridlines = False
        xlSheet.Range("A3:A" & 位置1).Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("A3:AA3").Select() : myExcel.Application.WindowState = xlNormal
        xlSheet.Range("C3:D" & 位置1).Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent6 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("F3:N3").Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("N4:N" & 位置1).Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("O3:S3").Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("S4:S" & 位置1).Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("T3:U" & 位置1).Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorDark2 : .TintAndShade = -0.0999786370433668
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("V3:Z3").Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("Z4:Z" & 位置1).Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0 : End With
        xlSheet.Range("AA3:AA" & 位置1 + 2).Select()
        With myExcel.Selection.Font : .Color = -16776961 : .TintAndShade = 0 : End With
        xlSheet.Range("A3:AA3").Select() : myExcel.Selection.Font.Bold = True
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        xlSheet.Range("A2:AA2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        xlSheet.Range("A1:AA1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 18 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        myExcel.Selection.Font.Bold = True
        xlSheet.Range("A3:AA3").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("A4:AA" & 位置1 + 2).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
    End Sub
End Class