Option Strict Off
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 System.Data.SqlClient
Public Class 營運成本收支單_對帳表
    ReadOnly conn1 As New SqlConnection
    ReadOnly cmd As New SqlCommand : ReadOnly cmd1 As New SqlCommand
    ReadOnly ds As New DataSet
    Dim N2 As Integer
    Dim xlApp As Microsoft.Office.Interop.Excel.Application
    Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
    Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
    Dim 位置1 As String
    Private Sub Set_清單1()
        明細_dgv.DataSource = Nothing : ds.Clear()
        明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        明細_dgv.ColumnHeadersHeight = 25
        明細_dgv.AllowUserToAddRows = False
        明細_dgv.RowTemplate.Height = 30
        SQL_營運成本收支單對帳表_查詢最後一筆清單()
        da.Fill(ds) : 明細_dgv.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
    End Sub
    Private Sub Set_grid()
        明細_dgv.Columns(0).FillWeight = 120 : 明細_dgv.Columns(1).FillWeight = 60 : 明細_dgv.Columns(2).FillWeight = 80 : 明細_dgv.Columns(3).FillWeight = 60
        明細_dgv.Columns(4).FillWeight = 80 : 明細_dgv.Columns(5).FillWeight = 50 : 明細_dgv.Columns(6).FillWeight = 150 : 明細_dgv.Columns(7).FillWeight = 300
        明細_dgv.Columns(8).FillWeight = 70 : 明細_dgv.Columns(9).FillWeight = 70 : 明細_dgv.Columns(10).FillWeight = 70 : 明細_dgv.Columns(11).FillWeight = 70
        明細_dgv.Columns(12).FillWeight = 70 : 明細_dgv.Columns(13).FillWeight = 50 : 明細_dgv.Columns(14).FillWeight = 70 : 明細_dgv.Columns(15).FillWeight = 50
        明細_dgv.Columns(16).FillWeight = 70 : 明細_dgv.Columns(17).Visible = False : 明細_dgv.Columns(18).Visible = False : 明細_dgv.Columns(19).Visible = False
        明細_dgv.Columns(20).Visible = False : 明細_dgv.Columns(21).FillWeight = 50 : 明細_dgv.Columns(22).FillWeight = 50

        If 隱藏申請審核資訊_cb.Checked = False Then
            明細_dgv.Columns(1).Visible = True : 明細_dgv.Columns(2).Visible = True : 明細_dgv.Columns(3).Visible = True : 明細_dgv.Columns(4).Visible = True
        Else
            明細_dgv.Columns(1).Visible = False : 明細_dgv.Columns(2).Visible = False : 明細_dgv.Columns(3).Visible = False : 明細_dgv.Columns(4).Visible = False
        End If

        If 隱藏作帳點交資訊_cb.Checked = False Then
            明細_dgv.Columns(13).Visible = True : 明細_dgv.Columns(14).Visible = True : 明細_dgv.Columns(15).Visible = True : 明細_dgv.Columns(16).Visible = True
        Else
            明細_dgv.Columns(13).Visible = False : 明細_dgv.Columns(14).Visible = False : 明細_dgv.Columns(15).Visible = False : 明細_dgv.Columns(16).Visible = False
        End If

        明細_dgv.Columns(8).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(9).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(10).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns(11).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(21).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(21).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(22).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(22).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        支出1_tb.Text = "0" : 現金1_tb.Text = "0" : 損益1_tb.Text = "0" : 零用金1_tb.Text = "0" : 已兌現支票1_tb.Text = "0" : 未兌現支票1_tb.Text = "0"
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            現金1_tb.Text = Val(現金1_tb.Text) + 明細_dgv.Rows(i).Cells("現金").Value * 明細_dgv.Rows(i).Cells("匯率").Value
            支出1_tb.Text = Val(支出1_tb.Text) + 明細_dgv.Rows(i).Cells("支出").Value * 明細_dgv.Rows(i).Cells("匯率").Value
            零用金1_tb.Text = Val(零用金1_tb.Text) + 明細_dgv.Rows(i).Cells("零用金").Value * 明細_dgv.Rows(i).Cells("匯率").Value
            If 明細_dgv(9, i).Value <> 0 And 明細_dgv(18, i).Value = True Then
                已兌現支票1_tb.Text = Val(已兌現支票1_tb.Text) + 明細_dgv.Rows(i).Cells("支票").Value * 明細_dgv.Rows(i).Cells("匯率").Value
            ElseIf 明細_dgv(9, i).Value <> 0 And 明細_dgv(18, i).Value = False Then
                未兌現支票1_tb.Text = Val(未兌現支票1_tb.Text) + 明細_dgv.Rows(i).Cells("支票").Value * 明細_dgv.Rows(i).Cells("匯率").Value
            End If
            If 明細_dgv("幣別", i).Value = "台幣現金" Then : 明細_dgv("幣別", i).Value = "台幣" : Else : 明細_dgv("幣別", i).Value = "人民幣" : End If
        Next i
        損益1_tb.Text = Val(已兌現支票1_tb.Text) + Val(零用金1_tb.Text) + Val(現金1_tb.Text) - Val(支出1_tb.Text)
        If Val(損益1_tb.Text) > 0 Then : 損益1_tb.ForeColor = Color.Blue : Else : 損益1_tb.ForeColor = Color.Red : End If

        支出1_tb.Text = Strings.Format(Val(支出1_tb.Text), "#,##0")
        損益1_tb.Text = Strings.Format(Val(損益1_tb.Text), "#,##0")
        現金1_tb.Text = Strings.Format(Val(現金1_tb.Text), "#,##0")
        零用金1_tb.Text = Strings.Format(Val(零用金1_tb.Text), "#,##0")
        已兌現支票1_tb.Text = Strings.Format(Val(已兌現支票1_tb.Text), "#,##0")
        未兌現支票1_tb.Text = Strings.Format(Val(未兌現支票1_tb.Text), "#,##0")
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn.Close()
        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
        Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        現金_tb.Text = "0" : 支出_tb.Text = "0" : 損益_tb.Text = "0" : 零用金_tb.Text = "0" : 已兌現支票_tb.Text = "0" : 未兌現支票_tb.Text = "0"
        現金1_tb.Text = "0" : 支出1_tb.Text = "0" : 損益1_tb.Text = "0" : 零用金1_tb.Text = "0" : 已兌現支票1_tb.Text = "0" : 未兌現支票1_tb.Text = "0"
        SQL_營運成本收支單對帳表_修改會計() : conn.Close()
        SQL_營運成本收支單對帳表_修改出納() : conn.Close()
        SQL_營運成本收支單對帳表_修改現金() : conn.Close()
        SQL_營運成本收支單對帳表_修改備用金() : conn.Close()
        SQL_營運成本收支單對帳表_修改公帳() : conn.Close()
        SQL_營運成本收支單對帳表_修改支票() : conn.Close()
        SQL_營運成本收支單對帳表_修改日期() : conn.Close()
        SQL_營運成本收支單對帳表_修改出納日期() : conn.Close()

        ComboBox1下拉表單資料載入()
        查詢日期_cb.Text = Year(Today) : 查詢日期1_cb.SelectedIndex = Month(Today) - 1
        PA20 = "" : PA19 = "" : PA18 = "" : PA17 = 查詢日期_cb.Text : PA16 = 查詢日期1_cb.Text
        PA20 = "AND (公帳控制表.審核日期 LIKE '" & PA17 & "/" & PA16 & "%') "
        If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9 : 隱藏申請審核資訊_cb.Checked = False
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 7.6 : 隱藏申請審核資訊_cb.Checked = True
        End If
    End Sub
    Private Sub 營運成本收支單_對帳表_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9 : 隱藏申請審核資訊_cb.Checked = False
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 7.6 : 隱藏申請審核資訊_cb.Checked = True
        End If
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 清除查詢資料_bt.Click
        ComboBox1下拉表單資料載入()
        查詢日期1_cb.Items.Clear()
        查詢日期1_cb.Items.Add("01") : 查詢日期1_cb.Items.Add("02") : 查詢日期1_cb.Items.Add("03") : 查詢日期1_cb.Items.Add("04") : 查詢日期1_cb.Items.Add("05") : 查詢日期1_cb.Items.Add("06")
        查詢日期1_cb.Items.Add("07") : 查詢日期1_cb.Items.Add("08") : 查詢日期1_cb.Items.Add("09") : 查詢日期1_cb.Items.Add("10") : 查詢日期1_cb.Items.Add("11") : 查詢日期1_cb.Items.Add("12")
        PA17 = "" : PA16 = "" : PA20 = ""
        明細_dgv.DataSource = Nothing : ds.Clear()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 對帳記錄存檔_bt.Click

        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            PA15 = 明細_dgv.Rows(i).Cells("現金點交").Value
            PA14 = 明細_dgv.Rows(i).Cells("零用金點交").Value
            PA13 = 明細_dgv.Rows(i).Cells("支出點交").Value
            PA12 = 明細_dgv.Rows(i).Cells("支票兌現").Value
            PA11 = 明細_dgv.Rows(i).Cells("收支單號").Value
            PA10 = 明細_dgv.Rows(i).Cells("項次").Value
            資料數 = 明細_dgv.Rows.Count : MyModule1.進度條()
            SQL_營運成本收支單對帳表_修改對帳記錄存檔() : conn1.Close()
        Next
        MsgBox("存檔完成。") : Set_清單1() : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub 總金額計算()
        Dim FFGG As Integer = 0 : Dim GGHH As Integer = 0 : Dim HHJJ As Integer = 0 : Dim JJKK As Integer = 0 : Dim KKLL As Integer = 0
        現金_tb.Text = "0" : 支出_tb.Text = "0" : 損益_tb.Text = "0" : 零用金_tb.Text = "0" : 已兌現支票_tb.Text = "0" : 未兌現支票_tb.Text = "0"
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            If 明細_dgv.Rows(i).Cells("收支單號").Value = 收支單號_tb.Text Then
                FFGG = Val(FFGG) + 明細_dgv.Rows(i).Cells("現金").Value * 明細_dgv.Rows(i).Cells("匯率").Value
                GGHH = Val(GGHH) + 明細_dgv.Rows(i).Cells("支出").Value * 明細_dgv.Rows(i).Cells("匯率").Value
                HHJJ = Val(HHJJ) + 明細_dgv.Rows(i).Cells("零用金").Value * 明細_dgv.Rows(i).Cells("匯率").Value
                If 明細_dgv(9, i).Value <> 0 And 明細_dgv(18, i).Value = True Then
                    JJKK = Val(JJKK) + 明細_dgv.Rows(i).Cells("支票").Value * 明細_dgv.Rows(i).Cells("匯率").Value
                ElseIf 明細_dgv(9, i).Value <> 0 And 明細_dgv(18, i).Value = False Then
                    KKLL = Val(KKLL) + 明細_dgv.Rows(i).Cells("支票").Value * 明細_dgv.Rows(i).Cells("匯率").Value
                End If
            End If
        Next i
        現金_tb.Text = FFGG : 支出_tb.Text = GGHH : 零用金_tb.Text = HHJJ : 已兌現支票_tb.Text = JJKK : 未兌現支票_tb.Text = KKLL
        損益_tb.Text = JJKK + HHJJ + FFGG - GGHH
        If Val(損益_tb.Text) > 0 Then : 損益_tb.ForeColor = Color.Blue : Else : 損益_tb.ForeColor = Color.Red : End If
        現金_tb.Text = Strings.Format(Val(現金_tb.Text), "#,##0") : 支出_tb.Text = Strings.Format(Val(支出_tb.Text), "#,##0") : 損益_tb.Text = Strings.Format(Val(損益_tb.Text), "#,##0")
        零用金_tb.Text = Strings.Format(Val(零用金_tb.Text), "#,##0") : 已兌現支票_tb.Text = Strings.Format(Val(已兌現支票_tb.Text), "#,##0") : 未兌現支票_tb.Text = Strings.Format(Val(未兌現支票_tb.Text), "#,##0")
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 明細_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            收支單號_tb.Text = 明細_dgv.Rows(e.RowIndex).Cells("收支單號").Value
            總金額計算()
        End If
    End Sub
    Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 明細_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 明細_dgv.Rows.Count - 1 Then
            Exit Sub
        Else
            If 明細_dgv(0, e.RowIndex).Value.ToString <> 明細_dgv(0, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(明細_dgv.RowHeadersVisible, 明細_dgv.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 明細_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            If 明細_dgv(9, i).Value <> 0 And 明細_dgv(18, i).Value = True Then
                明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
            ElseIf 明細_dgv(9, i).Value <> 0 And 明細_dgv(18, i).Value = False Then
                明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
            End If
        Next
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 查詢日期_cb.SelectedIndexChanged
        PA17 = 查詢日期_cb.Text
        If PA17 = "" Or PA16 = "" Then
        Else
            PA20 = "AND (公帳控制表.審核日期 LIKE '" & PA17 & "/" & PA16 & "%') "
            Set_清單1()
        End If
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 查詢日期1_cb.SelectedIndexChanged
        PA16 = 查詢日期1_cb.Text
        If PA17 = "" Or PA16 = "" Then
        Else
            PA20 = "AND (公帳控制表.審核日期 LIKE '" & PA17 & "/" & PA16 & "%') "
            Set_清單1()
        End If
    End Sub
    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles 只顯示支票資料_cb.Click
        If 只顯示支票資料_cb.Checked = False Then
            PA19 = ""
            Set_清單1()
        Else
            PA19 = " AND (公帳流水帳.支票數 <> 0) "
            Set_清單1()
        End If
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles 隱藏申請審核資訊_cb.Click
        Set_grid()
    End Sub
    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles 隱藏作帳點交資訊_cb.Click
        Set_grid()
    End Sub
    '-----------------------------滑鼠右鍵--------------------------------------------------------------------------------------------------------------------------------------
    Private Sub BBBToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BBBToolStripMenuItem.Click
        MsgBox("待開發。")
        '列印_零用金支付明細.ShowDialog()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 關鍵字查詢_bt.Click
        PA = InputBox("請輸入要查詢的關鍵字。")
        PA18 = " AND (公帳控制表.支付單號 LIKE N'%" & PA & "%' OR 公帳控制表.申請人 LIKE N'%" & PA & "%' OR 公帳控制表.審核人 LIKE N'%" & PA &
                 "%' OR 公帳流水帳.明細 LIKE N'%" & PA & "%' OR 公帳控制表.備註 LIKE N'%" & PA & "%' OR 公帳流水帳.備註 LIKE N'%" & PA & "%')" : Set_清單1()
        PA18 = "" : PA = ""
    End Sub

    '-----------------------------EXCEL--------------------------------------------------------------------------------------------------------------------------------------
    Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
        Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
    End Function
    Private Sub 匯出EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.Click
        xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
        xlApp.Visible = True
        xlApp.DisplayAlerts = True
        xlApp.Application.WindowState = xlMaximized
        xlBook = xlApp.Workbooks.Add
        xlSheet = NewMethod(xlBook)
        xlBook.Activate()
        xlSheet.Activate()

        xlSheet.Cells(1, 1) = "雅邸家具有限公司-營運費用收支明細表"
        xlSheet.Cells(2, 1) = "收支單號 "
        xlSheet.Cells(2, 2) = "申請人"
        xlSheet.Cells(2, 3) = "申請日期 "
        xlSheet.Cells(2, 4) = "審核人"
        xlSheet.Cells(2, 5) = "審核日期"
        xlSheet.Cells(2, 6) = "項次"
        xlSheet.Cells(2, 7) = "會計科目 "
        xlSheet.Cells(2, 8) = "用途與內容"
        xlSheet.Cells(2, 9) = "零用金"
        xlSheet.Cells(2, 10) = "支票"
        xlSheet.Cells(2, 11) = "現金"
        xlSheet.Cells(2, 12) = "支出"

        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            xlSheet.Cells(i + 3, 1) = 明細_dgv.Rows(i).Cells("收支單號").Value
            xlSheet.Cells(i + 3, 2) = 明細_dgv.Rows(i).Cells("申請人").Value
            xlSheet.Cells(i + 3, 3) = 明細_dgv.Rows(i).Cells("申請日期").Value
            xlSheet.Cells(i + 3, 4) = 明細_dgv.Rows(i).Cells("審核人").Value
            xlSheet.Cells(i + 3, 5) = 明細_dgv.Rows(i).Cells("審核日期").Value
            xlSheet.Cells(i + 3, 6) = 明細_dgv.Rows(i).Cells("項次").Value
            xlSheet.Cells(i + 3, 7) = 明細_dgv.Rows(i).Cells("會計科目").Value
            xlSheet.Cells(i + 3, 8) = 明細_dgv.Rows(i).Cells("用途與內容").Value
            xlSheet.Cells(i + 3, 9) = 明細_dgv.Rows(i).Cells("零用金").Value
            xlSheet.Cells(i + 3, 10) = 明細_dgv.Rows(i).Cells("支票").Value
            xlSheet.Cells(i + 3, 11) = 明細_dgv.Rows(i).Cells("現金").Value
            xlSheet.Cells(i + 3, 12) = 明細_dgv.Rows(i).Cells("支出").Value
            N2 = i + 3
        Next i

        xlSheet.Cells(N2 + 1, 8) = "合計"
        xlSheet.Cells(N2 + 1, 9) = "=SUM(I3:I" & N2 & ")"
        xlSheet.Cells(N2 + 1, 10) = "=SUM(J3:J" & N2 & ")"
        xlSheet.Cells(N2 + 1, 11) = "=SUM(K3:K" & N2 & ")"
        xlSheet.Cells(N2 + 1, 12) = "=SUM(L3:L" & N2 & ")"

        '--------------------------------------彙總-----------------------------
        xlSheet.Cells(N2 + 2, 8) = "彙總"
        xlSheet.Cells(N2 + 2, 9) = "=I" & N2 + 1 & "+J" & N2 + 1 & "+K" & N2 + 1 & "-L" & N2 + 1 & ""

        BB(xlApp, xlSheet)
        xlSheet.PageSetup.PrintArea = ""
        xlApp.Cells.Select()
        xlApp.Application.WindowState = xlMinimized
        MsgBox("列印完成!!!")
        'Me.Close()
    End Sub
    Private Sub BB(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 = 15
        xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 5
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With

        xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 20
        xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 35
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With

        xlSheet.Columns("I:L").Select : myExcel.Selection.ColumnWidth = 9 : myExcel.Selection.Style = "Comma"
        myExcel.Selection.NumberFormatLocal = "_-* #,##0.0_-;-* #,##0.0_-;_-* ""-""??_-;_-@_-"
        myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
        xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 35
        xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 30
        With myExcel.Selection : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False
        End With

        myExcel.Selection.AutoFilter
        xlSheet.Rows("1: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("A1:L1").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
        xlSheet.Rows("3:3").Select : myExcel.ActiveWindow.FreezePanes = True : xlSheet.Range("A1:L2").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
        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
        With myExcel.Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin
        End With
        xlSheet.Range("A3:L" & N2).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
        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
        With myExcel.Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin
        End With
        xlSheet.Range("L2").Select() : myExcel.Selection.ClearContents
        xlSheet.Range("L2").Select() : myExcel.Selection.ClearContents

        xlSheet.Range("A2:L2").Select()
        With myExcel.Selection
            .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        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
        With myExcel.Selection.Font
            .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
        With myExcel.Selection.Interior
            .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent6 : .TintAndShade = 0 : .PatternTintAndShade = 0
        End With
        xlSheet.Range("A1:L1").Select() : myExcel.Selection.Font.Size = 11
        With myExcel.Selection.Font
            .Name = "微軟正黑體" : .Size = 22 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
    End Sub

    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
    End Sub
End Class