123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- 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.XlPrintLocation
- Imports Microsoft.Office.Interop.Excel.XlPageOrientation
- Imports Microsoft.Office.Interop.Excel.XlPaperSize
- Imports Microsoft.Office.Interop.Excel.XlOrder
- Imports Microsoft.Office.Interop.Excel.XlPrintErrors
- Imports Microsoft.Office.Interop.Excel
- Imports System.IO
-
- Public Class 倉儲對帳表
- ReadOnly ds1 As New DataSet
- Dim xlApp As Microsoft.Office.Interop.Excel.Application
- Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
- Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
- Dim 位置1 As String
- Dim N2 As Integer
-
- Private Sub 倉儲對帳表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.MdiParent = ICS_ASMS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
- SQL_物料資料庫_類別_下拉清單() : 類別清單_cb.Items.Clear()
- While (dr.Read()) : 類別清單_cb.Items.Add(dr("類別")) : End While : conn.Close()
- 選擇供應商_cb.Items.Add("")
- SQL_物料資料庫_供應商_下拉清單()
- While (dr.Read()) : 選擇供應商_cb.Items.Add(dr("公司名")) : End While : conn.Close()
- Set_清單2()
- SQL_讀取公司名稱()
- If dr.Read() Then
- 公司名稱.Text = dr("公司名稱")
- End If
- End Sub
-
- Private Sub Set_清單2()
- 明細表_dgv.DataSource = Nothing : ds1.Clear()
- 明細表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 明細表_dgv.ColumnHeadersHeight = 25
- 明細表_dgv.AllowUserToAddRows = False
- 明細表_dgv.RowTemplate.Height = 35
- 明細表_dgv.EditMode = DataGridViewEditMode.EditOnEnter
- SQL_倉儲對帳表_明細表清單() : da.Fill(ds1) : 明細表_dgv.DataSource = ds1.Tables(0) : conn.Close()
- 明細表_dgv.Columns(3).ReadOnly = True : 明細表_dgv.Columns(4).ReadOnly = True : 明細表_dgv.Columns(5).ReadOnly = True
- 明細表_dgv.Columns(8).ReadOnly = True
-
- 明細表_dgv.Columns(0).FillWeight = 60 : 明細表_dgv.Columns(1).FillWeight = 60 : 明細表_dgv.Columns(2).Visible = False : 明細表_dgv.Columns(3).FillWeight = 150
- 明細表_dgv.Columns(4).FillWeight = 150 : 明細表_dgv.Columns(5).FillWeight = 40 : 明細表_dgv.Columns(6).FillWeight = 40
- 明細表_dgv.Columns(7).FillWeight = 40 : 明細表_dgv.Columns(8).FillWeight = 40 : 明細表_dgv.Columns(9).FillWeight = 150
- 明細表_dgv.Columns(10).Visible = False : 明細表_dgv.Columns(11).Visible = False
- 明細表_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 明細表_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
-
- Dim NUM1, NUM2, NUM3, NUM4 As Integer
- 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
- NUM1 += 明細表_dgv.Rows(i).Cells("總額").Value
- Else
- NUM2 += 明細表_dgv.Rows(i).Cells("總額").Value
- End If
- Next
- 本期銷貨金額_tb.Text = Strings.Format(Val(NUM2), "#,##0")
- 本期銷退金額_tb.Text = Strings.Format(Val(-NUM1), "#,##0")
- NUM3 = NUM2 + NUM1
- 合計金額_tb.Text = Strings.Format(Val(NUM3), "#,##0")
- NUM4 = NUM3 * 0.05
- If 含稅_ch.Checked = True Then
- 稅額_tb.Text = Strings.Format(Val(NUM4), "#,##0")
- 金額總計_tb.Text = Strings.Format(Val(NUM3 + NUM4), "#,##0")
- Else
- 稅額_tb.Text = "0"
- 金額總計_tb.Text = Strings.Format(Val(NUM3), "#,##0")
- End If
-
- End Sub
- Private Sub 含稅_CheckedChanged(sender As Object, e As EventArgs) Handles 含稅_ch.Click
- 含稅_ch.Checked = True : 不含稅_ch.Checked = False
- Dim NUM1, NUM2 As Integer
- NUM1 = 合計金額_tb.Text
- NUM2 = NUM1 * 0.05
- If 含稅_ch.Checked = True Then
- 稅額_tb.Text = Strings.Format(Val(NUM2), "#,##0")
- 金額總計_tb.Text = Strings.Format(Val(NUM1 + NUM2), "#,##0")
- Else
- 稅額_tb.Text = "0"
- 金額總計_tb.Text = Strings.Format(Val(NUM1), "#,##0")
- End If
-
- End Sub
- Private Sub 不含稅_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 不含稅_ch.Click
- 含稅_ch.Checked = False : 不含稅_ch.Checked = True
- Dim NUM1, NUM2 As Integer
- NUM1 = 合計金額_tb.Text
- NUM2 = NUM1 * 0.05
- If 含稅_ch.Checked = True Then
- 稅額_tb.Text = Strings.Format(Val(NUM2), "#,##0")
- 金額總計_tb.Text = Strings.Format(Val(NUM1 + NUM2), "#,##0")
- Else
- 稅額_tb.Text = "0"
- 金額總計_tb.Text = Strings.Format(Val(NUM1), "#,##0")
- End If
-
- End Sub
- Private Sub 選擇供應商_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 選擇供應商_cb.SelectedIndexChanged
- Set_清單2()
- If 選擇供應商_cb.Text = "" Then
- 供應商編號.Text = "" : 供應商名稱.Text = "" : 地址.Text = "" : 電話.Text = "" : 傳真.Text = ""
- Else
- SQL_倉儲對帳表_供應商資料()
- While (dr.Read())
- 供應商編號.Text = dr("編號") : 供應商名稱.Text = dr("名稱") : 地址.Text = dr("地址") : 電話.Text = dr("電話") : 傳真.Text = dr("傳真")
- End While : conn.Close()
- End If
- End Sub
- Private Sub 開始日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 開始日期_dtp.ValueChanged
- Set_清單2() : 開始日期_dtp.CustomFormat = "yyyy/MM/dd"
- 開始日期_dtp.Format = DateTimePickerFormat.Custom
- End Sub
- Private Sub 結束日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 結束日期_dtp.ValueChanged
- Set_清單2() : 結束日期_dtp.CustomFormat = "yyyy/MM/dd"
- 結束日期_dtp.Format = DateTimePickerFormat.Custom
- End Sub
- Private Sub 當日_bt_Click(sender As Object, e As EventArgs) Handles 當日_bt.Click
- 中間日期_dtp.Value = Today
- DTP = Strings.Format(Today(), "yyyy/MM/dd")
- 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = DTP
- Set_清單2()
- End Sub
- Private Sub 當月_bt_Click(sender As Object, e As EventArgs) Handles 當月_bt.Click
- 中間日期_dtp.Value = Today
- DTP = Strings.Left(Strings.Format(Today(), "yyyy/MM/dd"), 8) & "01"
- 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = Today()
- Set_清單2()
- End Sub
- Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月_ch.Click
- 會計月_ch.Checked = True : 一般月_ch.Checked = False : 日期格式() : Set_清單2()
- End Sub
- Private Sub 一般月_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月_ch.Click
- 會計月_ch.Checked = False : 一般月_ch.Checked = True : 日期格式() : Set_清單2()
- End Sub
- Private Sub 上個月_bt_Click(sender As Object, e As EventArgs) Handles 上個月_bt.Click
-
- If 會計月_ch.Checked = True Then
- 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
- 開始日期_dtp.Value = 中間日期_dtp.Value
- 結束日期_dtp.Value = 中間日期_dtp.Value
- Else
- 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
- 開始日期_dtp.Value = 中間日期_dtp.Value
- 結束日期_dtp.Value = 中間日期_dtp.Value
- End If : 日期格式() : Set_清單2()
- End Sub
- Private Sub 下個月_bt_Click(sender As Object, e As EventArgs) Handles 下個月_bt.Click
-
- If 會計月_ch.Checked = True Then
- 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
- 開始日期_dtp.Value = 中間日期_dtp.Value
- 結束日期_dtp.Value = 中間日期_dtp.Value
- Else
- 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
- 開始日期_dtp.Value = 中間日期_dtp.Value
- 結束日期_dtp.Value = 中間日期_dtp.Value
- End If : 日期格式() : Set_清單2()
- End Sub
- Private Sub 日期格式()
- If 會計月_ch.Checked = True Then
- '-------------日期一----------------------------------------------------------------------------------------
- DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
- 開始日期_dtp.Value = 結束日期_dtp.Value.AddMonths(-1)
- DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "26" : 開始日期_dtp.Value = DTP
- '-------------日期二----------------------------------------------------------------------------------------
- DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "25" : 結束日期_dtp.Value = DTP
- Else
- 開始日期_dtp.Value = 結束日期_dtp.Value
- '-------------日期一----------------------------------------------------------------------------------------
- DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
- '-------------日期二----------------------------------------------------------------------------------------
- DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 結束日期_dtp.Value = DTP
- 結束日期_dtp.Value = 結束日期_dtp.Value.AddMonths(1) : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(-1)
- End If
- End Sub
- Private Sub 匯出EXCEL_bt_MouseEnter(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.MouseEnter
- ToolTip1.SetToolTip(Me.匯出EXCEL_bt, "匯出PDF")
- End Sub
- Private Sub 匯出EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.Click
- xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
- xlApp.Visible = True
- xlApp.DisplayAlerts = True
- xlApp.Application.WindowState = xlMaximized
- xlBook = xlApp.Workbooks.Add
- xlSheet = NewMethod(xlBook)
- xlBook.Activate()
- xlSheet.Activate()
- Dim m As String
- Dim selectedDate As DateTime = 中間日期_dtp.Value
- Dim y As String = selectedDate.Year.ToString()
- If selectedDate.Month < 10 Then : m = "0" & selectedDate.Month.ToString()
- Else : m = selectedDate.Month.ToString()
- End If
-
-
- xlSheet.Cells(1, 1) = 公司名稱.Text & y & "年" & m & "月銷貨明細表"
- xlSheet.Cells(2, 1) = "供應商名稱: " & 供應商名稱.Text
- xlSheet.Cells(2, 4) = "供應商編號: " & 供應商編號.Text
- xlSheet.Cells(3, 1) = "地址: " & 地址.Text
- xlSheet.Cells(4, 1) = "電話: " & 電話.Text
- xlSheet.Cells(4, 4) = "傳真: " & 傳真.Text
- xlSheet.Cells(5, 1) = "項次" : xlSheet.Cells(5, 2) = "車種年份" : xlSheet.Cells(5, 3) = "品名"
- xlSheet.Cells(5, 4) = "廠牌" : xlSheet.Cells(5, 5) = "數量" : xlSheet.Cells(5, 6) = "單價" : xlSheet.Cells(5, 7) = "總額"
- xlSheet.Cells(5, 8) = "備註"
- For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
- xlSheet.Cells(i + 6, 1) = i + 1
- Dim str As String
- Dim cellValue As Object = 明細表_dgv.Rows(i).Cells("車種年份").Value
-
- If cellValue IsNot Nothing AndAlso IsNumeric(cellValue.ToString()) Then
- ' 如果是數字,則加上 '
- str = "'" & cellValue.ToString()
- Else
- str = 明細表_dgv.Rows(i).Cells("車種年份").Value
- End If
-
- xlSheet.Cells(i + 6, 2) = str : xlSheet.Cells(i + 6, 3) = 明細表_dgv.Rows(i).Cells("品名").Value
- xlSheet.Cells(i + 6, 4) = 明細表_dgv.Rows(i).Cells("廠牌").Value : xlSheet.Cells(i + 6, 5) = 明細表_dgv.Rows(i).Cells("數量").Value
- Dim value As Double = Convert.ToDouble(明細表_dgv.Rows(i).Cells("單價").Value)
- Dim formattedValue As String = value.ToString("#,##0") : xlSheet.Cells(i + 6, 6) = formattedValue
- Dim value1 As Double = Convert.ToDouble(明細表_dgv.Rows(i).Cells("總額").Value)
- Dim formattedValue1 As String = value1.ToString("#,##0") : xlSheet.Cells(i + 6, 7) = formattedValue1
- xlSheet.Cells(i + 6, 8) = 明細表_dgv.Rows(i).Cells("備註").Value
- N2 = i
- Next i
- xlSheet.Cells(N2 + 7, 4) = "金額合計:" : xlSheet.Cells(N2 + 7, 6) = 合計金額_tb.Text
- xlSheet.Cells(N2 + 8, 4) = "稅 額:" : xlSheet.Cells(N2 + 8, 6) = 稅額_tb.Text
- xlSheet.Cells(N2 + 9, 4) = "金額總計:" : xlSheet.Cells(N2 + 9, 6) = 金額總計_tb.Text
- BB(xlApp, xlSheet)
- xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
- '----轉成PDF-----
- Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
- If Not Directory.Exists(pdfFolderPath) Then
- Directory.CreateDirectory(pdfFolderPath)
- End If
- Dim pdfFilePath As String = Path.Combine(pdfFolderPath, 供應商名稱.Text & y & "年" & m & "月-對帳單.pdf")
- xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, 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 chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
- If System.IO.File.Exists(chromePath) Then
- Dim process As New Process()
- process.StartInfo.FileName = "chrome"
- process.StartInfo.Arguments = """" & pdfFilePath & """"
- process.Start()
- Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
- If System.IO.File.Exists(edgePath) Then
- Dim process As New Process()
- process.StartInfo.FileName = "msedge"
- process.StartInfo.Arguments = """" & pdfFilePath & """"
- process.Start()
- Else
- Process.Start(pdfFilePath)
- End If
- End If
- Catch ex As Exception
- MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & 供應商名稱.Text & y & "年" & m & "月-對帳單.pdf")
- End Try
- End Sub
- Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.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.Range("A1:H1").Select()
- 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
- xlSheet.Range("A2:H4").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").ColumnWidth = 4.5
- xlSheet.Columns("B:B").ColumnWidth = 22
- xlSheet.Columns("C:C").ColumnWidth = 28
- xlSheet.Columns("D:D").ColumnWidth = 6
- xlSheet.Columns("E:E").ColumnWidth = 4
- xlSheet.Columns("F:F").ColumnWidth = 7
- xlSheet.Columns("G:G").ColumnWidth = 8
- xlSheet.Columns("H:H").ColumnWidth = 14
-
-
- xlSheet.Range("A5:H5").Select()
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With myExcel.Selection.Borders(xlEdgeBottom)
- .LineStyle = 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("A" & N2 + 7 & ":H" & N2 + 7).Select()
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- myExcel.Selection.Borders(xlEdgeBottom).LineStyle = xlNone
- myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone
- myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
- myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
-
- xlSheet.Columns("A:A").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("E5:G5").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("A1:H1").Select()
- With myExcel.Selection
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = False
- End With
- myExcel.Selection.Merge
-
- xlSheet.Range("A2:C2").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
-
- xlSheet.Range("D2:H2").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
-
- xlSheet.Range("A3:H3").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
-
- xlSheet.Range("A4:C4").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
-
- xlSheet.Range("D4:H4").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
-
- xlSheet.Range("D" & N2 + 7 & ":E" & N2 + 7).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("F" & N2 + 7 & ":G" & N2 + 7).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("D" & N2 + 8 & ":E" & N2 + 8).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("F" & N2 + 8 & ":G" & N2 + 8).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("D" & N2 + 9 & ":E" & N2 + 9).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("F" & N2 + 9 & ":G" & N2 + 9).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.Application.PrintCommunication = False
- With myExcel.ActiveSheet.PageSetup
- .PrintTitleRows = "$1:$5"
- .PrintTitleColumns = "$A:$H"
- End With
- myExcel.Application.PrintCommunication = True
- myExcel.ActiveSheet.PageSetup.PrintArea = ""
- myExcel.Application.PrintCommunication = False
- With myExcel.ActiveSheet.PageSetup
- .LeftHeader = ""
- .CenterHeader = ""
- .RightHeader = "&D"
- .LeftFooter = ""
- .CenterFooter = "第 &P 頁,共 &N 頁"
- .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
- .CenterHorizontally = False
- .CenterVertically = False
- .Draft = False
- .FirstPageNumber = xlAutomatic
- .BlackAndWhite = False
- .Zoom = 100
- .OddAndEvenPagesHeaderFooter = False
- .DifferentFirstPageHeaderFooter = False
- .ScaleWithDocHeaderFooter = True
- .AlignMarginsHeaderFooter = True
- .EvenPage.LeftHeader.Text = ""
- .EvenPage.CenterHeader.Text = ""
- .EvenPage.RightHeader.Text = ""
- .EvenPage.LeftFooter.Text = ""
- .EvenPage.CenterFooter.Text = ""
- .EvenPage.RightFooter.Text = ""
- .FirstPage.LeftHeader.Text = ""
- .FirstPage.CenterHeader.Text = ""
- .FirstPage.RightHeader.Text = ""
- .FirstPage.LeftFooter.Text = ""
- .FirstPage.CenterFooter.Text = ""
- .FirstPage.RightFooter.Text = ""
- End With
- myExcel.Application.PrintCommunication = True
- End Sub
- Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
- Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
- End Function
- End Class
|