Option Strict Off
Imports System.Data.SqlClient
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
Public Class 列印_生產進度表
    ReadOnly conn As New SqlConnection
    ReadOnly da As New SqlDataAdapter
    ReadOnly cmd As New SqlCommand
    ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet
    Dim xlApp As Application
    Dim xlBook As Workbook
    Dim xlSheet As Worksheet
    Public Property ThisWorkbook As Object
    Public Property ActiveWorkbook As Object
    Dim N1 As Integer = 0
    Dim ASS As String
    Private Sub Set_工廠清單()
        工廠_DGV.DataSource = Nothing : ds1.Clear()
        工廠_DGV.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        工廠_DGV.ColumnHeadersHeight = 25
        工廠_DGV.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT METOO選擇按鈕.選擇, QQ.生產工廠
                FROM   METOO選擇按鈕 RIGHT OUTER JOIN
                      (SELECT   TOP (100) PERCENT 生產工廠 FROM 訂單控制表 WHERE (CXL = 0) AND (訂單數量 - 出貨數量 > 0) 
                       GROUP BY 生產工廠 ORDER BY 生產工廠) AS QQ ON METOO選擇按鈕.對應 = QQ.生產工廠"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : 工廠_DGV.DataSource = ds1.Tables(0) : conn.Close()
        工廠_DGV.Columns(0).FillWeight = 30 : 工廠_DGV.Columns(1).FillWeight = 100
        For i As Integer = 0 To 工廠_DGV.Rows.Count - 1
            工廠_DGV.Rows(i).Cells("選擇").Value = False
        Next
    End Sub
    Private Sub Set_訂單清單()
        DataGridView1.DataSource = Nothing : ds.Clear()
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView1.ColumnHeadersHeight = 25
        DataGridView1.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT  訂單明細表抬頭.下單日 AS 接單日, 訂單控制表.訂單流水號, 訂單控制表.客戶訂單號, 
                            訂單控制表.GOODBOX AS 型體名稱, 訂單控制表.型體號碼, 訂單控制表.年份季度, 訂單控制表.TVW AS 楦型, 
                            訂單控制表.APMA確認 AS 顏色, 訂單控制表.訂單數量, 訂單控制表.工廠回復交期 AS 最後交期, 訂單控制表.BUYER, 
                            訂單控制表.材質, 訂單控制表.東莞業務備註, 訂單控制表.LEATHER AS 手剪全套, 訂單控制表.LEA_Note AS 斬刀全套, 
                            訂單控制表.面料, 訂單控制表.副料, 訂單控制表.中底, 訂單控制表.鞋墊, 訂單控制表.大底, 訂單控制表.跟, 
                            訂單控制表.包裝確認時間 AS 包裝, 訂單控制表.裁斷時間 AS 裁斷, 訂單控制表.針車時間 AS 針車, 
                            訂單控制表.成型時間 AS 成形, 訂單控制表.驗貨時間 AS 驗貨, 訂單控制表.工廠進度表備註1 AS 驗貨結果, 
                            訂單控制表.工廠進度表備註2 AS 工廠備註, 訂單控制表.驗貨報告圖片
                    FROM    訂單控制表 LEFT OUTER JOIN
                            訂單明細表抬頭 ON 訂單控制表.客戶訂單號 = 訂單明細表抬頭.客戶訂單號 AND 
                            訂單控制表.訂單流水號 = 訂單明細表抬頭.訂單流水號
                    WHERE  (訂單控制表.CXL = 0 OR
                            訂單控制表.CXL IS NULL) AND (訂單控制表.訂單數量 - 訂單控制表.出貨數量 <> 0) AND (訂單控制表.生產工廠 LIKE '" & ASS & "')
                    ORDER BY   訂單控制表.訂單流水號 DESC, 訂單控制表.客戶交期1, 訂單控制表.型體號碼, 顏色, 楦型"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
    End Sub
    Private Sub 生產進度表列印_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ASS = ""
        FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
        CheckBox1.Visible = False : CheckBox3.Visible = False : CheckBox6.Visible = False : CheckBox5.Visible = False : CheckBox4.Visible = False
        Set_工廠清單()
    End Sub
    Private Sub 工廠_DGV_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 工廠_DGV.CellClick
        If e.RowIndex = -1 Then : Else
            For i As Integer = 0 To 工廠_DGV.Rows.Count - 1
                If e.RowIndex = i Then
                    工廠_DGV.Rows(i).Cells("選擇").Value = True : ASS = 工廠_DGV.Rows(i).Cells("生產工廠").Value.ToString : Set_訂單清單()
                Else
                    工廠_DGV.Rows(i).Cells("選擇").Value = False
                End If
            Next
        End If
    End Sub
    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        If ASS <> "" Then
            xlApp = CType(CreateObject("Excel.Application"), Application)
            xlApp.Visible = True
            xlApp.DisplayAlerts = True
            xlApp.Application.WindowState = xlMaximized
            xlBook = xlApp.Workbooks.Add
            xlSheet = NewMethod(xlBook)
            xlApp.Sheets(1).Select
            xlBook.Activate() : xlSheet.Activate()
            xlApp.Sheets(1).Name = ASS
            xlSheet.Range("A1").Select()

            xlSheet.Cells(1, 13) = "淺藍色欄位為系統輸出，請勿做任何更改
