Imports System.Runtime.InteropServices
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 Telerik.Windows.Documents.Fixed
Imports Microsoft.Office.Core
Public Class 報修單
    Dim xlApp As Application
    Dim xlBook As Workbook
    Dim xlSheet As Worksheet
    Dim 已開啟 As Boolean = False
    Dim 不執行下拉刷新 As Boolean = False
    Private Sub Set_清單()
        Dim ds1 As New DataSet
        清單_dgv.DataSource = Nothing : ds1.Clear()
        清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        清單_dgv.ColumnHeadersHeight = 25 : 清單_dgv.AllowUserToAddRows = False : 清單_dgv.RowTemplate.Height = 35
        Dim 單據狀態 As String : If 未維修_ch.Checked Then : 單據狀態 = "未維修" : Else : 單據狀態 = "已維修" : End If
        SQL_報修單清單(單據狀態)
        da.Fill(ds1) : 清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        For i As Integer = 1 To 清單_dgv.Columns.Count - 1
            清單_dgv.Columns(i).Visible = False
        Next
    End Sub

    Private Sub Set_下拉租客()
        SQL_租客類別(鄰近地址_cb.Text, 門牌_cb.Text) : 承租客_cb.Items.Clear() : 承租客_cb.Items.Add("") : While (dr.Read()) : 承租客_cb.Items.Add(dr(0) & "-" & dr(1)) : End While : conn.Close()
    End Sub
    Private Sub Set_下拉鄰近地址()
        SQL_鄰近地址類別("S") : 鄰近地址_cb.Items.Clear() : 鄰近地址_cb.Items.Add("") : While (dr.Read()) : 鄰近地址_cb.Items.Add(dr(0)) : End While : conn.Close()
    End Sub
    Private Sub Set_下拉門牌()
        SQL_門牌類別(鄰近地址_cb.Text) : 門牌_cb.Items.Clear() : 門牌_cb.Items.Add("") : While (dr.Read()) : 門牌_cb.Items.Add(dr(0)) : End While : conn.Close()
    End Sub
    Private Sub 報修單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        已開啟 = False : 未維修_ch.Checked = True : 已維修_ch.Checked = False
        申請日期_dtp.CustomFormat = "yyyy/MM/dd" : 申請日期_dtp.Value = Today()
        報修人_tb.Text = "" : 連絡電話_tb.Text = "" : 接洽人員_tb.Text = "" : 報修單號_tb.Text = "" : 承租客_cb.Text = "" : 原因_tb.Text = "" : 鄰近地址_cb.Text = "" : 門牌_cb.Text = ""
        維修狀況_tb.Text = "" : 維修人員_tb.Text = "" : 門牌_cb.Enabled = False : 承租客_cb.Enabled = False
        報修日期_dtp.Format = DateTimePickerFormat.Custom : 報修日期_dtp.CustomFormat = " "
        維修日期_dtp.Format = DateTimePickerFormat.Custom : 維修日期_dtp.CustomFormat = " "
        Set_清單() : Set_下拉鄰近地址()  'Set_下拉租客()
        已開啟 = True
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        申請日期_dtp.CustomFormat = "yyyy/MM/dd" : 申請日期_dtp.Value = Today()
        報修人_tb.Text = "" : 連絡電話_tb.Text = "" : 接洽人員_tb.Text = "" : 報修單號_tb.Text = "" : 承租客_cb.Text = "" : 原因_tb.Text = ""
        維修狀況_tb.Text = "" : 維修人員_tb.Text = "" : 鄰近地址_cb.Text = "" : 門牌_cb.Text = ""
        報修日期_dtp.Format = DateTimePickerFormat.Custom : 報修日期_dtp.CustomFormat = " "
        維修日期_dtp.Format = DateTimePickerFormat.Custom : 維修日期_dtp.CustomFormat = " "
        Dim 流水號 As String
        SQL_查詢最後一筆報修單號()
        If dr.Read() Then : 流水號 = dr(0).ToString : Else
            流水號 = "GN-" & Today.Year.ToString.PadLeft(4, "0") & Today.Month.ToString.PadLeft(2, "0") & Today.Day.ToString.PadLeft(2, "0") & "-000"
        End If
        Dim 新流水 As Integer = Integer.Parse(流水號.Substring(流水號.Length - 3)) : 新流水 += 1
        報修單號_tb.Text = "GN-" & Today.Year.ToString.PadLeft(4, "0") & Today.Month.ToString.PadLeft(2, "0") & Today.Day.ToString.PadLeft(2, "0") & "-" & 新流水.ToString.PadLeft(3, "0")
        SQL_報修單_新增(報修單號_tb.Text, 申請日期_dtp.Value) : Set_清單()
        MsgBox("已新增報修單")
    End Sub

    Private Sub 未維修_ch_Click(sender As Object, e As EventArgs) Handles 未維修_ch.Click
        未維修_ch.Checked = True : 已維修_ch.Checked = False : If 已開啟 Then : Set_清單() : End If
    End Sub

    Private Sub 已維修_ch_Click(sender As Object, e As EventArgs) Handles 已維修_ch.Click
        未維修_ch.Checked = False : 已維修_ch.Checked = True : If 已開啟 Then : Set_清單() : End If
    End Sub

    Private Sub 清單_dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles 清單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            不執行下拉刷新 = True
            報修單號_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("報修單號").Value.ToString : 報修人_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("報修人").Value.ToString
            連絡電話_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("連絡電話").Value.ToString : 接洽人員_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("接洽人員").Value.ToString
            承租客_cb.Text = 清單_dgv.Rows(e.RowIndex).Cells("承租客").Value.ToString : 案場_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("案場").Value.ToString
            鄰近地址_cb.Text = 清單_dgv.Rows(e.RowIndex).Cells("鄰近地址").Value.ToString : 原因_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("原因").Value.ToString
            維修狀況_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("維修狀況").Value.ToString : 維修人員_tb.Text = 清單_dgv.Rows(e.RowIndex).Cells("維修人員").Value.ToString
            門牌_cb.Text = 清單_dgv.Rows(e.RowIndex).Cells("門牌").Value.ToString
            If 清單_dgv.Rows(e.RowIndex).Cells("報修日期").Value.ToString = "" Then : 報修日期_dtp.CustomFormat = " " : Else
                If 清單_dgv.Rows(e.RowIndex).Cells("報修日期").Value.ToString = " " Then : 報修日期_dtp.CustomFormat = " " : Else
                    報修日期_dtp.CustomFormat = "yyyy/MM/dd" : 報修日期_dtp.Value = 清單_dgv.Rows(e.RowIndex).Cells("報修日期").Value.ToString
                End If
            End If
            If 清單_dgv.Rows(e.RowIndex).Cells("維修日期").Value.ToString = "" Then : 維修日期_dtp.CustomFormat = " " : Else
                If 清單_dgv.Rows(e.RowIndex).Cells("維修日期").Value.ToString = " " Then : 維修日期_dtp.CustomFormat = " " : Else
                    維修日期_dtp.CustomFormat = "yyyy/MM/dd" : 維修日期_dtp.Value = 清單_dgv.Rows(e.RowIndex).Cells("維修日期").Value.ToString
                End If
            End If
            If 清單_dgv.Rows(e.RowIndex).Cells("申請日期").Value.ToString = "" Then : 申請日期_dtp.CustomFormat = " " : Else
                If 清單_dgv.Rows(e.RowIndex).Cells("申請日期").Value.ToString = " " Then : 申請日期_dtp.CustomFormat = " " : Else
                    申請日期_dtp.CustomFormat = "yyyy/MM/dd" : 申請日期_dtp.Value = 清單_dgv.Rows(e.RowIndex).Cells("申請日期").Value.ToString
                End If
            End If
            不執行下拉刷新 = False
        End If
    End Sub

    Private Sub 承租客_cb_TextChanged(sender As Object, e As EventArgs) Handles 承租客_cb.TextChanged
        If 已開啟 And 承租客_cb.Text <> "" And 承租客_cb.Text.Contains("-") And 承租客_cb.Text.Length > 3 Then
            Dim parts() As String = 承租客_cb.Text.Split("-"c) : 案場_tb.Text = parts(1)
        Else
            案場_tb.Text = ""
        End If
    End Sub
    Private Sub 鄰近地址_cb_TextChanged(sender As Object, e As EventArgs) Handles 鄰近地址_cb.TextChanged
        If 鄰近地址_cb.Text = "" Then : 門牌_cb.Enabled = False : 承租客_cb.Enabled = False : 承租客_cb.Text = "" : 門牌_cb.Text = "" : Else
            門牌_cb.Enabled = True : 承租客_cb.Enabled = True
            If 已開啟 Then
                If 不執行下拉刷新 = False Then : 承租客_cb.Text = "" : 門牌_cb.Text = "" : End If : Set_下拉門牌() : Set_下拉租客()
            End If
        End If
    End Sub
    Private Sub 門牌_cb_TextChanged(sender As Object, e As EventArgs) Handles 門牌_cb.TextChanged
        If 已開啟 Then : If 不執行下拉刷新 = False Then : 承租客_cb.Text = "" : End If : Set_下拉租客() : End If
    End Sub

    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If 報修單號_tb.Text = "" Then : MsgBox("請先選擇報修單資料，才能繼續後續的操作!!") : Else
            Dim result As DialogResult = MessageBox.Show("請確定是否要刪除選定的報修單資料?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If result = DialogResult.Yes Then
                Dim 回應 As String : 回應 = InputBox("請輸入大寫 [YES]，並按下確認來刪除資料!!")
                If 回應 = "YES" Then : SQL_報修單刪除(報修單號_tb.Text) : Set_清單() : MsgBox("刪除完成!!") : End If
            End If
        End If
    End Sub

    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        If 報修單號_tb.Text = "" Then : MsgBox("請先選擇報修單資料，才能繼續後續的操作!!") : Else
            SQL_報修單_修改(報修單號_tb.Text, 報修人_tb.Text, 報修日期_dtp.Value, 連絡電話_tb.Text, 接洽人員_tb.Text, 承租客_cb.Text, 案場_tb.Text, 鄰近地址_cb.Text,
                       原因_tb.Text, 維修日期_dtp.Value, 維修狀況_tb.Text, 維修人員_tb.Text, 門牌_cb.Text)
            MsgBox("存檔完畢!") : Set_清單()
        End If
    End Sub
    Private Sub 報修日期_dtp_MouseDown(sender As Object, e As EventArgs) Handles 報修日期_dtp.MouseDown
        報修日期_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 維修日期_dtp_MouseDown(sender As Object, e As EventArgs) Handles 維修日期_dtp.MouseDown
        維修日期_dtp.CustomFormat = "yyyy/MM/dd"
    End Sub
    Private Sub 未維修變已維修_bt_Click(sender As Object, e As EventArgs) Handles 未維修變已維修_bt.Click
        If 報修單號_tb.Text = "" Then : MsgBox("請先選擇報修單資料，才能繼續後續的操作!!") : Else
            Dim result As DialogResult = MessageBox.Show("請確定該報修單是否已完成維修?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            If result = DialogResult.Yes Then : SQL_報修單_修改狀態(報修單號_tb.Text) : End If
            MsgBox("存檔完畢!") : Set_清單()
        End If
    End Sub
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_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(2, 2) = "報修單" : xlSheet.Cells(4, 9) = "申請日期 :" : xlSheet.Cells(4, 11) = 申請日期_dtp.Value.ToString("yyyy/MM/dd")
        xlSheet.Cells(5, 2) = "報修人" : xlSheet.Cells(5, 3) = 報修人_tb.Text : xlSheet.Cells(5, 8) = "報修日期" : xlSheet.Cells(5, 9) = 報修日期_dtp.Value.ToString("yyyy/MM/dd")
        xlSheet.Cells(6, 2) = "連絡電話" : xlSheet.Cells(6, 3) = 連絡電話_tb.Text : xlSheet.Cells(6, 8) = "接洽人員" : xlSheet.Cells(6, 9) = 接洽人員_tb.Text
        xlSheet.Cells(7, 2) = "承租客" : xlSheet.Cells(7, 3) = 承租客_cb.Text : xlSheet.Cells(7, 8) = "案場" : xlSheet.Cells(7, 9) = 案場_tb.Text
        xlSheet.Cells(8, 2) = "門牌地址" : xlSheet.Cells(8, 3) = 鄰近地址_cb.Text & 門牌_cb.Text : xlSheet.Cells(9, 2) = "原因" : xlSheet.Cells(9, 3) = 原因_tb.Text

        xlSheet.Cells(10, 2) = "維修日期" : xlSheet.Cells(10, 3) = 維修日期_dtp.Value.ToString("yyyy/MM/dd") : xlSheet.Cells(11, 2) = "維修狀況" : xlSheet.Cells(11, 3) = 維修狀況_tb.Text
        xlSheet.Cells(12, 2) = "維修人員" : xlSheet.Cells(12, 3) = 維修人員_tb.Text : xlSheet.Cells(12, 8) = "報修人確認"

        AA(xlApp, xlSheet) : DD(xlApp, xlSheet)

        xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
        '----轉成PDF-----
        Dim SERT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & 報修單號_tb.Text & "-報修單.pdf", XlFixedFormatQuality.xlQualityStandard, True)
        '--------
        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()
        Try
            Dim pdfFilePath As String = SERT & "\" & 報修單號_tb.Text & "-報修單.pdf"
            Dim acrobatReaderPath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
            If System.IO.File.Exists(acrobatReaderPath) Then : Process.Start(acrobatReaderPath, pdfFilePath)
            Else : Dim chromePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
                If System.IO.File.Exists(chromePath) Then : Process.Start(chromePath, pdfFilePath)
                Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
                    If System.IO.File.Exists(edgePath) Then : Process.Start(edgePath, pdfFilePath)
                    Else : MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱：" & 報修單號_tb.Text & "-報修單.pdf")
                    End If : End If : End If
        Catch ex As Exception
            MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱：" & 報修單號_tb.Text & "-報修單.pdf")
        End Try
    End Sub
    Private Sub DD(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)
        'Clipboard.SetDataObject(PictureBox1.Image)
        'xlSheet.Range("A1").Select()
        'myExcel.ActiveSheet.Pictures.Paste.Select
        'myExcel.Selection.ShapeRange.Height = 58
        'Dim leftPos As Double
        'Dim topPos As Double

        'leftPos = myExcel.ActiveSheet.Range("B2").Left
        'topPos = myExcel.ActiveSheet.Range("B2").Top

        'myExcel.Selection.ShapeRange.Left = leftPos
        'myExcel.Selection.ShapeRange.Top = topPos

        Dim imagePath As String = System.Windows.Forms.Application.StartupPath & "\YSLOGO2.png"
        Dim cell As Range = xlSheet.Cells(2, 2) : Dim left As Single = CType(cell.Left, Single) : Dim top As Single = CType(cell.Top, Single)
        Dim width As Single = 80 + 30 : Dim height As Single = 32 + 20
        If Not System.IO.File.Exists(imagePath) Then : MessageBox.Show("圖片文件未找到: " & imagePath) : Return : End If
        xlSheet.Shapes.AddPicture(imagePath, MsoTriState.msoFalse, MsoTriState.msoCTrue, left, top, width, height)

    End Sub
    Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)

        myExcel.Columns("B:M").Select
        With myExcel.Selection
            .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext
        End With
        With myExcel.Selection.Font
            .Name = "微軟正黑體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
            .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
        myExcel.Range("B2:M3").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.Range("I4:J4").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.Selection.Merge
        myExcel.Range("K4:M4").Select()
        With myExcel.Selection
            .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With
        myExcel.Selection.Merge

        For i As Integer = 5 To 7
            myExcel.Range("C" & i & ":G" & i).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.Range("I" & i & ":M" & i).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
        Next
        For i = 8 To 11
            myExcel.Range("C" & i & ":M" & i).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.Merge
        Next
        myExcel.Range("C12:G12").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.Range("I12:M12").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.Range("B5:M12").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With myExcel.Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With myExcel.Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With myExcel.Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With myExcel.Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With myExcel.Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With


        myExcel.Columns("B:B").ColumnWidth = 20 : myExcel.Columns("D:D").ColumnWidth = 9 : myExcel.Columns("E:E").ColumnWidth = 9
        myExcel.Columns("F:F").ColumnWidth = 9 : myExcel.Columns("G:G").ColumnWidth = 9 : myExcel.Columns("H:H").ColumnWidth = 20
        myExcel.Columns("I:I").ColumnWidth = 9 : myExcel.Columns("J:J").ColumnWidth = 9 : myExcel.Columns("K:k").ColumnWidth = 9
        myExcel.Columns("L:L").ColumnWidth = 9 : myExcel.Columns("M:M").ColumnWidth = 9
        myExcel.Rows("2:3").RowHeight = 15 : myExcel.Rows("4:12").RowHeight = 30
        myExcel.Rows("9:9").RowHeight = 75 : myExcel.Rows("11:11").RowHeight = 75


        myExcel.Columns("A:A").ColumnWidth = 0.54
        myExcel.Rows("1:1").RowHeight = 3.75
        '====列印======
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = ""
            .PaperSize = XlPaperSize.xlPaperA4
        End With
        myExcel.Application.PrintCommunication = True
        myExcel.ActiveSheet.PageSetup.PrintArea = ""
        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = ""
            .CenterFooter = ""
            .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.25)
            .RightMargin = myExcel.Application.InchesToPoints(0.25)
            .TopMargin = myExcel.Application.InchesToPoints(0.75)
            .BottomMargin = myExcel.Application.InchesToPoints(0.75)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
            .FooterMargin = myExcel.Application.InchesToPoints(0.3)
            .PrintHeadings = False
            .PrintGridlines = False
            ' .PrintQuality = 600
            .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