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 System.IO
Imports Microsoft.Office.Interop.Excel
Imports System.Threading
Public Class 列印_訂單明細
    Dim conn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    Dim ds As New DataSet : Dim ds2 As New DataSet
    Dim dr As SqlDataReader
    Dim N1 As Integer = 5 : Dim N2 As Integer
    Dim M1 As String
    Dim xlApp As Microsoft.Office.Interop.Excel.Application
    Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
    Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
    Private Sub Set_DGV1載入前設定()
        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
    End Sub
    Private Sub Set_DGV1載入後設定()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_訂單清單()
        Set_DGV1載入前設定() : SQL1 = 列印用SQL : Set_DGV1載入後設定()
    End Sub
    Private Sub Set_DGV2載入前設定()
        DataGridView2.DataSource = Nothing : ds2.Clear()
        DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView2.ColumnHeadersHeight = 25
        DataGridView2.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
    End Sub
    Private Sub Set_DGV2載入後設定()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : DataGridView2.DataSource = ds2.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_清單2()
        Set_DGV2載入前設定()
        SQL1 = "SELECT 訂單流水號, 附件數 FROM 訂單附件資料 WHERE 訂單流水號 LIKE N'" & 列印用SQL1 & "' ORDER BY 附件數"
        Set_DGV2載入後設定()
    End Sub
    Private Sub Set_格式設定()
        DataGridView1.Visible = False
    End Sub
    Private Sub 列印_訂單明細_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
        Set_清單2() : Set_訂單清單() : Set_格式設定()
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
        xlBook = xlApp.Workbooks.Add
        xlApp.DisplayAlerts = True
        xlApp.Visible = True
        xlApp.Application.WindowState = xlMaximized

        For i As Integer = 0 To DataGridView2.Rows.Count - 1
            xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Name = "附件_" & i + 1 : xlBook.Activate() : xlSheet.Activate()

            PictureBox2.Image = Nothing : conn.Close()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT TOP(1) 圖片 FROM 訂單附件資料 
                    WHERE 訂單流水號 LIKE N'" & DataGridView2.Rows(i).Cells("訂單流水號").Value & "' AND 附件數 LIKE N'" & DataGridView2.Rows(i).Cells("附件數").Value & "'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            While dr.Read() = True
                Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("圖片"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox2.Image = Bitmap.FromStream(oStream)
            End While
            conn.Close()
            PictureBox2.SizeMode = 4
            AA(xlApp, xlSheet)
        Next

        xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Name = "訂單" : xlBook.Activate() : xlSheet.Activate()

        CC(xlApp, xlSheet)

        xlSheet.Cells(2, 1) = "Number" : xlSheet.Cells(2, 3) = OD(0)
        xlSheet.Cells(3, 1) = "Created Date"
        xlSheet.Cells(3, 3) = OD(20) 'OD(1)
        xlSheet.Cells(4, 1) = "Brand" : xlSheet.Cells(4, 3) = OD(2) : xlSheet.Cells(5, 1) = "Vendor Name" : xlSheet.Cells(5, 3) = OD(3)
        xlSheet.Cells(7, 1) = "Mode Of Delivery" : xlSheet.Cells(7, 3) = OD(4) : xlSheet.Cells(8, 1) = "Delivery Terms" : xlSheet.Cells(8, 3) = OD(5)
        xlSheet.Cells(9, 1) = "Ship from name Ship from address" : xlSheet.Cells(9, 3) = OD(6)

        xlSheet.Cells(2, 4) = "Org. Ship Date" : xlSheet.Cells(2, 6) = OD(21) : xlSheet.Cells(3, 4) = "From Port" : xlSheet.Cells(3, 6) = OD(8)
        xlSheet.Cells(4, 4) = "To Port" : xlSheet.Cells(4, 6) = OD(9) : xlSheet.Cells(5, 4) = "Shipping Carrier" : xlSheet.Cells(5, 6) = OD(10)
        xlSheet.Cells(6, 4) = "Customer Requisition" : xlSheet.Cells(6, 6) = OD(39) : xlSheet.Cells(7, 4) = "Vendor Reference" : xlSheet.Cells(7, 6) = OD(11)
        xlSheet.Cells(8, 4) = "訂單屬性" : xlSheet.Cells(8, 6) = OD(45)

        'xlSheet.Cells(2, 8) = "Modified Date" : xlSheet.Cells(2, 10) = OD(12)
        xlSheet.Cells(3, 8) = "Customer Name" : xlSheet.Cells(3, 10) = OD(13)
        xlSheet.Cells(4, 8) = "Ship Date" : xlSheet.Cells(4, 10) = OD(14)
        'xlSheet.Cells(5, 8) = "Sales Order" : xlSheet.Cells(5, 10) = OD(15) : xlSheet.Cells(6, 8) = "ETA Date" : xlSheet.Cells(6, 10) = OD(16)
        xlSheet.Cells(8, 8) = "Delivery Address" : xlSheet.Cells(8, 10) = OD(17)

        xlSheet.Cells(2, 13) = OD(18) : xlSheet.Cells(3, 13) = "工廠：" : xlSheet.Cells(3, 14) = OD(19)
        xlSheet.Cells(4, 13) = "下單日：" : xlSheet.Cells(4, 14) = OD(20) : xlSheet.Cells(5, 13) = "交期：" : xlSheet.Cells(5, 14) = OD(21) : xlSheet.Cells(6, 13) = OD(40)

        xlSheet.Cells(16, 1) = "Item Number" : xlSheet.Cells(16, 2) = "Product Name" : xlSheet.Cells(16, 3) = "Color" : xlSheet.Cells(16, 4) = "DM"

        If OD(43) <> 0 Then : xlSheet.Cells(16, N1) = "4" : N1 = N1 + 1 : End If : If OD(44) <> 0 Then : xlSheet.Cells(16, N1) = "4.5" : N1 = N1 + 1 : End If
        If OD(22) <> 0 Then : xlSheet.Cells(16, N1) = "5" : N1 = N1 + 1 : End If : If OD(23) <> 0 Then : xlSheet.Cells(16, N1) = "5.5" : N1 = N1 + 1 : End If
        If OD(24) <> 0 Then : xlSheet.Cells(16, N1) = "6" : N1 = N1 + 1 : End If : If OD(25) <> 0 Then : xlSheet.Cells(16, N1) = "6.5" : N1 = N1 + 1 : End If
        If OD(26) <> 0 Then : xlSheet.Cells(16, N1) = "7" : N1 = N1 + 1 : End If : If OD(27) <> 0 Then : xlSheet.Cells(16, N1) = "7.5" : N1 = N1 + 1 : End If
        If OD(28) <> 0 Then : xlSheet.Cells(16, N1) = "8" : N1 = N1 + 1 : End If : If OD(29) <> 0 Then : xlSheet.Cells(16, N1) = "8.5" : N1 = N1 + 1 : End If
        If OD(30) <> 0 Then : xlSheet.Cells(16, N1) = "9" : N1 = N1 + 1 : End If : If OD(31) <> 0 Then : xlSheet.Cells(16, N1) = "9.5" : N1 = N1 + 1 : End If
        If OD(32) <> 0 Then : xlSheet.Cells(16, N1) = "10" : N1 = N1 + 1 : End If : If OD(33) <> 0 Then : xlSheet.Cells(16, N1) = "10.5" : N1 = N1 + 1 : End If
        If OD(34) <> 0 Then : xlSheet.Cells(16, N1) = "11" : N1 = N1 + 1 : End If : If OD(41) <> 0 Then : xlSheet.Cells(16, N1) = "11.5" : N1 = N1 + 1 : End If
        If OD(35) <> 0 Then : xlSheet.Cells(16, N1) = "12" : N1 = N1 + 1 : End If : If OD(42) <> 0 Then : xlSheet.Cells(16, N1) = "12.5" : N1 = N1 + 1 : End If
        If OD(36) <> 0 Then : xlSheet.Cells(16, N1) = "13" : N1 = N1 + 1 : End If : If OD(37) <> 0 Then : xlSheet.Cells(16, N1) = "14" : N1 = N1 + 1 : End If
        xlSheet.Cells(16, N1) = "TOTAL"

        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            xlSheet.Cells(i + 17, 1) = DataGridView1.Rows(i).Cells("ItemNumber").Value
            xlSheet.Cells(i + 17, 2) = DataGridView1.Rows(i).Cells("ProductName").Value
            xlSheet.Cells(i + 17, 3) = DataGridView1.Rows(i).Cells("Color").Value
            xlSheet.Cells(i + 17, 4) = DataGridView1.Rows(i).Cells("DM").Value
            N1 = 5
            If OD(43) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("4").Value : N1 = N1 + 1 : End If
            If OD(44) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("4.5").Value : N1 = N1 + 1 : End If
            If OD(22) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("5").Value : N1 = N1 + 1 : End If
            If OD(23) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("5.5").Value : N1 = N1 + 1 : End If
            If OD(24) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("6").Value : N1 = N1 + 1 : End If
            If OD(25) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("6.5").Value : N1 = N1 + 1 : End If
            If OD(26) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("7").Value : N1 = N1 + 1 : End If
            If OD(27) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("7.5").Value : N1 = N1 + 1 : End If
            If OD(28) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("8").Value : N1 = N1 + 1 : End If
            If OD(29) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("8.5").Value : N1 = N1 + 1 : End If
            If OD(30) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("9").Value : N1 = N1 + 1 : End If
            If OD(31) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("9.5").Value : N1 = N1 + 1 : End If
            If OD(32) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("10").Value : N1 = N1 + 1 : End If
            If OD(33) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("10.5").Value : N1 = N1 + 1 : End If
            If OD(34) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("11").Value : N1 = N1 + 1 : End If
            If OD(41) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("11.5").Value : N1 = N1 + 1 : End If
            If OD(35) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("12").Value : N1 = N1 + 1 : End If
            If OD(42) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("12.5").Value : N1 = N1 + 1 : End If
            If OD(36) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("13").Value : N1 = N1 + 1 : End If
            If OD(37) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("14").Value : N1 = N1 + 1 : End If
            xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("TOTAL").Value
            With xlApp.Selection
                .Font.Bold = True
            End With
            N2 = i
        Next i

        N1 = 5 : N2 = N2 + 3
        xlSheet.Cells(N2 + 17, N1) = "合計" : N1 = N1
        If OD(43) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(43) : N1 = N1 + 1 : End If : If OD(44) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(44) : N1 = N1 + 1 : End If  '4  4.5
        If OD(22) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(22) : N1 = N1 + 1 : End If : If OD(23) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(23) : N1 = N1 + 1 : End If  '5  5.5
        If OD(24) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(24) : N1 = N1 + 1 : End If : If OD(25) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(25) : N1 = N1 + 1 : End If  '6  6.5
        If OD(26) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(26) : N1 = N1 + 1 : End If : If OD(27) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(27) : N1 = N1 + 1 : End If  '7  7.5
        If OD(28) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(28) : N1 = N1 + 1 : End If : If OD(29) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(29) : N1 = N1 + 1 : End If  '8  8.5
        If OD(30) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(30) : N1 = N1 + 1 : End If : If OD(31) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(31) : N1 = N1 + 1 : End If  '9  9.5
        If OD(32) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(32) : N1 = N1 + 1 : End If : If OD(33) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(33) : N1 = N1 + 1 : End If  '10  10.5
        If OD(34) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(34) : N1 = N1 + 1 : End If : If OD(41) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(41) : N1 = N1 + 1 : End If  '11  11.5
        If OD(35) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(35) : N1 = N1 + 1 : End If : If OD(42) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(42) : N1 = N1 + 1 : End If  '12  12.5
        If OD(36) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(36) : N1 = N1 + 1 : End If : If OD(37) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(37) : N1 = N1 + 1 : End If  '13  14
        xlSheet.Cells(N2 + 17, N1) = OD(38)

        BB(xlApp, xlSheet)

        xlSheet.PageSetup.PrintArea = ""
        xlApp.Cells.Select()
        xlSheet.Range("B1").Select()
        xlApp.Application.WindowState = xlMinimized
        MsgBox("列印完成")
        Me.Close()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        列印用SQL = "" : 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, Microsoft.Office.Interop.Excel.Worksheet)
    End Function
    Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        Clipboard.SetDataObject(PictureBox2.Image)
        xlSheet.Cells(1, 1).Select
        Thread.Sleep(100) '延迟0.1秒
        xlSheet.Range("A1").Select()
        myExcel.ActiveSheet.Paste
        If PictureBox2.Image.Height < PictureBox2.Image.Width Then
            myExcel.Selection.ShapeRange.Width = 900
        Else
            myExcel.Selection.ShapeRange.Height = 900
        End If
        myExcel.Selection.ShapeRange.IncrementLeft(2)
        myExcel.Selection.ShapeRange.IncrementTop(2)
    End Sub
    Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        Dim 位置1 As String
        If N1 = 6 Then : M1 = "F" : ElseIf N1 = 7 Then : M1 = "G" : ElseIf N1 = 8 Then : M1 = "H" : ElseIf N1 = 9 Then : M1 = "I" : ElseIf N1 = 10 Then : M1 = "J"
        ElseIf N1 = 11 Then : M1 = "K" : ElseIf N1 = 12 Then : M1 = "L" : ElseIf N1 = 13 Then : M1 = "M" : ElseIf N1 = 14 Then : M1 = "N"
        ElseIf N1 = 15 Then : M1 = "O" : ElseIf N1 = 16 Then : M1 = "P" : ElseIf N1 = 17 Then : M1 = "Q" : ElseIf N1 = 18 Then : M1 = "R"
        ElseIf N1 = 19 Then : M1 = "S" : ElseIf N1 = 20 Then : M1 = "T" : ElseIf N1 = 21 Then : M1 = "U" : ElseIf N1 = 22 Then : M1 = "V"
        ElseIf N1 = 23 Then : M1 = "W" : ElseIf N1 = 24 Then : M1 = "X" : ElseIf N1 = 25 Then : M1 = "Y" : ElseIf N1 = 26 Then : M1 = "Z" : End If

        xlSheet.Cells.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
        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 18
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 20
        xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("E:Z").Select : myExcel.Selection.ColumnWidth = 6
        xlSheet.Rows("16:16").Select : myExcel.Selection.RowHeight = 30

        位置1 = "17:" & N2 + 14 : xlSheet.Rows(位置1).Select : myExcel.Selection.RowHeight = 25

        位置1 = "A17:D" & N2 + 14
        xlSheet.Range(位置1).Select()
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With

        位置1 = "E17:F" & N2 + 17 : xlSheet.Range(位置1).Select() : myExcel.Selection.NumberFormatLocal = "#,##0"
        位置1 = "A16:" & M1 & N2 + 14 : xlSheet.Range(位置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

        位置1 = "A16:" & M1 & "16" : xlSheet.Range(位置1).Select()
        With myExcel.Selection.Interior
            .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.599993896298105 : .PatternTintAndShade = 0
        End With
        位置1 = "A16:" & M1 & "16" : xlSheet.Range(位置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("A2:B2,A3:B3,A4:B4,A5:B6,C5:C6,A7:B7,A8:B8,A9:B15,C9:C15").Select() : xlSheet.Range("C9").Activate()
        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.Range("D2:E2,D3:E3,D4:E4,D5:E5,D6:E6,D8:E8,F2:G2,F3:G3,F4:G4,F5:G5,F6:G6,F8:G8").Select() : xlSheet.Range("F6").Activate()
        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.Range("H2:I2,H3:I3,H4:I4,H5:I5,H6:I7,H8:I15,J2:L2,J3:L3,J4:L4,J5:L5,J6:L7,J8:L15").Select() : xlSheet.Range("J8").Activate()
        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.Range("M2:O2,N3:O3,N4:O4,N5:O5").Select() : xlSheet.Range("N5").Activate()
        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.Range("A2:O15").Select()
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext
        End With
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext
        End With
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext
        End With
        xlSheet.Range("A2:B15,D2:E8,H2:I15,M3:M5").Select() : xlSheet.Range("M3").Activate()
        With myExcel.Selection.Interior
            .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0
        End With
        xlSheet.Range("A1").Select() : myExcel.ActiveWindow.DisplayGridlines = False

        xlSheet.Range("D7:E7,F7:G7").Select() : xlSheet.Range("F7").Activate()
        With myExcel.Selection
            .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        myExcel.Selection.Merge

        xlSheet.Range("D7:D7").Select()
        With myExcel.Selection.Interior
            .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0
        End With
        xlSheet.Rows("7:7").Select : xlSheet.Rows("7:7").EntireRow.AutoFit : xlSheet.Range("F10").Select()

        xlSheet.Range("D7:G7").Select()
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext
        End With

        xlSheet.Range("C9:D15").Select()

        With myExcel.Selection
            .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        myExcel.Selection.UnMerge

        xlSheet.Range("J8:M15").Select()
        With myExcel.Selection
            .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        myExcel.Selection.UnMerge

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

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

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

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

        xlSheet.Rows("8:9").Select
        xlSheet.Rows("8:9").EntireRow.AutoFit
        xlSheet.Range("C1").Select()

        xlApp.Application.PrintCommunication = False
        With xlBook.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
        xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.PrintArea = "" : xlApp.Application.PrintCommunication = False
        With xlBook.ActiveSheet.PageSetup
            .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
            .LeftMargin = xlApp.Application.InchesToPoints(0.7) : .RightMargin = xlApp.Application.InchesToPoints(0.7)
            .TopMargin = xlApp.Application.InchesToPoints(0.75) : .BottomMargin = xlApp.Application.InchesToPoints(0.75)
            .HeaderMargin = xlApp.Application.InchesToPoints(0.3) : .FooterMargin = xlApp.Application.InchesToPoints(0.3)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
            .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = 100 : .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True : .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With
        xlApp.Application.PrintCommunication = True : xlApp.Application.PrintCommunication = False
        With xlBook.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
        xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.PrintArea = "" : xlApp.Application.PrintCommunication = False
        With xlBook.ActiveSheet.PageSetup
            .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
            .LeftMargin = xlApp.Application.InchesToPoints(0.708661417322835) : .RightMargin = xlApp.Application.InchesToPoints(0.708661417322835)
            .TopMargin = xlApp.Application.InchesToPoints(0.748031496062992) : .BottomMargin = xlApp.Application.InchesToPoints(0.748031496062992)
            .HeaderMargin = xlApp.Application.InchesToPoints(0.31496062992126) : .FooterMargin = xlApp.Application.InchesToPoints(0.31496062992126)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
            .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1
            .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With
        xlApp.Application.PrintCommunication = True : xlApp.Application.PrintCommunication = False
        With xlBook.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
        xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.PrintArea = "" : xlApp.Application.PrintCommunication = False
        With xlBook.ActiveSheet.PageSetup
            .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
            .LeftMargin = xlApp.Application.InchesToPoints(0.25) : .RightMargin = xlApp.Application.InchesToPoints(0.25)
            .TopMargin = xlApp.Application.InchesToPoints(0.75) : .BottomMargin = xlApp.Application.InchesToPoints(0.75)
            .HeaderMargin = xlApp.Application.InchesToPoints(0.3) : .FooterMargin = xlApp.Application.InchesToPoints(0.3)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
            .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1
            .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
            .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With
        xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.Orientation = 2
        xlBook.ActiveSheet.PageSetup.CenterFooter = OD(18) & "-" & OD(0)

        xlSheet.Range("M6:N6").Select()
        With myExcel.Selection
            .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        myExcel.Selection.Merge
        xlSheet.Rows("6:6").Select : xlSheet.Range("O6").Activate() : myExcel.Selection.RowHeight = 12.75
        xlSheet.Range("O7").Select()
    End Sub
    Private Sub CC(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        xlSheet.Range("C2").Select() : myExcel.Selection.NumberFormatLocal = "@"
    End Sub
End Class