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 ds As New DataSet : Dim N1, 總數 As Integer : Dim 首次開啟 As Boolean
    Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
    Private Sub Set_清單1()
        運費明細表_dgv.DataSource = Nothing : ds.Clear()
        運費明細表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        運費明細表_dgv.ColumnHeadersHeight = 25
        運費明細表_dgv.AllowUserToAddRows = False
        運費明細表_dgv.RowTemplate.Height = 25

        If 依據1_ch.Checked = True And 依據2_ch.Checked = False And 依據3_ch.Checked = False And 依據4_ch.Checked = False Then : SQL_業績運費1()
        ElseIf 依據1_ch.Checked = False And 依據2_ch.Checked = True And 依據3_ch.Checked = False And 依據4_ch.Checked = False Then : SQL_業績運費2()
        ElseIf 依據1_ch.Checked = False And 依據2_ch.Checked = False And 依據3_ch.Checked = True And 依據4_ch.Checked = False Then : SQL_業績運費3()
        ElseIf 依據1_ch.Checked = False And 依據2_ch.Checked = False And 依據3_ch.Checked = False And 依據4_ch.Checked = True Then : SQL_業績運費4()
        End If

        da.Fill(ds) : 運費明細表_dgv.DataSource = ds.Tables(0) : conn.Close()
        運費明細表_dgv.Columns(0).FillWeight = 80 : 運費明細表_dgv.Columns(1).FillWeight = 70 : 運費明細表_dgv.Columns(2).FillWeight = 100 : 運費明細表_dgv.Columns(3).FillWeight = 80
        運費明細表_dgv.Columns(4).FillWeight = 80 : 運費明細表_dgv.Columns(5).FillWeight = 70 : 運費明細表_dgv.Columns(6).FillWeight = 70 : 運費明細表_dgv.Columns(7).FillWeight = 230
        運費明細表_dgv.Columns(8).FillWeight = 150 : 運費明細表_dgv.Columns(9).FillWeight = 70 : 運費明細表_dgv.Columns(10).FillWeight = 70 : 運費明細表_dgv.Columns(11).FillWeight = 70
        運費明細表_dgv.Columns("運費").DefaultCellStyle.Format = "#,##0" : 運費明細表_dgv.Columns("已付運費").DefaultCellStyle.Format = "#,##0"
        運費明細表_dgv.Columns("衍伸運費").DefaultCellStyle.Format = "#,##0" : 運費明細表_dgv.Columns("銷售小計").DefaultCellStyle.Format = "#,##0"
        運費明細表_dgv.Columns("已付運費").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        運費明細表_dgv.Columns("運費").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        運費明細表_dgv.Columns("衍伸運費").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        運費明細表_dgv.Columns("銷售小計").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        運費明細表_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        運費明細表_dgv.Columns(0).ReadOnly = True : 運費明細表_dgv.Columns(1).ReadOnly = True : 運費明細表_dgv.Columns(2).ReadOnly = True : 運費明細表_dgv.Columns(3).ReadOnly = True
        運費明細表_dgv.Columns(5).ReadOnly = True
        For I As Integer = 0 To 運費明細表_dgv.Rows.Count - 1
            If IsDBNull(運費明細表_dgv.Rows(I).Cells("已付運費").Value) Then : 運費明細表_dgv.Rows(I).Cells("已付運費").Value = 0 : End If
            If 運費明細表_dgv.Rows(I).Cells("衍伸運費").Value.ToString = "" Then : 運費明細表_dgv.Rows(I).Cells("衍伸運費").Value = "0" : End If
            運費明細表_dgv.Rows(I).Cells("運費").Value = CInt(運費明細表_dgv.Rows(I).Cells("運費").Value) + CInt(運費明細表_dgv.Rows(I).Cells("衍伸運費").Value.ToString)
        Next
        計算()
    End Sub
    Private Sub 計算()
        NUD1.Value = 0 : NUD2.Value = 0
        For I As Integer = 0 To 運費明細表_dgv.Rows.Count - 1
            If IsDBNull(運費明細表_dgv.Rows(I).Cells("運費已付").Value) = True Then : 運費明細表_dgv.Rows(I).Cells("運費已付").Value = False : End If
            If IsDBNull(運費明細表_dgv.Rows(I).Cells("備註").Value) = True Then : 運費明細表_dgv.Rows(I).Cells("備註").Value = "" : End If
            If 運費明細表_dgv.Rows(I).Cells("已付運費").Value = 運費明細表_dgv.Rows(I).Cells("運費").Value Then
                運費明細表_dgv.Rows(I).Cells("付清").Value = True
            Else
                運費明細表_dgv.Rows(I).Cells("付清").Value = False
            End If
            If 運費明細表_dgv.Rows(I).Cells("運費已付").Value = True Then
                If 運費明細表_dgv.Rows(I).Cells("已付運費").Value <> 0 Then : Else
                    運費明細表_dgv.Rows(I).Cells("已付運費").Value = 運費明細表_dgv.Rows(I).Cells("運費").Value
                End If
            Else
                運費明細表_dgv.Rows(I).Cells("已付運費").Value = 0
            End If
            If 運費明細表_dgv.Rows(I).Cells("運費已付").Value = True Then
                NUD1.Value += 運費明細表_dgv.Rows(I).Cells("已付運費").Value
            Else
                NUD2.Value += 運費明細表_dgv.Rows(I).Cells("運費").Value
            End If
        Next
        NUD3.Value = NUD2.Value + NUD1.Value
    End Sub
    Private Sub 日期格式()
        '-------------日期一----------------------------------------------------------------------------------------
        DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
        '-------------日期二----------------------------------------------------------------------------------------
        DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 結束日期_dtp.Value = DTP
        結束日期_dtp.Value = 結束日期_dtp.Value.AddMonths(1) : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(-1)
    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
        首次開啟 = True
        日期格式() : Set_清單1() : 計算()
        If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 8
        End If
    End Sub
    Private Sub 業績運費明細表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        首次開啟 = False
    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
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 8
        End If
    End Sub
    Dim 已超出 As Boolean
    Private Sub 運費明細表_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 運費明細表_dgv.MouseUp
        'If 運費明細表_dgv.SelectedCells.Count = 1 Then : MsgBox(運費明細表_dgv.SelectedCells(0).ColumnIndex & "  " & 運費明細表_dgv.SelectedCells(0).RowIndex) : End If
        If 運費明細表_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If
        If 運費明細表_dgv.SelectedCells.Count > 0 Then
            If 運費明細表_dgv.SelectedCells(0).ColumnIndex = 3 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 運費明細表_dgv.SelectedCells.Count - 1
                        x += Val(運費明細表_dgv.Rows(運費明細表_dgv.SelectedCells.Item(i).RowIndex).Cells(運費明細表_dgv.SelectedCells.Item(i).ColumnIndex).Value)
                    Next i : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
                Else : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : YD_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
            End If
        End If
    End Sub
    Private Sub 運費明細表_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 運費明細表_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 方便點選功能_ch.Checked = True Then
                If 運費明細表_dgv.Rows(e.RowIndex).Cells("運費已付").Value = True Then
                    運費明細表_dgv.Rows(e.RowIndex).Cells("運費已付").Value = False
                Else
                    運費明細表_dgv.Rows(e.RowIndex).Cells("運費已付").Value = True
                End If
            End If : 計算()
        End If
    End Sub
    Private Sub 運費明細表_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles 運費明細表_dgv.CellEndEdit
        If 首次開啟 = False Then
            計算()
        End If
    End Sub
    Private Sub 上個月_bt_Click(sender As Object, e As EventArgs) Handles 上個月_bt.Click
        中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
        開始日期_dtp.Value = 中間日期_dtp.Value
        結束日期_dtp.Value = 中間日期_dtp.Value
        日期格式() : Set_清單1() : 計算()
    End Sub
    Private Sub 下個月_bt_Click(sender As Object, e As EventArgs) Handles 下個月_bt.Click
        中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
        開始日期_dtp.Value = 中間日期_dtp.Value
        結束日期_dtp.Value = 中間日期_dtp.Value
        日期格式() : Set_清單1() : 計算()
    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
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        資料數 = 運費明細表_dgv.Rows.Count
        For I As Integer = 0 To 運費明細表_dgv.Rows.Count - 1
            MyModule1.進度條()
            PA = 運費明細表_dgv.Rows(I).Cells("單號").Value : PA1 = 運費明細表_dgv.Rows(I).Cells("運費已付").Value : PA2 = 運費明細表_dgv.Rows(I).Cells("備註").Value
            PA4 = 運費明細表_dgv.Rows(I).Cells("已付運費").Value
            If 運費明細表_dgv.Rows(I).Cells("運費已付").Value = True And 運費明細表_dgv.Rows(I).Cells("運費付款").Value.ToString = "" Then
                PA3 = Strings.Format(付款日期_dtp.Value, "yyyy/MM/dd")
            ElseIf 運費明細表_dgv.Rows(I).Cells("運費已付").Value = True And 運費明細表_dgv.Rows(I).Cells("運費付款").Value.ToString <> "" Then
                PA3 = 運費明細表_dgv.Rows(I).Cells("運費付款").Value.ToString
            Else : PA3 = "" : End If
            SQL_業績運費_修正()
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        MsgBox("存檔完成!!!") : Set_清單1() : 計算()
    End Sub
    Private Sub 全部選擇_bt_Click(sender As Object, e As EventArgs) Handles 全部選擇_bt.Click
        For i As Integer = 0 To 運費明細表_dgv.Rows.Count - 1 : 運費明細表_dgv.Rows(i).Cells("運費已付").Value = True : Next i : 計算()
    End Sub
    Private Sub 全部取消_bt_Click(sender As Object, e As EventArgs) Handles 全部取消_bt.Click
        For i As Integer = 0 To 運費明細表_dgv.Rows.Count - 1 : 運費明細表_dgv.Rows(i).Cells("運費已付").Value = False : Next i : 計算()
    End Sub
    Private Sub 依據1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 依據1_ch.Click
        依據1_ch.Checked = True : 依據2_ch.Checked = False : 依據3_ch.Checked = False : 依據4_ch.Checked = False : Set_清單1() : 計算()
    End Sub
    Private Sub 依據2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 依據2_ch.Click
        依據1_ch.Checked = False : 依據2_ch.Checked = True : 依據3_ch.Checked = False : 依據4_ch.Checked = False : Set_清單1() : 計算()
    End Sub
    Private Sub 依據3_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 依據3_ch.Click
        依據1_ch.Checked = False : 依據2_ch.Checked = False : 依據3_ch.Checked = True : 依據4_ch.Checked = False : Set_清單1() : 計算()
    End Sub
    Private Sub 依據4_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 依據4_ch.Click
        依據1_ch.Checked = False : 依據2_ch.Checked = False : 依據3_ch.Checked = False : 依據4_ch.Checked = True : Set_清單1() : 計算()
    End Sub
    Private Sub 列印成EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 列印成EXCEL_bt.Click
        xlApp = CType(CreateObject("Excel.Application"), Application)
        xlBook = xlApp.Workbooks.Add
        xlApp.DisplayAlerts = True
        xlBook.Activate()
        xlSheet = NewMethod(xlBook)
        xlSheet.Activate()
        xlApp.Visible = True
        xlApp.Application.WindowState = xlMaximized

        xlSheet.Cells(1, 1) = "雅邸家居" : xlSheet.Cells(2, 1) = "司 機 運 費 (明細表)" : xlSheet.Cells(3, 1) = "日期區間:" & 開始日期_dtp.Value & " ~ " & 結束日期_dtp.Value
        xlSheet.Cells(4, 1) = "完單日期" : xlSheet.Cells(4, 2) = "單據號碼" : xlSheet.Cells(4, 3) = "地址" : xlSheet.Cells(4, 4) = "運費總計" : xlSheet.Cells(4, 5) = "已付"
        xlSheet.Cells(4, 6) = "銷售小計" : xlSheet.Cells(4, 7) = "運費" : xlSheet.Cells(4, 8) = "衍伸運費"
        For I As Integer = 0 To 運費明細表_dgv.Rows.Count - 1
            xlSheet.Cells(I + 5, 1) = 運費明細表_dgv.Rows(I).Cells("完單日期").Value
            xlSheet.Cells(I + 5, 2) = 運費明細表_dgv.Rows(I).Cells("單號").Value
            xlSheet.Cells(I + 5, 3) = 運費明細表_dgv.Rows(I).Cells("地址").Value
            xlSheet.Cells(I + 5, 4) = 運費明細表_dgv.Rows(I).Cells("運費").Value
            xlSheet.Cells(I + 5, 5) = 運費明細表_dgv.Rows(I).Cells("已付運費").Value
            xlSheet.Cells(I + 5, 6) = 運費明細表_dgv.Rows(I).Cells("銷售小計").Value
            xlSheet.Cells(I + 5, 7) = "=D" & I + 5 & "-H" & I + 5
            xlSheet.Cells(I + 5, 8) = 運費明細表_dgv.Rows(I).Cells("衍伸運費").Value
            N1 = I
        Next
        xlSheet.Cells(N1 + 6, 1) = "已付總額" : xlSheet.Cells(N1 + 6, 2) = NUD1.Value
        xlSheet.Cells(N1 + 6, 3) = "未付總額" : xlSheet.Cells(N1 + 6, 4) = NUD2.Value
        xlSheet.Cells(N1 + 6, 5) = "運費總額" : xlSheet.Cells(N1 + 6, 6) = NUD3.Value

        BB(xlApp, xlSheet)

        xlSheet.PageSetup.PrintArea = ""
        xlApp.Cells.Select()
        xlSheet.Range("B1").Select()
        xlApp.Application.WindowState = xlMinimized
        xlSheet.Cells.Select()
        MsgBox("列印完成。")
    End Sub
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        xlSheet.Cells.Select()
        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

        xlSheet.Range("D5:D" & N1 + 5).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
        xlSheet.Range("B" & N1 + 6).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
        xlSheet.Range("D" & N1 + 6).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
        xlSheet.Range("F" & N1 + 6).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "#,##0_ ;[紅色]-#,##0 "
        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("B:H").Select
        xlSheet.Columns("B:H").EntireColumn.AutoFit
        xlSheet.Columns("F:H").Select : myExcel.Selection.NumberFormatLocal = "#,##0_ "
        xlSheet.Columns("B:B").Select
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : End With

        xlSheet.Range("A1:H1").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 = 24 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With

        xlSheet.Range("A2:H2").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.Range("A4:H4").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlDouble : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThick : End With
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A3:H3").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A" & N1 + 5 & ":H" & N1 + 5).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A" & N1 + 6).Select()
        With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With

        xlSheet.Range("C" & N1 + 6).Select()
        With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
        myExcel.ActiveWindow.DisplayGridlines = False
    End Sub
End Class