暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

列印_零用金支付明細.vb 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Public Class 列印_零用金支付明細
  11. Private ReadOnly ds, ds1 As New DataSet
  12. Dim N1, N2 As Integer
  13. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  14. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  15. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  16. Private Sub Set_清單()
  17. DataGridView1.DataSource = Nothing : ds.Clear()
  18. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  19. DataGridView1.ColumnHeadersHeight = 25
  20. DataGridView1.AllowUserToAddRows = False
  21. ConnOpen()
  22. If CheckBox1.Checked = True Then
  23. SQL1 = 列印用SQL
  24. Else
  25. SQL1 = "SELECT 零用金支付表.流水號, 零用金支付表.部門, 零用金支付表.申請人, LEFT(零用金支付表.申請日期, 10) AS 申請日期, 零用金支付表.審核人, LEFT(零用金支付表.審核日期, 10) AS 審核日期, " &
  26. "零用金支付表.核准人, LEFT(零用金支付表.核准日期, 10) AS 核准日期, 零用金支付明細.項次, 零用金支付明細.用途, 零用金支付明細.金額, 零用金支付明細.會計 AS 會計作業, " &
  27. "零用金支付明細.出納 AS 出納作業, 零用金支付明細.備註, 零用金支付表.會計, 零用金支付表.作帳日期, 零用金支付表.出納, 零用金支付表.出納日期, 零用金支付明細.現金, 零用金支付明細.備用金, " &
  28. "零用金支付明細.公帳 FROM 零用金支付表 RIGHT OUTER JOIN 零用金支付明細 " &
  29. "ON 零用金支付表.流水號 = 零用金支付明細.流水號 WHERE (零用金支付表.審核人 NOT LIKE N'作廢%') AND (零用金支付表.核准人 NOT LIKE N'') AND (零用金支付表.核准人 NOT LIKE N'作廢%') " &
  30. "AND (零用金支付表.核准日期 LIKE N'" & ComboBox1.Text & "%') " &
  31. " ORDER BY 零用金支付表.流水號 DESC, 零用金支付明細.項次"
  32. End If
  33. CmdSet_For_DGV()
  34. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  35. End Sub
  36. Private Sub ComboBox1下拉表單資料載入()
  37. ConnOpen()
  38. SQL1 = "SELECT 年份 FROM 年份清單 ORDER BY 年份 DESC"
  39. CmdSet_For_dr()
  40. ComboBox1.Items.Clear()
  41. While (dr.Read()) : ComboBox1.Items.Add(dr("年份")) : End While
  42. conn.Close()
  43. End Sub
  44. Private Sub 列印_零用金支付明細_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  45. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  46. ComboBox1下拉表單資料載入()
  47. CheckBox1.Checked = True : CheckBox2.Checked = False
  48. Set_清單() : DataGridView1.Visible = False
  49. End Sub
  50. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  51. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  52. xlBook = xlApp.Workbooks.Add
  53. xlApp.DisplayAlerts = True
  54. xlBook.Activate()
  55. xlSheet = NewMethod(xlBook)
  56. xlSheet.Activate()
  57. xlApp.Visible = True
  58. xlApp.Application.WindowState = xlMaximized
  59. xlSheet.Cells(1, 1) = "巨益貿易-零用金支付明細表" : xlSheet.Cells(2, 1) = "單號" : xlSheet.Cells(2, 2) = "部門" : xlSheet.Cells(2, 3) = "申請人" : xlSheet.Cells(2, 4) = "申請日期"
  60. xlSheet.Cells(2, 5) = "審核人" : xlSheet.Cells(2, 6) = "審核日期" : xlSheet.Cells(2, 7) = "核准人" : xlSheet.Cells(2, 8) = "核准日期" : xlSheet.Cells(2, 9) = "項次"
  61. xlSheet.Cells(2, 10) = "用途" : xlSheet.Cells(2, 11) = "金額" : xlSheet.Cells(2, 12) = "備註" : xlSheet.Cells(2, 13) = "會計" : xlSheet.Cells(2, 14) = "作帳日期" : xlSheet.Cells(2, 15) = "出納"
  62. xlSheet.Cells(2, 16) = "出納日期" : xlSheet.Cells(2, 17) = "現金" : xlSheet.Cells(2, 18) = "備用金" : xlSheet.Cells(2, 19) = "公帳"
  63. AA(xlApp, xlSheet)
  64. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  65. xlSheet.Cells(i + 3, 1) = DataGridView1.Rows(i).Cells("流水號").Value : xlSheet.Cells(i + 3, 2) = DataGridView1.Rows(i).Cells("部門").Value
  66. xlSheet.Cells(i + 3, 3) = DataGridView1.Rows(i).Cells("申請人").Value : xlSheet.Cells(i + 3, 4) = DataGridView1.Rows(i).Cells("申請日期").Value
  67. xlSheet.Cells(i + 3, 5) = DataGridView1.Rows(i).Cells("審核人").Value : xlSheet.Cells(i + 3, 6) = DataGridView1.Rows(i).Cells("審核日期").Value
  68. xlSheet.Cells(i + 3, 7) = DataGridView1.Rows(i).Cells("核准人").Value : xlSheet.Cells(i + 3, 8) = DataGridView1.Rows(i).Cells("核准日期").Value
  69. xlSheet.Cells(i + 3, 9) = DataGridView1.Rows(i).Cells("項次").Value : xlSheet.Cells(i + 3, 10) = DataGridView1.Rows(i).Cells("用途").Value
  70. xlSheet.Cells(i + 3, 11) = DataGridView1.Rows(i).Cells("金額").Value : xlSheet.Cells(i + 3, 12) = DataGridView1.Rows(i).Cells("備註").Value
  71. xlSheet.Cells(i + 3, 13) = DataGridView1.Rows(i).Cells("會計").Value : xlSheet.Cells(i + 3, 14) = DataGridView1.Rows(i).Cells("作帳日期").Value
  72. xlSheet.Cells(i + 3, 15) = DataGridView1.Rows(i).Cells("出納").Value : xlSheet.Cells(i + 3, 16) = DataGridView1.Rows(i).Cells("出納日期").Value
  73. xlSheet.Cells(i + 3, 17) = DataGridView1.Rows(i).Cells("現金").Value : xlSheet.Cells(i + 3, 18) = DataGridView1.Rows(i).Cells("備用金").Value
  74. xlSheet.Cells(i + 3, 19) = DataGridView1.Rows(i).Cells("公帳").Value
  75. With xlApp.Selection
  76. .Font.Bold = True
  77. End With
  78. N2 = i + 3 : N1 = i
  79. Next i
  80. BB(xlApp, xlSheet)
  81. xlSheet.PageSetup.PrintArea = ""
  82. xlApp.Cells.Select()
  83. xlSheet.Range("B1").Select()
  84. xlApp.Application.WindowState = xlMinimized
  85. MsgBox("列印完成")
  86. Me.Close()
  87. End Sub
  88. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  89. 列印用SQL = "" : Me.Close()
  90. End Sub
  91. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  92. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  93. End Function
  94. Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  95. xlSheet.Cells.Select()
  96. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  97. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  98. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 30
  99. xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 25
  100. With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  101. .ReadingOrder = xlContext : .MergeCells = False : End With
  102. myExcel.Selection.AutoFilter
  103. xlSheet.Range("A1").Select()
  104. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 20 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  105. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  106. xlSheet.Rows("3:3").Select
  107. myExcel.ActiveWindow.FreezePanes = True
  108. xlSheet.Range("A2:S2").Select()
  109. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  110. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  111. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  112. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  113. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  114. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  115. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  116. myExcel.ActiveWindow.DisplayGridlines = False
  117. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 15.5
  118. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 11.5
  119. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 6
  120. xlSheet.Columns("D:D").Select : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd" : myExcel.Selection.ColumnWidth = 10
  121. xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 6
  122. xlSheet.Columns("F:F").Select : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd" : myExcel.Selection.ColumnWidth = 10
  123. xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 6
  124. xlSheet.Columns("H:H").Select : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd" : myExcel.Selection.ColumnWidth = 10
  125. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 4 : myExcel.Selection.NumberFormatLocal = "@"
  126. xlSheet.Columns("J:J").Select : myExcel.Selection.ColumnWidth = 52
  127. xlSheet.Columns("K:K").Select : myExcel.Selection.ColumnWidth = 12 : myExcel.Selection.Style = "Comma"
  128. xlSheet.Columns("L:L").Select : myExcel.Selection.ColumnWidth = 45
  129. xlSheet.Columns("M:M").Select : myExcel.Selection.ColumnWidth = 6
  130. xlSheet.Columns("N:N").Select : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd" : myExcel.Selection.ColumnWidth = 10
  131. xlSheet.Columns("O:O").Select : myExcel.Selection.ColumnWidth = 6
  132. xlSheet.Columns("P:P").Select : myExcel.Selection.NumberFormatLocal = "yyyy/mm/dd" : myExcel.Selection.ColumnWidth = 10
  133. xlSheet.Columns("Q:S").Select : myExcel.Selection.ColumnWidth = 8
  134. xlSheet.Cells.Select() : myExcel.ActiveWindow.Zoom = 90
  135. End Sub
  136. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  137. Dim 位置1 As String
  138. 位置1 = "A3:S" & N1 + 3 : xlSheet.Range(位置1).Select()
  139. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  140. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  141. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  142. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  143. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  144. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  145. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  146. End Sub
  147. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
  148. CheckBox1.Checked = True : CheckBox2.Checked = False
  149. Set_清單()
  150. End Sub
  151. Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
  152. CheckBox1.Checked = False : CheckBox2.Checked = True
  153. Set_清單()
  154. End Sub
  155. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  156. Set_清單()
  157. End Sub
  158. End Class