淺綠色欄位為巨益辦公室填入"
            xlSheet.Cells(2, 14) = "量產樣品" : xlSheet.Cells(2, 16) = "PRODUCTION"
            xlSheet.Cells(3, 1) = "接單日" : xlSheet.Cells(3, 2) = "巨益PO#" : xlSheet.Cells(3, 3) = "客戶PO#" : 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) = "BUYER" : 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) = "驗貨結果" : xlSheet.Cells(3, 28) = "工廠備註"

            For i As Integer = 0 To DataGridView1.Rows.Count - 1
                xlSheet.Cells(i + 4, 1) = DataGridView1.Rows(i).Cells("接單日").Value : xlSheet.Cells(i + 4, 2) = DataGridView1.Rows(i).Cells("訂單流水號").Value
                xlSheet.Cells(i + 4, 3) = DataGridView1.Rows(i).Cells("客戶訂單號").Value : xlSheet.Cells(i + 4, 4) = DataGridView1.Rows(i).Cells("型體名稱").Value
                xlSheet.Cells(i + 4, 5) = DataGridView1.Rows(i).Cells("型體號碼").Value : xlSheet.Cells(i + 4, 6) = DataGridView1.Rows(i).Cells("年份季度").Value
                xlSheet.Cells(i + 4, 7) = DataGridView1.Rows(i).Cells("楦型").Value : xlSheet.Cells(i + 4, 8) = DataGridView1.Rows(i).Cells("顏色").Value
                xlSheet.Cells(i + 4, 9) = DataGridView1.Rows(i).Cells("訂單數量").Value : xlSheet.Cells(i + 4, 10) = DataGridView1.Rows(i).Cells("最後交期").Value

                xlSheet.Cells(i + 4, 11) = DataGridView1.Rows(i).Cells("BUYER").Value
                xlSheet.Cells(i + 4, 12) = DataGridView1.Rows(i).Cells("材質").Value
                xlSheet.Cells(i + 4, 13) = DataGridView1.Rows(i).Cells("東莞業務備註").Value
                xlSheet.Cells(i + 4, 14) = DataGridView1.Rows(i).Cells("手剪全套").Value
                xlSheet.Cells(i + 4, 15) = DataGridView1.Rows(i).Cells("斬刀全套").Value

                xlSheet.Cells(i + 4, 16) = DataGridView1.Rows(i).Cells("面料").Value : xlSheet.Cells(i + 4, 17) = DataGridView1.Rows(i).Cells("副料").Value
                xlSheet.Cells(i + 4, 18) = DataGridView1.Rows(i).Cells("中底").Value : xlSheet.Cells(i + 4, 19) = DataGridView1.Rows(i).Cells("鞋墊").Value
                xlSheet.Cells(i + 4, 20) = DataGridView1.Rows(i).Cells("大底").Value : xlSheet.Cells(i + 4, 21) = DataGridView1.Rows(i).Cells("跟").Value
                xlSheet.Cells(i + 4, 22) = DataGridView1.Rows(i).Cells("包裝").Value : xlSheet.Cells(i + 4, 23) = DataGridView1.Rows(i).Cells("裁斷").Value
                xlSheet.Cells(i + 4, 24) = DataGridView1.Rows(i).Cells("針車").Value : xlSheet.Cells(i + 4, 25) = DataGridView1.Rows(i).Cells("成形").Value
                xlSheet.Cells(i + 4, 26) = DataGridView1.Rows(i).Cells("驗貨").Value : xlSheet.Cells(i + 4, 27) = DataGridView1.Rows(i).Cells("驗貨結果").Value
                xlSheet.Cells(i + 4, 28) = DataGridView1.Rows(i).Cells("工廠備註").Value
                With xlApp.Selection
                    .Font.Bold = True
                End With
                N1 = i
            Next i

            BB(xlApp, xlSheet)
            xlSheet.Range("A4").Select()
            If xlApp.Sheets(2).Name = "工作表1" Then
                xlApp.Sheets("工作表1").Delete
            Else
                xlApp.Sheets("sheet1").Delete
            End If
            xlSheet.Cells(1, 1) = "巨益 量產進度管理表"
            xlSheet.PageSetup.PrintArea = ""
            xlApp.Cells.Select()
            xlApp.Application.WindowState = xlMinimized
            MsgBox("列印完成")
            Me.Close()
        Else
            MsgBox("請先選擇工廠")
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
    Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    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.Range("A1:L1").Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 24 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With

        xlSheet.Range("A2:A3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("B2:B3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("C2:C3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("D2:D3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("E2:E3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("F2:F3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("G2:G3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("H2:H3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("I2:I3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("J2:J3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("K2:K3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("L2:L3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("M2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("N2:O2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("P2:AB2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Rows("2:3").Select
        With myExcel.Selection : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With

        xlSheet.Rows("2:3").Select : myExcel.Selection.RowHeight = 25
        xlSheet.Rows("3:3").Select : myExcel.Selection.AutoFilter

        xlSheet.Rows("4:" & N1 + 5).Select
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 9 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        With myExcel.Selection : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : End With

        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 9 : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd"
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With

        xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With

        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 11 : myExcel.Selection.NumberFormatLocal = "@"
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With

        xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 11
        xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 5
        xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 6 : myExcel.Selection.NumberFormatLocal = "#,##0 "
        xlSheet.Columns("J:J").Select : myExcel.Selection.ColumnWidth = 9 : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd"
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With

        xlSheet.Columns("K:K").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("L:L").Select : myExcel.Selection.ColumnWidth = 5
        xlSheet.Columns("M:M").Select : myExcel.Selection.ColumnWidth = 40
        xlSheet.Rows("4:" & N1 + 5).Select : myExcel.Selection.RowHeight = 40 : With myExcel.Selection : .WrapText = True : End With

        xlSheet.Columns("M:M").Select : myExcel.Selection.ColumnWidth = 12
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With

        xlSheet.Columns("N:AA").Select : myExcel.Selection.ColumnWidth = 9
        xlSheet.Columns("N:N").Select
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With
        xlSheet.Columns("O:O").Select
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : End With
        xlSheet.Columns("M:AB").Select
        With myExcel.Selection : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : End With

        xlSheet.Columns("AB:AB").Select : myExcel.Selection.ColumnWidth = 9

        xlSheet.Range("A1:AB3").Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorDark1 : .TintAndShade = -0.249977111117893 : .PatternTintAndShade = 0 : 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 = 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.Range("A4:K" & N1 + 5).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 = xlHairline : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With

        xlSheet.Range("L4:M" & N1 + 5).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 = xlHairline : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With

        xlSheet.Columns("M:M").Select : myExcel.Selection.ColumnWidth = 40

        xlSheet.Range("L4:M" & N1 + 5).Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent6 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With

        xlSheet.Range("N4:AB" & N1 + 5).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 = xlHairline : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With

        xlSheet.Range("A1:L1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Range("M1:AB1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge

        xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 40

        xlSheet.Range("M1:AB1").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = True : End With

        xlSheet.Range("L4").Select() : myExcel.ActiveWindow.FreezePanes = True
        myExcel.ActiveWindow.DisplayGridlines = False

        xlSheet.Range("M4:M" & N1 + 5).Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 7 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : End With

        xlSheet.Range("M1:AB1").Select() : With myExcel.Selection.Font : .Color = -16776961 : .TintAndShade = 0 : End With
        xlSheet.Range("M2:M3").Select() : myExcel.Selection.Merge
    End Sub
    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
        If CheckBox1.Checked = True Then : CheckBox1.Checked = True
            CheckBox2.Checked = False : CheckBox3.Checked = False : CheckBox4.Checked = False : CheckBox5.Checked = False : CheckBox7.Checked = False : End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
        If CheckBox2.Checked = True Then : CheckBox2.Checked = True
            CheckBox1.Checked = False : CheckBox3.Checked = False : CheckBox4.Checked = False : CheckBox6.Checked = False : CheckBox7.Checked = False : End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.Click
        If CheckBox3.Checked = True Then : CheckBox3.Checked = True
            CheckBox1.Checked = False : CheckBox2.Checked = False : CheckBox5.Checked = False : CheckBox6.Checked = False : CheckBox7.Checked = False : End If
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click
        If CheckBox4.Checked = True Then : CheckBox4.Checked = True
            CheckBox1.Checked = False : CheckBox2.Checked = False : CheckBox5.Checked = False : CheckBox6.Checked = False : CheckBox7.Checked = False : End If
    End Sub
    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.Click
        If CheckBox5.Checked = True Then : CheckBox5.Checked = True
            CheckBox1.Checked = False : CheckBox3.Checked = False : CheckBox4.Checked = False : CheckBox6.Checked = False : CheckBox7.Checked = False : End If
    End Sub
    Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox6.Click
        If CheckBox6.Checked = True Then : CheckBox6.Checked = True
            CheckBox2.Checked = False : CheckBox3.Checked = False : CheckBox4.Checked = False : CheckBox5.Checked = False : CheckBox7.Checked = False : End If
    End Sub
    Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox7.Click
        If CheckBox7.Checked = True Then : CheckBox7.Checked = True
            CheckBox1.Checked = False : CheckBox2.Checked = False : CheckBox3.Checked = False : CheckBox4.Checked = False : CheckBox5.Checked = False : CheckBox6.Checked = False : End If
    End Sub
End Class