Option Strict Off Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle Imports Microsoft.Office.Interop.Excel.Constants Imports Microsoft.Office.Interop.Excel.XlBordersIndex Imports Microsoft.Office.Interop.Excel.XlLineStyle Imports Microsoft.Office.Interop.Excel.XlBorderWeight Imports Microsoft.Office.Interop.Excel.XlThemeFont Imports Microsoft.Office.Interop.Excel.XlThemeColor Imports Microsoft.Office.Interop.Excel.XlWindowState Imports Microsoft.Office.Interop.Excel Public Class 應付賬款控制表 ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet Dim N1 As Integer Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet Private Sub Set_賬款主單() DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView1.ColumnHeadersHeight = 40 DataGridView1.AllowUserToAddRows = False : DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView1.MultiSelect = True SQL_應付賬款主單() da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).FillWeight = 100 DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter For I As Integer = 0 To 1 : DataGridView1.Columns(I).ReadOnly = True : Next End Sub Private Sub Set_賬款清單() DataGridView2.DataSource = Nothing : ds1.Clear() : DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView2.ColumnHeadersHeight = 40 DataGridView2.AllowUserToAddRows = False : DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView2.MultiSelect = True If TextBox6.Text = "" Then : SQL_應付賬款清單一() : Else : SQL_應付賬款清單二() : End If da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() DataGridView2.Columns(0).FillWeight = 150 : DataGridView2.Columns(1).Visible = False : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).Visible = False DataGridView2.Columns(4).FillWeight = 80 : DataGridView2.Columns(5).FillWeight = 300 : DataGridView2.Columns(6).FillWeight = 80 : DataGridView2.Columns(7).FillWeight = 80 DataGridView2.Columns(8).FillWeight = 80 : DataGridView2.Columns(9).FillWeight = 80 : DataGridView2.Columns(10).FillWeight = 100 : DataGridView2.Columns(11).FillWeight = 100 DataGridView2.Columns(12).FillWeight = 150 : DataGridView2.Columns(13).FillWeight = 60 : DataGridView2.Columns(14).FillWeight = 50 : DataGridView2.Columns(15).Visible = False DataGridView2.Columns(16).FillWeight = 120 : DataGridView2.Columns(17).Visible = False DataGridView2.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView2.Columns(7).DefaultCellStyle.Format = "#,##0.000" DataGridView2.Columns(8).DefaultCellStyle.Format = "#,##0" : DataGridView2.Columns(9).DefaultCellStyle.Format = "#,##0" DataGridView2.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView2.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter For I As Integer = 0 To 12 : DataGridView2.Columns(I).ReadOnly = True : Next : DataGridView2.Columns(14).ReadOnly = True For I As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.Rows(I).Cells("應付立帳").Value.ToString = "" Then : DataGridView2.Rows(I).Cells("應付立帳").Value = False : End If DataGridView2.Rows(I).Cells("選擇").Value = False Next End Sub Private Sub Set_財務清單() DataGridView3.DataSource = Nothing : ds2.Clear() : DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView3.ColumnHeadersHeight = 40 DataGridView3.AllowUserToAddRows = False : DataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView3.MultiSelect = True DataGridView3.RowTemplate.Height = 35 SQL_應付賬款清單三() da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close() DataGridView3.Columns(0).Visible = False : DataGridView3.Columns(1).Visible = False : DataGridView3.Columns(2).FillWeight = 75 : DataGridView3.Columns(3).Visible = False DataGridView3.Columns(4).FillWeight = 150 : DataGridView3.Columns(5).FillWeight = 80 : DataGridView3.Columns(6).Visible = False : DataGridView3.Columns(7).FillWeight = 80 DataGridView3.Columns(8).Visible = False : DataGridView3.Columns(9).FillWeight = 150 : DataGridView3.Columns(10).FillWeight = 50 : DataGridView3.Columns(11).FillWeight = 50 DataGridView3.Columns(12).FillWeight = 120 : DataGridView3.Columns(13).FillWeight = 75 : DataGridView3.Columns(14).FillWeight = 95 : DataGridView3.Columns(15).FillWeight = 95 DataGridView3.Columns(16).FillWeight = 95 : DataGridView3.Columns(17).FillWeight = 95 : DataGridView3.Columns(18).FillWeight = 75 : DataGridView3.Columns(19).Visible = False DataGridView3.Columns(20).FillWeight = 150 : DataGridView3.Columns(21).FillWeight = 100 : DataGridView3.Columns(22).FillWeight = 80 : DataGridView3.Columns(23).FillWeight = 150 DataGridView3.Columns(24).Visible = False : DataGridView3.Columns(25).Visible = False : DataGridView3.Columns(26).Visible = False DataGridView3.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(7).DefaultCellStyle.Format = "#,##0" DataGridView3.Columns(8).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(5).DefaultCellStyle.Format = "#,##0" DataGridView3.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView3.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter End Sub Private Sub 日期格式() If 會計月.Checked = True Then '-------------日期一---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker1.Value = DTP DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(-1) DTP = Strings.Left(Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd"), 8) & "26" : DateTimePicker1.Value = DTP '-------------日期二---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd"), 8) & "25" : DateTimePicker2.Value = DTP Else '-------------日期一---------------------------------------------------------------------------------------- DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(1) DTP = Strings.Left(Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker1.Value = DTP '-------------日期二---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker2.Value = DTP DateTimePicker2.Value = DateTimePicker2.Value.AddMonths(1) : DateTimePicker2.Value = DateTimePicker2.Value.AddDays(-1) End If End Sub Private Sub 應付賬款控制表1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True DateTimePicker4.Visible = False : TextBox1.Visible = False : TextBox5.Visible = False 日期格式() : Set_賬款主單() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If 會計月.Checked = True Then DateTimePicker4.Value = DateTimePicker4.Value.AddMonths(-1) DateTimePicker1.Value = DateTimePicker4.Value DateTimePicker2.Value = DateTimePicker4.Value Else DateTimePicker4.Value = DateTimePicker4.Value.AddMonths(-1) DateTimePicker1.Value = DateTimePicker4.Value.AddMonths(-1) DateTimePicker2.Value = DateTimePicker4.Value End If TextBox6.Text = "" : 日期格式() : Set_賬款主單() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If 會計月.Checked = True Then DateTimePicker4.Value = DateTimePicker4.Value.AddMonths(1) DateTimePicker1.Value = DateTimePicker4.Value DateTimePicker2.Value = DateTimePicker4.Value Else DateTimePicker4.Value = DateTimePicker4.Value.AddMonths(1) DateTimePicker1.Value = DateTimePicker4.Value.AddMonths(-1) DateTimePicker2.Value = DateTimePicker4.Value End If TextBox6.Text = "" : 日期格式() : Set_賬款主單() End Sub Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月.Click 會計月.Checked = True : 一般月.Checked = False : TextBox6.Text = "" : 日期格式() : Set_賬款主單() End Sub Private Sub 一般月_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月.Click 會計月.Checked = False : 一般月.Checked = True : TextBox6.Text = "" : 日期格式() : Set_賬款主單() End Sub Private Sub 選中金額計算() TextBox4.Text = "0" : TextBox5.Text = "0" For I As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.Rows(I).Cells("選擇").Value = True Then TextBox5.Text = Val(TextBox5.Text) + DataGridView2.Rows(I).Cells("金額").Value TextBox4.Text = Val(TextBox4.Text) + DataGridView2.Rows(I).Cells("金額").Value End If Next NumericUpDown2.Value = Val(TextBox5.Text) - NumericUpDown1.Value TextBox4.Text = Strings.Format(Val(TextBox4.Text), "#,##0") End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then : Else TextBox6.Text = "" : TextBox2.Text = "" : CheckBox2.Checked = False : TextBox4.Text = "0" : NumericUpDown1.Value = 0 : NumericUpDown2.Value = 0 TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells("供應商編號").Value TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells("供應商").Value Set_賬款清單() : Set_財務清單() For i As Integer = 0 To DataGridView2.Rows.Count - 1 : DataGridView2.Rows(i).Cells("選擇").Value = True : Next i : 選中金額計算() End If End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick If e.RowIndex = -1 Then : Else If DataGridView2.Rows(e.RowIndex).Cells("申請日期").Value.ToString = "" Then : Else : DateTimePicker3.Value = DataGridView2.Rows(e.RowIndex).Cells("申請日期").Value.ToString : End If TextBox2.Text = DataGridView2.Rows(e.RowIndex).Cells("單據編號").Value : TextBox6.Text = DataGridView2.Rows(e.RowIndex).Cells("財務單號").Value.ToString For I As Integer = 0 To DataGridView2.Rows.Count - 1 If CheckBox2.Checked = False Then DataGridView2.Rows(I).Cells("選擇").Value = False End If If TextBox2.Text = DataGridView2.Rows(I).Cells("單據編號").Value Then DataGridView2.Rows(I).Cells("選擇").Value = True End If Next 選中金額計算() : Set_財務清單() NumericUpDown1.Value = 0 For I As Integer = 0 To DataGridView3.Rows.Count - 1 If DataGridView3.Rows(I).Cells("開票").Value < 0 Or DataGridView3.Rows(I).Cells("付現").Value < 0 Then : Else NumericUpDown1.Value = NumericUpDown1.Value + DataGridView3.Rows(I).Cells("開票").Value + DataGridView3.Rows(I).Cells("付現").Value End If Next End If End Sub Private Sub DataGridView2_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView2.RowPostPaint Dim linePen As New Pen(Color.Blue, 2) If e.RowIndex = DataGridView2.Rows.Count - 1 Then : Exit Sub Else If DataGridView2(0, e.RowIndex).Value.ToString <> DataGridView2(0, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(DataGridView2.RowHeadersVisible, DataGridView2.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + DataGridView2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView2.HorizontalScrollingOffset e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub End If End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click TextBox6.Text = "" : TextBox1.Text = "%%" : Set_賬款清單() : Set_財務清單() End Sub Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged NumericUpDown2.Value = Val(TextBox5.Text) - NumericUpDown1.Value End Sub Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click For i As Integer = 0 To DataGridView2.Rows.Count - 1 : DataGridView2.Rows(i).Cells("選擇").Value = True : Next i : 選中金額計算() End Sub Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click For i As Integer = 0 To DataGridView2.Rows.Count - 1 : DataGridView2.Rows(i).Cells("選擇").Value = False : Next i : 選中金額計算() End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click Dim 選擇判斷 As Boolean = False For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.Rows(i).Cells("選擇").Value = True Then 選擇判斷 = True : Exit For End If Next i If 選擇判斷 = True Then If CheckBox1.Checked = False Then : DTP = Strings.Format(Today(), "yyyy/MM/dd") : DTP1 = Strings.Format(Today(), "yyyyMMdd") Else : DTP1 = Strings.Format(DateTimePicker3.Value, "yyyyMMdd") : DTP = Strings.Format(DateTimePicker3.Value, "yyyy/MM/dd") : End If 收付應沖金額 = Val(TextBox5.Text) 財務單申請狀態 = "應付" : 收付對應財務單號 = TextBox6.Text 收付對應客戶供應商編號 = TextBox1.Text For I As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.Rows(I).Cells("選擇").Value = True Then PA19 = DataGridView2.Rows(I).Cells("資料流水號").Value.ToString SQL_應收應付單號連接暫存檔新增() : conn.Close() End If Next 財務單具申請.ShowDialog() Set_賬款清單() : Set_財務清單() : 財務單具申請.Close() For I As Integer = 0 To DataGridView2.Rows.Count - 1 DataGridView2.Rows(I).Cells("選擇").Value = True Next Else MsgBox("最少要選擇一張單據。") End If End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click For i As Integer = 0 To DataGridView2.Rows.Count - 1 If TextBox2.Text = DataGridView2.Rows(i).Cells("單據編號").Value.ToString Then DataGridView2.Rows(i).Cells("應付立帳").Value = False End If Next i End Sub Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged CheckBox2.Checked = True Set_賬款清單() : For i As Integer = 0 To DataGridView2.Rows.Count - 1 : DataGridView2.Rows(i).Cells("選擇").Value = True : Next i : 選中金額計算() End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click xlApp = CType(CreateObject("Excel.Application"), Application) xlBook = xlApp.Workbooks.Add xlApp.DisplayAlerts = True xlApp.Visible = True xlApp.Application.WindowState = xlMaximized N1 = 0 If DataGridView2.Rows.Count = 0 Then : Else xlSheet = NewMethod(xlBook) xlSheet.Cells(1, 1) = MAOJI_ERP_SYS.ComboBox2.Text : xlSheet.Cells(2, 1) = DateTimePicker1.Value & " 到 " & DateTimePicker2.Value & " 應付帳款清單" xlSheet.Cells(3, 1) = "單據編號" : xlSheet.Cells(3, 2) = "供應商" : xlSheet.Cells(3, 3) = "頁碼" : xlSheet.Cells(3, 4) = "品名" : xlSheet.Cells(3, 5) = "單價" : xlSheet.Cells(3, 6) = "匯率" xlSheet.Cells(3, 7) = "入庫" : xlSheet.Cells(3, 8) = "金額" : xlSheet.Cells(3, 9) = "採購下單" : xlSheet.Cells(3, 10) = "入庫日期" : xlSheet.Cells(3, 11) = "是否立帳" xlSheet.Cells(2, 7) = "合計" : xlSheet.Cells(2, 8) = "=SUBTOTAL(9,H4:H9999)" For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.Rows(i).Cells("選擇").Value = True Then xlSheet.Cells(N1 + 4, 1) = DataGridView2.Rows(i).Cells("單據編號").Value : xlSheet.Cells(N1 + 4, 2) = DataGridView2.Rows(i).Cells("供應商").Value xlSheet.Cells(N1 + 4, 3) = DataGridView2.Rows(i).Cells("頁碼").Value : xlSheet.Cells(N1 + 4, 4) = DataGridView2.Rows(i).Cells("品名").Value xlSheet.Cells(N1 + 4, 5) = DataGridView2.Rows(i).Cells("單價").Value : xlSheet.Cells(N1 + 4, 6) = DataGridView2.Rows(i).Cells("匯率").Value xlSheet.Cells(N1 + 4, 7) = DataGridView2.Rows(i).Cells("入庫").Value : xlSheet.Cells(N1 + 4, 8) = DataGridView2.Rows(i).Cells("金額").Value xlSheet.Cells(N1 + 4, 9) = DataGridView2.Rows(i).Cells("採購下單").Value : xlSheet.Cells(N1 + 4, 10) = DataGridView2.Rows(i).Cells("入庫日期").Value If DataGridView2.Rows(i).Cells("應付立帳").Value = True Then : PA1 = "YES" : Else : PA1 = "NO" : End If xlSheet.Cells(N1 + 4, 11) = PA1 N1 += 1 End If Next i N1 += 4 AA(xlApp, xlSheet) End If xlSheet.PageSetup.PrintArea = "" xlApp.Cells.Select() xlSheet.Range("B1").Select() xlApp.Application.WindowState = xlMinimized xlSheet.Cells.Select() MsgBox("列印完成。") End Sub Private Shared Function NewMethod(xlBook As Workbook) As Worksheet Return CType(xlBook.Worksheets.Add, Worksheet) End Function Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet) xlSheet.Cells.Select() With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 18 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10 xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 9 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 30 xlSheet.Columns("E:H").Select : myExcel.Selection.NumberFormatLocal = "#,##0;[紅色]-#,##0" xlSheet.Columns("F:F").Select : myExcel.Selection.NumberFormatLocal = "#,##0.000;[紅色]-#,##0.000" xlSheet.Columns("E:H").Select : myExcel.Selection.ColumnWidth = 7 : xlSheet.Columns("I:J").Select : myExcel.Selection.ColumnWidth = 10 xlSheet.Columns("K:K").Select : myExcel.Selection.ColumnWidth = 8 xlSheet.Rows("1:1").Select With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 22 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Rows("2:2").Select 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 xlSheet.Rows("3:3").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.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = True : xlSheet.Rows("3:3").Select : myExcel.Selection.AutoFilter xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 25 With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Range("H2:I2").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("G2:I2").Select() With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Range("A1:K1").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("A2:F2").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 xlSheet.Range("L10").Select() : myExcel.ActiveWindow.DisplayGridlines = False xlSheet.Range("G2").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("A3:K" & 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 End Sub End Class