Option Strict Off
Imports System.IO
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
Imports System.Windows.Forms.DataVisualization.Charting
Public Class 採購單編輯
    ReadOnly ds8 As New DataSet
    Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
    Dim QQQ1, QQQ2, QQQ3, 新項次, 物料規格, 採購選擇, 對話框(15) As String
    Dim NUM1, NA1, N1, N2 As Integer
    Dim 可繪圖 As Boolean
    Private Sub Set_明細清單()
        Dim ds As New DataSet : 明細_dgv.DataSource = Nothing : ds.Clear()
        明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        明細_dgv.ColumnHeadersHeight = 40
        明細_dgv.AllowUserToAddRows = False
        If 小間距_ch.Checked = False And 中間距_ch.Checked = False And 大間距_ch.Checked = True Then : 明細_dgv.RowTemplate.Height = 65
        ElseIf 小間距_ch.Checked = False And 中間距_ch.Checked = True And 大間距_ch.Checked = False Then : 明細_dgv.RowTemplate.Height = 45
        ElseIf 小間距_ch.Checked = True And 中間距_ch.Checked = False And 大間距_ch.Checked = False Then : 明細_dgv.RowTemplate.Height = 25
        End If

        PA20 = 採購選擇 : If PA20 = "" Then : PA20 = "B" : End If
        PA1 = QQQ1 : PA2 = 採購單號_tb.Text : SQL_建築物料採購單生成_明細()
        da.Fill(ds) : 明細_dgv.DataSource = ds.Tables(0) : conn.Close()

        明細_dgv.Columns(0).Visible = False : 明細_dgv.Columns(1).FillWeight = 52 : 明細_dgv.Columns(3).FillWeight = 243 : 明細_dgv.Columns(4).FillWeight = 230
        明細_dgv.Columns(5).FillWeight = 145 : 明細_dgv.Columns(6).FillWeight = 80 : 明細_dgv.Columns(7).FillWeight = 80 : 明細_dgv.Columns(8).FillWeight = 80
        明細_dgv.Columns(9).FillWeight = 80 : 明細_dgv.Columns(10).Visible = False : 明細_dgv.Columns(11).Visible = False : 明細_dgv.Columns(12).Visible = False
        明細_dgv.Columns(13).Visible = False : 明細_dgv.Columns(14).Visible = False : 明細_dgv.Columns(15).Visible = False : 明細_dgv.Columns(16).FillWeight = 95
        明細_dgv.Columns(17).Visible = False : 明細_dgv.Columns(18).Visible = False : 明細_dgv.Columns(19).Visible = False : 明細_dgv.Columns(20).Visible = False
        明細_dgv.Columns(21).Visible = False : 明細_dgv.Columns(22).Visible = False : 明細_dgv.Columns(23).Visible = False : 明細_dgv.Columns(24).Visible = False
        明細_dgv.Columns(25).Visible = False : 明細_dgv.Columns(26).FillWeight = 40 : 明細_dgv.Columns("KEY").Visible = False : 明細_dgv.Columns("OUP").FillWeight = 80
        明細_dgv.Columns(2).FillWeight = 86 : 明細_dgv.Columns(27).FillWeight = 80 : 明細_dgv.Columns("SP%").FillWeight = 80
        明細_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(8).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns("OUP").DefaultCellStyle.Format = "#,##0"
        明細_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns("OUP").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns("OUP").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        明細_dgv.Columns(1).ReadOnly = True : 明細_dgv.Columns(3).ReadOnly = True : 明細_dgv.Columns(4).ReadOnly = True : 明細_dgv.Columns(16).ReadOnly = True
        明細_dgv.Columns("單位").ReadOnly = True : 明細_dgv.Columns("數量").ReadOnly = True : 明細_dgv.Columns("OUP").ReadOnly = True : 明細_dgv.Columns("SP%").ReadOnly = True
        If 低網速模式 = False Then
            明細_dgv.Columns(29).FillWeight = 80 : 明細_dgv.Columns("Image").Visible = True
            Dim mycol As DataGridViewImageColumn = 明細_dgv.Columns("Image")
            mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        Else
            If 明細_dgv.Columns.Count = 30 Then
                明細_dgv.Columns("Image").Visible = False
            End If
        End If

        新項次 = "00"
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            明細_dgv.Columns("OUP").DefaultCellStyle.Format = "#,0"
            NUM1 = Double.Parse(新項次) + 1
            If NUM1 < 10 Then : 新項次 = "0" & NUM1
            ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1
            End If
            明細_dgv.Rows(i).Cells("No").Value = 新項次

            '-------------------------規格合併呈現----------------------------------------------------------------------------------------------------------------------------------------
            If i = 0 Then
                AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = "" : PA3 = 明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value
                SQL_規格庫抬頭讀取()
                If dr.Read() Then : AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8") : End If
                conn.Close()
            Else
                If 明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value.ToString <> 明細_dgv.Rows(i - 1).Cells("規格庫抬頭指定").Value.ToString Then
                    AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = "" : PA3 = 明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value : SQL_規格庫抬頭讀取()
                    If dr.Read() Then : AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8") : End If
                    conn.Close()
                End If
            End If
            物料規格 = ""
            If 詳細資料2_ch.Checked = True Then
                Dim columns() As String = {"規格", "A2", "A3", "A4", "A5", "A6", "A7", "A8"}
                Dim AAAs() As String = {"AAA1", "AAA2", "AAA3", "AAA4", "AAA5", "AAA6", "AAA7", "AAA8"}
                For j As Integer = 0 To columns.Length - 1
                    Dim cellValue As String = 明細_dgv.Rows(i).Cells(columns(j)).Value.ToString()
                    If cellValue <> "" Then : Dim ZA As String = AAAs(j) & "=" & cellValue : If 物料規格 = "" Then : 物料規格 = ZA : Else : 物料規格 &= "、" & ZA : End If : End If
                Next
            Else
                If 明細_dgv.Rows(i).Cells("規格").Value.ToString <> "" Then : 物料規格 = 明細_dgv.Rows(i).Cells("規格").Value.ToString : End If
                For j As Integer = 2 To 8
                    Dim columnName As String = "A" & j
                    If 明細_dgv.Rows(i).Cells(columnName).Value.ToString <> "" Then
                        Dim value As String = 明細_dgv.Rows(i).Cells(columnName).Value.ToString
                        If 物料規格 = "" Then : 物料規格 = value : Else : 物料規格 &= "、" & value : End If
                    End If
                Next
            End If
            明細_dgv.Rows(i).Cells("規格").Value = 物料規格
            '-------------------------歷史單價----------------------------------------------------------------------------------------------------------------------------------------
            PA = 明細_dgv.Rows(i).Cells("料號").Value : Set_單價()
            If 價錢_dgv.Rows.Count = 0 Then : 明細_dgv.Rows(i).Cells("OUP").Value = 0 : Else : 明細_dgv.Rows(i).Cells("OUP").Value = 價錢_dgv.Rows(0).Cells("單價").Value : End If
        Next i

        Dim FFGG As Long = 0
        總金額_tb.Text = "0"
        If 採購選擇 = "A" Then
            For i As Integer = 0 To 明細_dgv.Rows.Count - 1
                明細_dgv.Rows(i).Cells("金額").Value = "0.0"
                明細_dgv.Rows(i).Cells("金額").Value = 明細_dgv.Rows(i).Cells("單價").Value * 明細_dgv.Rows(i).Cells("數量").Value
                FFGG = CLng(FFGG) + 明細_dgv.Rows(i).Cells("金額").Value : 明細_dgv.Rows(i).Cells("已採購").Value = False
            Next i
        ElseIf 採購選擇 = "B" Then
            For i As Integer = 0 To 明細_dgv.Rows.Count - 1
                明細_dgv.Rows(i).Cells("金額").Value = 明細_dgv.Rows(i).Cells("單價").Value * 明細_dgv.Rows(i).Cells("數量").Value
                FFGG = CLng(FFGG) + 明細_dgv.Rows(i).Cells("金額").Value : 明細_dgv.Rows(i).Cells("選擇").Value = True
            Next i
        End If
        折扣金額_tb.Text = CLng(折扣比_tb.Text) * FFGG / 100
        If 稅金計算_ch.Checked = True Then
            If 折扣比_tb.Text = "0" Then : 稅金金額_tb.Text = FFGG * CLng(稅金比_tb.Text) / 100 : Else : 稅金金額_tb.Text = (FFGG - 折扣金額_tb.Text) * CLng(稅金比_tb.Text) / 100 : End If
        Else : 稅金金額_tb.Text = "0" : End If
        總金額_tb.Text = FFGG - CLng(折扣金額_tb.Text) + CLng(稅金金額_tb.Text)
        折扣金額_tb.Text = Strings.Format(CLng(折扣金額_tb.Text), "#,##0") : 稅金金額_tb.Text = Strings.Format(CLng(稅金金額_tb.Text), "#,##0")
        總金額_tb.Text = Strings.Format(CLng(總金額_tb.Text), "#,##0")

        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            If 明細_dgv.Rows(i).Cells("選擇").Value = True Then
                明細_dgv.Rows(i).Cells("選擇").Value = False
            End If
            For II As Integer = 0 To 最新單價_dgv.Rows.Count - 1
                If 明細_dgv.Rows(i).Cells("料號").Value.ToString = 最新單價_dgv.Rows(II).Cells("料號").Value.ToString And CLng(明細_dgv.Rows(i).Cells("金額").Value.ToString) = 0 Then
                    明細_dgv.Rows(i).Cells("金額").Value = 最新單價_dgv.Rows(II).Cells("單價").Value.ToString : Exit For
                End If
            Next
        Next : 價格()
    End Sub
    Private Sub Set_清單1()
        Dim ds1 As New DataSet : 請購單_dgv.DataSource = Nothing : ds1.Clear()
        請購單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        請購單_dgv.ColumnHeadersHeight = 25
        請購單_dgv.AllowUserToAddRows = False

        SQL_建築物料採購單生成_請購()
        da.Fill(ds1) : 請購單_dgv.DataSource = ds1.Tables(0) : conn.Close()

        請購單_dgv.Columns(0).FillWeight = 125 : 請購單_dgv.Columns(1).Visible = False : 請購單_dgv.Columns(2).Visible = False : 請購單_dgv.Columns(3).Visible = False
        請購單_dgv.Columns(4).Visible = False : 請購單_dgv.Columns(5).Visible = False : 請購單_dgv.Columns(6).Visible = False : 請購單_dgv.Columns(7).Visible = False
        請購單_dgv.Columns(8).Visible = False : 請購單_dgv.Columns(9).Visible = False
    End Sub
    Private Sub Set_清單2()
        Dim ds2 As New DataSet : 採購單_dgv.DataSource = Nothing : ds2.Clear()
        採購單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        採購單_dgv.ColumnHeadersHeight = 25
        採購單_dgv.AllowUserToAddRows = False
        If 未指定_ch.Checked = True Then
            SQL2 = " AND (採購單控制表.供應商編號 LIKE '' OR 採購單控制表.供應商編號 IS NULL) "
        Else
            SQL2 = " AND (採購單控制表.供應商編號 NOT LIKE '') AND (採購單控制表.供應商編號 IS NOT NULL) "
        End If : SQL_建築物料採購單生成_採購()
        da.Fill(ds2) : 採購單_dgv.DataSource = ds2.Tables(0) : conn.Close()

        For i As Integer = 0 To 18 : 採購單_dgv.Columns(i).Visible = False : Next
        採購單_dgv.Columns(17).Visible = True
    End Sub
    Private Sub Set_清單3()
        Dim ds1 As New DataSet : 最新單價_dgv.DataSource = Nothing : ds1.Clear()
        最新單價_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        最新單價_dgv.ColumnHeadersHeight = 25
        最新單價_dgv.AllowUserToAddRows = False
        PA14 = 供應商編碼_tb.Text : SQL_物料最新單價查詢()
        da.Fill(ds1) : 最新單價_dgv.DataSource = ds1.Tables(0) : conn.Close()

        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            For II As Integer = 0 To 最新單價_dgv.Rows.Count - 1
                If 明細_dgv.Rows(i).Cells("料號").Value.ToString = 最新單價_dgv.Rows(II).Cells("料號").Value.ToString And CLng(明細_dgv.Rows(i).Cells("金額").Value.ToString) = 0 Then
                    明細_dgv.Rows(i).Cells("金額").Value = 最新單價_dgv.Rows(II).Cells("單價").Value.ToString : Exit For
                End If
            Next
        Next
    End Sub
    Private Sub 總金額計算()
        Dim FFGG As Long = 0
        總金額_tb.Text = "0"
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            明細_dgv.Rows(i).Cells("金額").Value = 明細_dgv.Rows(i).Cells("單價").Value * 明細_dgv.Rows(i).Cells("數量").Value
            If 明細_dgv.Rows(i).Cells("金額").Value = "0" Then
                明細_dgv.Rows(i).Cells("選擇").Value = False
            Else
                明細_dgv.Rows(i).Cells("選擇").Value = True
            End If
            FFGG = CLng(FFGG) + 明細_dgv.Rows(i).Cells("金額").Value
            If 明細_dgv("選擇", i).Value = True Then
                明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
            Else
                明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.White
            End If
        Next i
        If 折扣比_tb.Text = "" Then : 折扣比_tb.Text = "0" : End If
        折扣金額_tb.Text = CLng(折扣比_tb.Text) * FFGG / 100
        If 稅金計算_ch.Checked = True Then
            If 折扣比_tb.Text = "0" Then
                稅金金額_tb.Text = FFGG * CLng(稅金比_tb.Text) / 100
            Else
                稅金金額_tb.Text = (FFGG - 折扣金額_tb.Text) * CLng(稅金比_tb.Text) / 100
            End If
        Else
            稅金金額_tb.Text = "0"
        End If
        總金額_tb.Text = FFGG - CLng(折扣金額_tb.Text) + CLng(稅金金額_tb.Text)
        折扣金額_tb.Text = Strings.Format(CLng(折扣金額_tb.Text), "#,##0") : 稅金金額_tb.Text = Strings.Format(CLng(稅金金額_tb.Text), "#,##0")
        總金額_tb.Text = Strings.Format(CLng(總金額_tb.Text), "#,##0")
    End Sub
    Private Sub Set_單價()
        Dim ds6 As New DataSet : 價錢_dgv.DataSource = Nothing : ds6.Clear()
        價錢_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        價錢_dgv.ColumnHeadersHeight = 25
        價錢_dgv.AllowUserToAddRows = False

        If 日期_rb.Checked = False And 單價_rb.Checked = True Then
            SQL_加權平均()
        ElseIf 日期_rb.Checked = True And 單價_rb.Checked = False Then
            SQL_最近日期()
        End If
        da.Fill(ds6) : 價錢_dgv.DataSource = ds6.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_料號比價()
        Dim ds1 As New DataSet
        料號_dgv.DataSource = Nothing : ds1.Clear()
        料號_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        料號_dgv.ColumnHeadersHeight = 25
        料號_dgv.AllowUserToAddRows = False
        PA = 料號1_tb.Text : SQL_料號比對價格()
        da.Fill(ds1) : 料號_dgv.DataSource = ds1.Tables(0) : conn.Close()
        料號_dgv.Columns("排序").Visible = False : 料號_dgv.Columns(3).DefaultCellStyle.Format = "#,##0.00" : 料號_dgv.Columns(3).FillWeight = 50
    End Sub
    Private Sub 清空供應商_bt_MouseEnter(sender As Object, e As EventArgs) Handles 清空供應商_bt.MouseEnter
        ToolTip1.SetToolTip(Me.清空供應商_bt, "清空供應商")
    End Sub
    Private Sub 生成採購單_bt_MouseEnter(sender As Object, e As EventArgs) Handles 生成採購單_bt.MouseEnter
        ToolTip1.SetToolTip(Me.生成採購單_bt, "單據存檔")
    End Sub
    Private Sub 列印成詢價單_bt_MouseEnter(sender As Object, e As EventArgs) Handles 列印成詢價單_bt.MouseEnter
        ToolTip1.SetToolTip(Me.列印成詢價單_bt, "列印成詢價單")
    End Sub
    Private Sub 料號_bt_MouseEnter(sender As Object, e As EventArgs) Handles 分析工具_bt.MouseEnter
        ToolTip1.SetToolTip(Me.分析工具_bt, "價格分析")
    End Sub
    Private Sub 類別管理_cb_下拉表單資料載入()
        SQL_供應商類別_下拉清單() : 類別管理_cb.Items.Clear() : 類別管理_cb.Items.Add("")
        While (dr.Read()) : 類別管理_cb.Items.Add(dr("類別")) : End While : conn.Close()
    End Sub
    Private Sub 廠商_cb_下拉表單資料載入()
        SQL2 = "" : SQL_供應商資料表_公司名_下拉用() : 廠商_cb.Items.Clear() : 廠商_cb.Items.Add("")
        While (dr.Read()) : 廠商_cb.Items.Add(dr("公司名")) : End While : conn.Close() : SQL2 = ""
    End Sub
    Private Sub 公司類別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 公司類別_cb.SelectedIndexChanged
        廠商_cb_下拉表單資料載入()
    End Sub
    Private Sub 廠商清空()
        供應商編碼_tb.Text = "" : 地址_tb.Text = "" : 電話_tb.Text = "" : 郵件_tb.Text = "" : 傳真_tb.Text = "" : 類別管理_cb_下拉表單資料載入() : 廠商_cb_下拉表單資料載入()
    End Sub
    Private Sub 採購單編輯_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = FH_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        單價_rb.Checked = True : Panel3.SendToBack() : 小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False : ToolTip1.ToolTipTitle = "系統說明"
        Label4.Text = "森林綠代表漲幅大於" & 比例1 & "小於" & 比例2 & "。淡藍色代表漲幅大於" & 比例2 & "小於" & 比例3 & "。紅色代表漲幅大於" & 比例3
        採購單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
        明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
        料號_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 採購單編輯_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        計算分流01.Enabled = True
    End Sub
    Private Sub 計算分流01_Tick(sender As Object, e As EventArgs) Handles 計算分流01.Tick
        計算分流01.Enabled = False : 公司類別_cb.SelectedIndex = 0
        類別管理_cb_下拉表單資料載入() : Set_清單1() : Set_清單2() : 首次開啟 = False
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 價格()
        Dim 差異, 比對 As Double
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            If 明細_dgv.Rows(i).Cells("OUP").Value = 0 And 明細_dgv.Rows(i).Cells("單價").Value = 0 Then
                明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Lavender
                明細_dgv.Rows(i).Cells("SP%").Value = "0 % →"
            ElseIf 明細_dgv.Rows(i).Cells("單價").Value = 0 And 明細_dgv.Rows(i).Cells("OUP").Value <> 0 Then
                明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.Lavender
                明細_dgv.Rows(i).Cells("SP%").Value = "0 % →"
            ElseIf 明細_dgv.Rows(i).Cells("OUP").Value <> 0 And 明細_dgv.Rows(i).Cells("單價").Value <> 0 Then
                差異 = 明細_dgv.Rows(i).Cells("單價").Value - 明細_dgv.Rows(i).Cells("OUP").Value : 比對 = 差異 / 明細_dgv.Rows(i).Cells("單價").Value * 100
                If 比對 > 0 Then : 明細_dgv.Rows(i).Cells("SP%").Value = CInt(比對) & " % ↗" : 比對 *= 1
                ElseIf 比對 < 0 Then : 明細_dgv.Rows(i).Cells("SP%").Value = CInt(比對) & " % ↘" : 比對 *= -1
                ElseIf 比對 = 0 Then : 明細_dgv.Rows(i).Cells("SP%").Value = CInt(比對) & " % →" : End If
                If 比對 < 比例1 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.White
                ElseIf 比對 > 比例1 And 比對 < 比例2 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
                ElseIf 比對 > 比例2 And 比對 < 比例3 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
                ElseIf 比對 >= 比例3 Then : 明細_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink : End If
            End If
        Next
    End Sub
    Private Sub 單價_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 單價_rb.Click
        If 首次開啟 = False Then : Set_明細清單() : End If
    End Sub
    Private Sub 日期_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 日期_rb.Click
        Set_明細清單()
    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 : 通知訊息 = 明細_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 = 9 Then
                If 已超出 = False Then
                    Dim x As Double = 0
                    For i As Integer = 0 To 明細_dgv.SelectedCells.Count - 1
                        Dim 變數 As String = "" : Dim 取變數 As String
                        取變數 = 明細_dgv.Rows(明細_dgv.SelectedCells.Item(i).RowIndex).Cells(明細_dgv.SelectedCells.Item(i).ColumnIndex).Value
                        For ii As Integer = 1 To Len(取變數)
                            If ii = 1 Then : 變數 = Strings.Left(取變數, ii) : Else : If Strings.Mid(取變數, ii, 1) <> "," Then : 變數 &= Strings.Mid(取變數, ii, 1) : End If : End If
                        Next : x += CLng(變數)
                    Next i : FH_ERP_SYS.合計_TSSL.Text = "Total : " & Strings.Format(x, "#,##0")
                Else : FH_ERP_SYS.合計_TSSL.Text = "Total : " & Strings.Format(0, "#,##0") : End If
            Else : 已超出 = True : FH_ERP_SYS.合計_TSSL.Text = "Total : " & 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
            物料圖2_pb.Image = Nothing : 物料圖1_pb.Image = Nothing
            PA2 = 明細_dgv.Rows(e.RowIndex).Cells("料號原則").Value : SQL_物料圖庫_圖檔讀取一()
            While dr.Read() = True
                Dim unused As Byte() = New Byte(-1) {}
                Dim bytes As Byte() = DirectCast(dr.Item("圖檔"), Byte())
                Dim oStream As New MemoryStream(bytes)
                物料圖1_pb.Image = Bitmap.FromStream(oStream)
            End While
            conn.Close() : 物料圖1_pb.SizeMode = 4
            料號1_tb.Text = 明細_dgv("料號", e.RowIndex).Value.ToString
            品名_tb.Text = 明細_dgv("品名", e.RowIndex).Value.ToString
            If 歷史單價_P.Visible = True Then : Set_料號比價() : 繪圖() : 料號_dgv.Sort(料號_dgv.Columns("排序"), System.ComponentModel.ListSortDirection.Descending) : End If
        End If
        價格()
    End Sub
    Private Sub 明細_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 明細_dgv.CellEnter
        總金額計算() : 價格()
    End Sub
    Private Sub 請購單_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 請購單_dgv.CellClick
        選擇公司_cb.Enabled = True : 採購選擇 = "A"
        If e.RowIndex = -1 Then : Else
            QQQ1 = 請購單_dgv(0, e.RowIndex).Value.ToString : QQQ2 = 請購單_dgv(3, e.RowIndex).Value.ToString : QQQ3 = 請購單_dgv(4, e.RowIndex).Value.ToString
            If 請購單_dgv.Rows(e.RowIndex).Cells("用途").Value.ToString = "" Then : 使用地點_tb.Text = "" : Else
                使用地點_tb.Text = 請購單_dgv.Rows(e.RowIndex).Cells("用途").Value.ToString & "-" & 請購單_dgv.Rows(e.RowIndex).Cells("倉名").Value
            End If
            折扣比_tb.Text = "0" : 稅金計算_ch.Checked = True : 稅金比_tb.Text = "10" : 採購單號_tb.Text = ""
        End If : Set_明細清單()
    End Sub
    Private Sub 採購單_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 採購單_dgv.CellClick
        PA = "" : 廠商清空()
        選擇公司_cb.Enabled = False : 採購選擇 = "B"
        If e.RowIndex = -1 Then : Else
            採購單號_tb.Text = 採購單_dgv(0, e.RowIndex).Value.ToString : 折扣比_tb.Text = 採購單_dgv(13, e.RowIndex).Value.ToString : 稅金計算_ch.Checked = 採購單_dgv(14, e.RowIndex).Value
            稅金比_tb.Text = 採購單_dgv(15, e.RowIndex).Value.ToString : 核對員_tb.Text = 採購單_dgv(4, e.RowIndex).Value.ToString : 核對日期_tb.Text = 採購單_dgv(5, e.RowIndex).Value.ToString
            詢價員_tb.Text = 採購單_dgv(6, e.RowIndex).Value.ToString : 尋價日期_tb.Text = 採購單_dgv(7, e.RowIndex).Value.ToString : 手動號碼_tb.Text = 採購單_dgv(18, e.RowIndex).Value.ToString
            If Strings.Left(採購單號_tb.Text, 3) = "HXI" Then
                選擇公司_cb.Text = "PT HONG XHE INDUSTRIAL"
            ElseIf Strings.Left(採購單號_tb.Text, 3) = "PGS" Then
                選擇公司_cb.Text = "PT PUNCAK GEMILANG SEMESTA" : End If

            供應商編碼_tb.Text = 採購單_dgv(1, e.RowIndex).Value.ToString : conn.Close()
            PA1 = 供應商編碼_tb.Text : SQL_建築物料採購單生成_供應商資料一()
            If dr.Read() Then : 廠商_cb.Text = dr("公司名") : conn.Close() : Else : 廠商_cb.Text = "" : End If : conn.Close()
            使用地點_tb.Text = 採購單_dgv(3, e.RowIndex).Value.ToString : 需求日期_dtp.Value = 採購單_dgv(2, e.RowIndex).Value
            Set_明細清單() : 歷史單價_P.Visible = False

            PA1 = 廠商_cb.Text : SQL_建築物料採購單生成_供應商資料二()
            If dr.Read() Then
                付款條件_tb.Text = dr("付款條件").ToString : 地址_tb.Text = dr("公司地址").ToString : 電話_tb.Text = dr("公司電話1").ToString : 郵件_tb.Text = dr("聯繫人1郵箱").ToString
                傳真_tb.Text = dr("公司傳真1").ToString : 供應商編碼_tb.Text = dr("供應商編碼").ToString
            End If : conn.Close()
        End If
    End Sub
    Private Sub 廠商_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 廠商_cb.SelectedIndexChanged
        PA1 = 廠商_cb.Text : SQL_建築物料採購單生成_供應商資料二()
        If dr.Read() Then
            付款條件_tb.Text = dr("付款條件").ToString : 地址_tb.Text = dr("公司地址").ToString : 電話_tb.Text = dr("公司電話1").ToString : 郵件_tb.Text = dr("聯繫人1郵箱").ToString
            傳真_tb.Text = dr("公司傳真1").ToString : 供應商編碼_tb.Text = dr("供應商編碼").ToString
        End If : conn.Close()
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Strings.Format(Today(), "yyyy/MM/dd") : DTP1 = Strings.Format(Today(), "yyyyMMdd") : DTP2 = Strings.Format(需求日期_dtp.Value, "yyyy/MM/dd")
    End Sub
    Private Sub 類別管理_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 類別管理_cb.SelectedIndexChanged
        PA20 = 類別管理_cb.Text : SQL_供應商類別管理_查詢()
        If dr.Read() Then : 供應商簡稱_tb.Text = dr("編碼").ToString : Else : 供應商簡稱_tb.Text = "" : End If
        PA = 供應商簡稱_tb.Text : 廠商_cb_下拉表單資料載入()
    End Sub
    Private Sub 供應商編碼_tb_TextChanged(sender As Object, e As EventArgs) Handles 供應商編碼_tb.TextChanged
        Set_清單3()
    End Sub
    Private Sub 清空供應商_bt_Click(sender As Object, e As EventArgs) Handles 清空供應商_bt.Click
        If 採購單號_tb.Text = "" Then : Else
            SQL_採購單供應商_清空() : 廠商_cb.Text = "" : 地址_tb.Text = "" : 電話_tb.Text = "" : 郵件_tb.Text = "" : 傳真_tb.Text = ""
            供應商編碼_tb.Text = "" : MsgBox("清除完成!!")
        End If
    End Sub
    Private Sub 折扣比_tb_TextChanged(sender As Object, e As EventArgs) Handles 折扣比_tb.TextChanged
        總金額計算()
    End Sub
    Private Sub 稅金計算_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 稅金計算_ch.CheckedChanged
        總金額計算()
    End Sub
    Private Sub 稅金比_tb_TextChanged(sender As Object, e As EventArgs) Handles 稅金比_tb.TextChanged
        總金額計算()
    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 生成採購單_bt_Click(sender As Object, e As EventArgs) Handles 生成採購單_bt.Click
        If 採購選擇 = "A" Then : 生成新的採購訂單() : ElseIf 採購選擇 = "B" Then : 修改的採購單存檔() : End If : Set_清單2()
    End Sub
    Private Sub 生成新的採購訂單()
        If 選擇公司_cb.Text = "PT HONG XHE INDUSTRIAL" Then
            Set_日期格式轉換() : Dim NUM1 As Integer
            For i As Integer = 1 To 999
                NUM1 = 0 + i
                If NUM1 < 10 Then : 採購單號_tb.Text = "HXI-C-" & DTP1 & "-00" & NUM1
                ElseIf NUM1 > 9 And NUM1 < 100 Then : 採購單號_tb.Text = "HXI-C-" & DTP1 & "-0" & NUM1
                ElseIf NUM1 > 99 Then : 採購單號_tb.Text = "HXI-C-" & DTP1 & "-" & NUM1
                End If
                PA1 = 採購單號_tb.Text
                SQL_採購單控制表_單號最後一筆() : If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
            Next
            確定新增()
        ElseIf 選擇公司_cb.Text = "PT PUNCAK GEMILANG SEMESTA" Then
            Set_日期格式轉換() : Dim NUM1 As Integer
            For i As Integer = 1 To 999
                NUM1 = 0 + i
                If NUM1 < 10 Then : 採購單號_tb.Text = "PGS-C-" & DTP1 & "-00" & NUM1
                ElseIf NUM1 > 9 And NUM1 < 100 Then : 採購單號_tb.Text = "PGS-C-" & DTP1 & "-0" & NUM1
                ElseIf NUM1 > 99 Then : 採購單號_tb.Text = "PGS-C-" & DTP1 & "-" & NUM1
                End If
                PA1 = 採購單號_tb.Text
                SQL_採購單控制表_單號最後一筆() : If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
            Next
            確定新增()
        End If
    End Sub
    Private Sub 修改的採購單存檔()
        If 廠商_cb.Text = "" Then : MsgBox("沒有選擇供應商!!") : Else : Set_日期格式轉換()
            PA1 = 供應商編碼_tb.Text : PA2 = 使用地點_tb.Text : PA3 = 折扣比_tb.Text : BL1 = 稅金計算_ch.Checked : PA4 = 稅金比_tb.Text : PA5 = 採購單號_tb.Text
            PA39 = 手動號碼_tb.Text : SQL_採購單控制表_編輯() : conn.Close()
            For i As Integer = 0 To 明細_dgv.Rows.Count - 1
                資料數 = 明細_dgv.Rows.Count : MyMod.進度條()
                PA6 = 明細_dgv.Rows(i).Cells("備註").Value : PA7 = 明細_dgv.Rows(i).Cells("單價").Value
                PA8 = 明細_dgv.Rows(i).Cells("數量").Value : PA9 = 明細_dgv.Rows(i).Cells("單位").Value
                PA10 = 明細_dgv.Rows(i).Cells("項次").Value : PA4 = 明細_dgv.Rows(i).Cells("KEY").Value
                SQL_採購單明細表_修改() : conn.Close()
            Next
            Set_清單1() : Set_清單2() : MsgBox("採購單修改完畢!!") : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        End If
    End Sub
    Private Sub 確定新增()
        Set_日期格式轉換()
        If 採購單號_tb.Text = "" Or 供應商編碼_tb.Text = "" Or 明細_dgv.Rows.Count = 0 Then : MsgBox("資料未齊全!!") : Else
            PA1 = 採購單號_tb.Text : PA2 = 供應商編碼_tb.Text : PA3 = 使用地點_tb.Text : PA4 = QQQ2
            PA5 = QQQ3 : PA6 = QQQ1 : PA7 = 折扣比_tb.Text : BL1 = 稅金計算_ch.Checked : PA8 = 稅金比_tb.Text
            SQL_採購單控制表_新增() : SQL_請購單控制表_轉採修改() : conn.Close()
            For i As Integer = 0 To 明細_dgv.Rows.Count - 1
                資料數 = 明細_dgv.Rows.Count : MyMod.進度條()
                If 明細_dgv.Rows(i).Cells("已採購").Value = True Then
                    PA9 = 明細_dgv.Rows(i).Cells("已採購").Value : PA2 = 明細_dgv.Rows(i).Cells("採購單號").Value : PA3 = 明細_dgv.Rows(i).Cells("項次").Value
                    PA4 = 明細_dgv.Rows(i).Cells("品名").Value : PA5 = 明細_dgv.Rows(i).Cells("規格").Value : PA6 = 明細_dgv.Rows(i).Cells("備註").Value
                    NU1 = 明細_dgv.Rows(i).Cells("數量").Value : PA8 = 明細_dgv.Rows(i).Cells("單位").Value : PA10 = 明細_dgv.Rows(i).Cells("金額").Value
                    PA11 = 明細_dgv.Rows(i).Cells("群組碼").Value : PA12 = 明細_dgv.Rows(i).Cells("料號原則").Value : PA13 = 明細_dgv.Rows(i).Cells("料號").Value
                    SQL_請購單明細表_轉採修改() : SQL_採購單明細表_新增() : conn.Close()
                End If
            Next
            Set_清單1() : Set_清單2() : MsgBox("採購單開立完畢!!") : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        End If
    End Sub
    Private Sub 料號_bt_Click(sender As Object, e As EventArgs) Handles 分析工具_bt.Click
        Set_料號比價()
        If 料號1_tb.Text = "" Then : MsgBox("並未指定品名!!") : Else
            If 歷史單價_P.Visible = True Then : 歷史單價_P.Visible = False
            Else : 歷史單價_P.Visible = True : 繪圖() : 料號_dgv.Sort(料號_dgv.Columns("排序"), System.ComponentModel.ListSortDirection.Descending) : End If
        End If
    End Sub
    Private Sub 繪圖()
        Chart1.Series.Clear() : Chart1.ChartAreas(0).AxisX.Minimum = 0
        If 品名_tb.Text <> "" Then
            If 折線圖_ch.Checked = True Then
                Chart1.Series.Add(品名_tb.Text & "_1") : Chart1.Series(品名_tb.Text & "_1").ChartType = SeriesChartType.Line
                Chart1.Series(品名_tb.Text & "_1").IsVisibleInLegend = False
            End If
            If 長條圖_ch.Checked = True Then
                Chart1.Series.Add(品名_tb.Text) : Chart1.Series(品名_tb.Text).ChartType = SeriesChartType.Column
            End If
            For i As Integer = 0 To 料號_dgv.Rows.Count - 1
                Chart1.Series(品名_tb.Text).Points.AddXY(料號_dgv.Rows(i).Cells("合約號").Value.ToString, 料號_dgv.Rows(i).Cells("金額").Value.ToString)
            Next
        End If
    End Sub
    Private Sub 小間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距_ch.Click
        小間距_ch.Checked = True : 中間距_ch.Checked = False : 大間距_ch.Checked = False : Set_明細清單()
    End Sub
    Private Sub 中間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False : Set_明細清單()
    End Sub
    Private Sub 大間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = False : 大間距_ch.Checked = True : Set_明細清單()
    End Sub
    Private Sub 類別管理_cb_Click(sender As Object, e As EventArgs) Handles 類別管理_cb.Click
        CB選擇清單(類別管理_cb, 類別管理_cb.Text)
    End Sub
    Private Sub 廠商_cb_Click(sender As Object, e As EventArgs) Handles 廠商_cb.Click
        CB選擇清單(廠商_cb, 廠商_cb.Text)
    End Sub
    Private Sub 選擇公司_cb_Click(sender As Object, e As EventArgs) Handles 選擇公司_cb.Click
        CB選擇清單(選擇公司_cb, 選擇公司_cb.Text)
    End Sub
    Private Sub 物料圖1_pb_Click(sender As Object, e As EventArgs) Handles 物料圖1_pb.Click
        If IsNothing(物料圖1_pb.Image) = False Then : 圖片傳遞 = 物料圖1_pb.Image : 圖片放大視窗.ShowDialog() : End If
    End Sub
    Private Sub 未指定_ch_Click(sender As Object, e As EventArgs) Handles 未指定_ch.Click
        未指定_ch.Checked = True : 已指定_ch.Checked = False : Set_清單2()
    End Sub
    Private Sub 已指定_ch_Click(sender As Object, e As EventArgs) Handles 已指定_ch.Click
        未指定_ch.Checked = False : 已指定_ch.Checked = True : Set_清單2()
    End Sub
    Private Sub 詳細資料2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 詳細資料2_ch.Click
        If 詳細資料2_ch.Checked = True Then : 詳細資料2_ch.Checked = True : Else : 詳細資料2_ch.Checked = False : End If : Set_明細清單()
    End Sub
    Private Sub 列印成詢價單_bt_Click(sender As Object, e As EventArgs) Handles 列印成詢價單_bt.Click
        If 採購單號_tb.Text = "" Then : MsgBox("資料未齊全!!") : Else
            Dim ds6 As New DataSet : 請購資料_dgv.DataSource = Nothing : ds6.Clear()
            請購資料_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
            請購資料_dgv.ColumnHeadersHeight = 25 : 請購資料_dgv.AllowUserToAddRows = False
            PA38 = 採購單號_tb.Text : SQL_採購資料() : da.Fill(ds6) : 請購資料_dgv.DataSource = ds6.Tables(0) : conn.Close()

            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
            N1 = 0 : N2 = 0
            xlSheet.Cells(2, 1) = "屏東縣長治鄉神農東路22號" : xlSheet.Cells(3, 1) = "電話:(08)762-0588 傳真:(08)762-0599"
            xlSheet.Cells(4, 1) = "採購單"
            xlSheet.Cells(5, 1) = "廠商名稱 : " & 廠商_cb.Text : xlSheet.Cells(6, 1) = "聯絡地址 : " & 地址_tb.Text : xlSheet.Cells(7, 1) = "電話 : " & 電話_tb.Text
            xlSheet.Cells(8, 1) = "傳真 : " & 傳真_tb.Text : xlSheet.Cells(9, 1) = "Email    : " & 郵件_tb.Text

            xlSheet.Cells(6, 5) = "聯絡人 : "
            xlSheet.Cells(5, 5) = "採購日期 : " : xlSheet.Cells(5, 6) = Strings.Format(Today(), "yyyy/MM/dd")
            xlSheet.Cells(7, 5) = "採購單號 : " : xlSheet.Cells(7, 6) = 採購單號_tb.Text
            xlSheet.Cells(8, 5) = "需求日期 : " : xlSheet.Cells(8, 6) = 需求日期_dtp.Value
            xlSheet.Cells(9, 5) = "送貨地點 : " : xlSheet.Cells(9, 6) = 使用地點_tb.Text

            xlSheet.Cells(10, 1) = "No." : xlSheet.Cells(10, 2) = "圖號/料號" : xlSheet.Cells(10, 3) = "品名" : xlSheet.Cells(10, 4) = "規格" : xlSheet.Cells(10, 5) = "單位"
            xlSheet.Cells(10, 6) = "數量" : xlSheet.Cells(10, 7) = "單價" : xlSheet.Cells(10, 8) = "金額"

            Dim GGHH As Integer = 0
            For i As Integer = 0 To 明細_dgv.Rows.Count - 1
                xlSheet.Cells(i + 11, 1) = 明細_dgv.Rows(i).Cells("No").Value : xlSheet.Cells(i + 11, 2) = 明細_dgv.Rows(i).Cells("料號").Value
                xlSheet.Cells(i + 11, 3) = 明細_dgv.Rows(i).Cells("品名").Value : xlSheet.Cells(i + 11, 4) = 明細_dgv.Rows(i).Cells("規格").Value
                xlSheet.Cells(i + 11, 5) = 明細_dgv.Rows(i).Cells("單位").Value : xlSheet.Cells(i + 11, 6) = 明細_dgv.Rows(i).Cells("數量").Value
                xlSheet.Cells(i + 11, 7) = 明細_dgv.Rows(i).Cells("單價").Value : xlSheet.Cells(i + 11, 8) = 明細_dgv.Rows(i).Cells("金額").Value
                'xlSheet.Cells(i + 11, 4) = 明細1_dgv.Rows(i).Cells("備註").Value
                GGHH += 明細_dgv.Rows(i).Cells("金額").Value
                N1 = i + 11
            Next i
            xlSheet.Cells(N1 + 2, 1) = "付款方式 : " & 付款條件_tb.Text : xlSheet.Cells(N1 + 2, 7) = "採購淨額 :" : xlSheet.Cells(N1 + 2, 8) = GGHH
            xlSheet.Cells(N1 + 3, 1) = "進貨地址 : 屏東縣長治鄉神農東路22" : xlSheet.Cells(N1 + 3, 7) = "折扣 " & 折扣比_tb.Text & "% :" : xlSheet.Cells(N1 + 3, 8) = 折扣金額_tb.Text
            xlSheet.Cells(N1 + 4, 1) = "備註 : " & 手動號碼_tb.Text
            xlSheet.Cells(N1 + 4, 7) = "稅額 " & 稅金比_tb.Text & "% :" : xlSheet.Cells(N1 + 4, 8) = 稅金金額_tb.Text
            xlSheet.Cells(N1 + 5, 7) = "總金額 :" : xlSheet.Cells(N1 + 5, 8) = 總金額_tb.Text
            xlSheet.Cells(N1 + 6, 1) = "核准"
            xlSheet.Cells(N1 + 6, 3) = "覆審"
            xlSheet.Cells(N1 + 6, 4) = "初審"
            xlSheet.Cells(N1 + 6, 6) = "詢價員"
            xlSheet.Cells(N1 + 6, 8) = "採購人員"
            xlSheet.Cells(N1 + 12, 1) = "廠商回簽" : N2 = 10

            AA(xlApp, xlSheet) : GG(xlApp, xlSheet) : FF(xlApp, xlSheet) ': EE(xlApp, xlSheet) : CC(xlApp, xlSheet) DD(xlApp, xlSheet)
            '-------------轉換成PDF---------------------------------------------------------------------
            Dim SERT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & 採購單號_tb.Text & "_PO(採購單).pdf", XlFixedFormatQuality.xlQualityStandard, True)
            '-------------關閉EXCEL---------------------------------------------------------------------
            xlSheet.PageSetup.PrintArea = "" : xlApp.Cells.Select()
            xlApp.Application.WindowState = xlMinimized
            xlBook.Close(False)
            Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
            Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
            Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
            xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
            '-------------開啟PDF---------------------------------------------------------------------
            Dim pdfFilePath As String = SERT & "\" & 採購單號_tb.Text & "_PO(採購單).pdf"
            If IsChromeInstalled() Then
                Try
                    Dim chromeProcess As New Process()
                    chromeProcess.StartInfo.FileName = "chrome"
                    chromeProcess.StartInfo.Arguments = """" & pdfFilePath & """"
                    chromeProcess.Start()
                Catch ex As Exception
                End Try
            Else
                Try
                    System.Diagnostics.Process.Start("""" & pdfFilePath & """")
                Catch ex As Exception
                End Try
            End If
            MsgBox("列印完成!!")
        End If
    End Sub
    ' 檢查系統是否已安裝 Google Chrome
    Private Function IsChromeInstalled() As Boolean
        Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
        If key IsNot Nothing Then
            For Each subkeyName As String In key.GetSubKeyNames()
                Dim subkey As Microsoft.Win32.RegistryKey = key.OpenSubKey(subkeyName)
                Dim displayName As Object = subkey.GetValue("DisplayName")

                If displayName IsNot Nothing AndAlso displayName.ToString().Contains("Google Chrome") Then
                    Return True
                End If
            Next
        End If
        Return False
    End Function
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub AA(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.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 6 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 24
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 30 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 25
        xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 10 : xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 15 : xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 25

        xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 90 : xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 20
        xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 20 : xlSheet.Rows("4:4").Select : myExcel.Selection.RowHeight = 25
        xlSheet.Rows("5:9").Select : myExcel.Selection.RowHeight = 20 : xlSheet.Rows("10:10").Select : myExcel.Selection.RowHeight = 20
        xlSheet.Rows("11:" & N1).Select : myExcel.Selection.RowHeight = 65 : xlSheet.Rows(N1 + 1 & ":" & N1 + 1).Select : myExcel.Selection.RowHeight = 5
        xlSheet.Rows(N1 + 2 & ":" & N1 + 5).Select : myExcel.Selection.RowHeight = 17 : xlSheet.Rows(N1 + 6 & ":" & N1 + 6).Select : myExcel.Selection.RowHeight = 35
        xlSheet.Rows(N1 + 7 & ":" & N1 + 9).Select : myExcel.Selection.RowHeight = 35

        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
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 26 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With

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

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

        xlSheet.Range("A" & N1 + 2 & ":H" & N1 + 2).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = 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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("A" & N1 + 3 & ":H" & N1 + 3).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("A" & N1 + 4 & ":H" & N1 + 4).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
        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
        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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A" & N1 + 6 & ":B" & N1 + 6).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
        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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("C" & N1 + 6 & ":C" & N1 + 6).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
        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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("D" & N1 + 6 & ":E" & N1 + 6).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
        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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("F" & N1 + 6 & ":G" & N1 + 6).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
        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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("H" & N1 + 6).Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : 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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A" & N1 + 7 & ":B" & N1 + 9).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("C" & N1 + 7 & ":C" & N1 + 9).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("D" & N1 + 7 & ":E" & N1 + 9).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("F" & N1 + 7 & ":G" & N1 + 9).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        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("H" & N1 + 7 & ":H" & N1 + 9).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        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("A10:A" & N1).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("B11:D" & N1).Select()
        With myExcel.Selection
            .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
            .ReadingOrder = xlContext : .MergeCells = False : End With

        xlSheet.Range("E11:F" & N1).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("G11:H" & N1).Select() : myExcel.Selection.NumberFormatLocal = "#,##0"
        xlSheet.Range("H" & N1 + 2).Select() : myExcel.Selection.NumberFormatLocal = "#,##0"

        xlSheet.Range("H" & N1 + 2 & ":H" & 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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With

        myExcel.ActiveWindow.DisplayGridlines = False

        xlSheet.Range("A4:H4").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 = xlThin : End With
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

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

        xlSheet.Range("A10:H" & N1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        xlSheet.Range("A" & N1 + 2 & ":H" & 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 = 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(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        xlSheet.Range("A" & N1 + 6 & ":B" & N1 + 9).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        xlSheet.Range("C" & N1 + 6 & ":C" & N1 + 9).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        xlSheet.Range("D" & N1 + 6 & ":E" & N1 + 9).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        xlSheet.Range("F" & N1 + 6 & ":G" & N1 + 9).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        xlSheet.Range("H" & N1 + 6 & ":H" & N1 + 9).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone

        xlSheet.Rows("5:9").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.Rows("11:" & N1).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("A10:H10").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        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 = xlMedium : End With
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        xlSheet.Range("A11:H" & N1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        xlSheet.Range("B11:D" & N1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        xlSheet.Range("F11:F" & N1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        xlSheet.Range("H11:H" & N1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        xlSheet.Range("A" & N1 + 2 & ":H" & 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 = 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(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With
        xlSheet.Range("H" & N1 + 2 & ":H" & 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 = 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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With

        xlSheet.Range("G" & N1 + 2 & ":G" & N1 + 5).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("F" & N1 + 8 & ":G" & N1 + 8).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("F" & N1 + 9 & ":G" & N1 + 9).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("A" & N1 + 8 & ":B" & N1 + 8).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("A" & N1 + 9 & ":B" & N1 + 9).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("C" & N1 + 9).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("A" & N1 + 11 & ":H" & N1 + N2 + 11).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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A2:H3").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("A4:H4").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 18 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
        myExcel.Selection.Font.Bold = True

        xlSheet.Range("A" & N1 + 4 & ":F" & N1 + 5).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 : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
        xlSheet.Range("G" & N1 + 2 & ":G" & 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 = xlHairline : 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
        myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlHairline : End With

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

        xlSheet.Range("D" & N1 + 8 & ":E" & N1 + 8).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("D" & N1 + 9 & ":E" & N1 + 9).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

        Dim 攔寬 As Single
        xlSheet.Rows("11:" & N1).Select : xlSheet.Rows("11:" & N1).EntireRow.AutoFit
        For i As Integer = 11 To N1
            xlSheet.Rows(i & ":" & i).Select
            攔寬 = xlSheet.Rows(i & ":" & i).RowHeight
            xlSheet.Rows(i & ":" & i).Select : myExcel.Selection.RowHeight = 攔寬 + 20
        Next
        myExcel.ActiveSheet.PageSetup.CenterHeaderPicture.Filename =
            Str01 & "\FHBWLOG.png"

        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$10" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = ""
            .CenterHeader = "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "&G"
            .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "第 &P 頁，共 &N 頁" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.236220472440945) : .RightMargin = myExcel.Application.InchesToPoints(0.236220472440945)
            .TopMargin = myExcel.Application.InchesToPoints(0.748031496062992) : .BottomMargin = myExcel.Application.InchesToPoints(0.748031496062992)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.31496062992126) : .FooterMargin = myExcel.Application.InchesToPoints(0.31496062992126)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
            .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = False : .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 : myExcel.Application.PrintCommunication = True
    End Sub
    Private Sub GG(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)
        Clipboard.SetDataObject(請購單核准.PB1.Image)
        xlSheet.Range("A1").Select()
        myExcel.ActiveSheet.Pictures.Paste.Select
        myExcel.Selection.ShapeRange.Height = 93
        myExcel.Selection.ShapeRange.IncrementLeft(50)
        myExcel.Selection.ShapeRange.IncrementTop(0)
    End Sub
    Private Sub FF(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$11" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "第 &P 頁，共 &N 頁" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.236220472440945) : .RightMargin = myExcel.Application.InchesToPoints(0.236220472440945)
            .TopMargin = myExcel.Application.InchesToPoints(0.748031496062992) : .BottomMargin = myExcel.Application.InchesToPoints(0.748031496062992)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.31496062992126) : .FooterMargin = myExcel.Application.InchesToPoints(0.31496062992126)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
            .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = False : .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 : myExcel.Application.PrintCommunication = True
    End Sub
End Class