暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

列印_零用金支付單.vb 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. Option Strict Off
  2. Imports System.IO
  3. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  4. Imports Microsoft.Office.Interop.Excel.Constants
  5. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  6. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  7. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  8. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  9. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  10. Imports Microsoft.Office.Interop.Excel.XlWindowState
  11. Imports Microsoft.Office.Interop.Excel
  12. Public Class 列印_零用金支付單
  13. Private ReadOnly ds1, ds2, ds3, ds4 As New DataSet
  14. Dim N1, N2 As Integer
  15. Dim 位置1 As String
  16. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  17. Private Sub Set_訂單清單1()
  18. DataGridView1.DataSource = Nothing : ds1.Clear()
  19. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  20. DataGridView1.ColumnHeadersHeight = 25
  21. DataGridView1.AllowUserToAddRows = False
  22. ConnOpen()
  23. SQL1 = "SELECT 零用金支付表.流水號, 零用金支付表.部門, 零用金支付表.申請人, LEFT(零用金支付表.申請日期, 10) AS 申請日期,
  24. 零用金支付表.審核人, LEFT(零用金支付表.審核日期, 10) AS 審核日期, 零用金支付表.核准人,
  25. LEFT(零用金支付表.核准日期, 10) AS 核准日期, 零用金支付表.核准圖檔, 零用金支付表.簽名編碼,
  26. 零用金支付明細.出納 AS 已出納
  27. FROM 零用金支付表 INNER JOIN
  28. 零用金支付明細 ON 零用金支付表.流水號 = 零用金支付明細.流水號
  29. WHERE (零用金支付表.流水號 LIKE N'" & 列印用SQL & "') AND (零用金支付表.審核人 NOT LIKE N'作廢%') AND (零用金支付表.審核人 NOT LIKE N'') AND
  30. (零用金支付表.核准人 NOT LIKE N'作廢%') AND (零用金支付表.核准人 NOT LIKE N'')
  31. GROUP BY 零用金支付表.流水號, 零用金支付表.部門, 零用金支付表.申請人, LEFT(零用金支付表.申請日期, 10),
  32. 零用金支付表.審核人, LEFT(零用金支付表.審核日期, 10), 零用金支付表.核准人, LEFT(零用金支付表.核准日期, 10),
  33. 零用金支付表.核准圖檔, 零用金支付表.簽名編碼, 零用金支付明細.出納
  34. ORDER BY 零用金支付表.流水號 DESC"
  35. CmdSet_For_DGV()
  36. da.Fill(ds1) : DataGridView1.DataSource = ds1.Tables(0) : conn.Close()
  37. End Sub
  38. Private Sub Set_訂單清單2()
  39. DataGridView2.DataSource = Nothing : ds2.Clear()
  40. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  41. DataGridView2.ColumnHeadersHeight = 25
  42. DataGridView2.AllowUserToAddRows = False
  43. ConnOpen()
  44. SQL1 = 列印用SQL2
  45. CmdSet_For_DGV()
  46. da.Fill(ds2) : DataGridView2.DataSource = ds2.Tables(0) : conn.Close()
  47. End Sub
  48. Private Sub 列印_零用金支付單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  49. DataGridView1.Visible = False : DataGridView2.Visible = False
  50. PictureBox1.Visible = False
  51. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  52. ConnOpen()
  53. SQL1 = "SELECT 簽名檔圖片 FROM 簽名檔管理 WHERE 圖片流水號 LIKE N'" & 簽核圖片編號 & "'"
  54. CmdSet_For_dr()
  55. While dr.Read() = True
  56. Dim bytes As Byte() = New Byte(-1) {}
  57. bytes = DirectCast(dr.Item("簽名檔圖片"), Byte())
  58. Dim oStream As New MemoryStream(bytes)
  59. PictureBox1.Image = Bitmap.FromStream(oStream)
  60. End While
  61. conn.Close()
  62. Set_訂單清單1() : Set_訂單清單2()
  63. End Sub
  64. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  65. xlApp = CType(CreateObject("Excel.Application"), Application)
  66. xlBook = xlApp.Workbooks.Add
  67. xlApp.DisplayAlerts = True
  68. xlBook.Activate()
  69. xlSheet = NewMethod(xlBook)
  70. xlSheet.Activate()
  71. xlApp.Visible = True
  72. xlApp.Application.WindowState = xlMaximized
  73. xlSheet.Cells(1, 1) = "費用報銷單" : xlSheet.Cells(2, 1) = "報銷部門 : " : xlSheet.Cells(2, 4) = "申請人 : " : xlSheet.Cells(2, 6) = "申請日期 : " : xlSheet.Cells(3, 1) = "項次"
  74. xlSheet.Cells(3, 2) = "用途" : xlSheet.Cells(3, 5) = "金額" : xlSheet.Cells(3, 6) = "備註"
  75. xlSheet.Cells(2, 3) = DataGridView1.Rows(0).Cells("部門").Value : xlSheet.Cells(2, 5) = DataGridView1.Rows(0).Cells("申請人").Value
  76. xlSheet.Cells(2, 7) = DataGridView1.Rows(0).Cells("申請日期").Value
  77. For i As Integer = 0 To DataGridView2.Rows.Count - 1
  78. xlSheet.Cells(i + 4, 1) = i + 1
  79. xlSheet.Cells(i + 4, 2) = DataGridView2.Rows(i).Cells("用途").Value
  80. xlSheet.Cells(i + 4, 5) = DataGridView2.Rows(i).Cells("金額").Value
  81. xlSheet.Cells(i + 4, 6) = DataGridView2.Rows(i).Cells("備註").Value
  82. With xlApp.Selection
  83. .Font.Bold = True
  84. End With
  85. N1 = i + 4 : N2 = i + 4
  86. Next i
  87. xlSheet.Cells(N1 + 1, 2) = "以下空白" : xlSheet.Cells(N1 + 3, 4) = "合计" : xlSheet.Cells(N1 + 3, 5) = "=SUM(E4:E" & N1 + 1 & ")"
  88. xlSheet.Cells(N1 + 3, 1) = "單據驗證碼 : " : xlSheet.Cells(N1 + 4, 1) = "核准人 : " : xlSheet.Cells(N1 + 4, 4) = "審核人 : " : xlSheet.Cells(N1 + 4, 6) = "審核日期 : "
  89. xlSheet.Cells(N1 + 5, 4) = "會計 : " : xlSheet.Cells(N1 + 5, 6) = "對帳日期 : " : xlSheet.Cells(N1 + 6, 4) = "出納 : " : xlSheet.Cells(N1 + 6, 6) = "出納日期 : "
  90. xlSheet.Cells(N1 + 6, 8) = "領款人 : "
  91. xlSheet.Cells(N1 + 3, 3) = DataGridView1.Rows(0).Cells("簽名編碼").Value : xlSheet.Cells(N1 + 4, 5) = DataGridView1.Rows(0).Cells("審核人").Value
  92. xlSheet.Cells(N1 + 4, 7) = DataGridView1.Rows(0).Cells("審核日期").Value
  93. AA(xlApp, xlSheet) : BB(xlApp, xlSheet) : CC(xlApp, xlSheet)
  94. xlSheet.PageSetup.PrintArea = ""
  95. xlApp.Cells.Select()
  96. xlSheet.Range("B1").Select()
  97. xlApp.Application.WindowState = xlMinimized
  98. xlApp.ActiveSheet.Protect(DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="0911274990")
  99. xlApp.ActiveSheet.EnableSelection = 1
  100. MsgBox("列印完成")
  101. Me.Close()
  102. End Sub
  103. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  104. 列印用SQL = "" : Me.Close()
  105. End Sub
  106. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  107. Return CType(xlBook.Worksheets.Add, Worksheet)
  108. End Function
  109. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  110. xlSheet.Cells.Select()
  111. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False
  112. .Superscript = False
  113. .Subscript = False
  114. .OutlineFont = False
  115. .Shadow = False
  116. .Underline = xlUnderlineStyleNone
  117. .ThemeColor = xlThemeColorLight1
  118. .TintAndShade = 0
  119. .ThemeFont = xlThemeFontNone
  120. End With
  121. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 5
  122. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 9
  123. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 25
  124. xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 9
  125. xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 15
  126. xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 10
  127. xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 12
  128. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 8
  129. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 10
  130. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 35
  131. xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 30
  132. xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 20
  133. xlSheet.Rows("4:" & N2 + 2 & "").Select : myExcel.Selection.RowHeight = 30
  134. xlSheet.Rows("" & N2 + 3 & ":" & N2 + 6 & "").Select : myExcel.Selection.RowHeight = 30
  135. 位置1 = "A3:I" & N2 + 2 : xlSheet.Range(位置1).Select()
  136. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  137. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = xlAutomatic : .TintAndShade = 0 : .Weight = xlThin : End With
  138. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = xlAutomatic : .TintAndShade = 0 : .Weight = xlThin : End With
  139. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = xlAutomatic : .TintAndShade = 0 : .Weight = xlThin : End With
  140. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = xlAutomatic : .TintAndShade = 0 : .Weight = xlThin : End With
  141. myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
  142. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = xlAutomatic : .TintAndShade = 0 : .Weight = xlThin : End With
  143. xlSheet.Range("A1:I1").Select() : myExcel.Selection.Merge
  144. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 20 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  145. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  146. xlSheet.Range("A2:I2").Select()
  147. With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlBottom : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  148. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  149. myExcel.ActiveWindow.DisplayGridlines = False
  150. 位置1 = "A2:A" & N2 + 4 : xlSheet.Range(位置1).Select()
  151. With myExcel.Selection : .HorizontalAlignment = xlLeft : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  152. .ReadingOrder = xlContext : .MergeCells = False : End With
  153. 位置1 = "D2:D" & N2 + 4 : xlSheet.Range(位置1).Select()
  154. With myExcel.Selection : .HorizontalAlignment = xlLeft : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  155. .ReadingOrder = xlContext : .MergeCells = False : End With
  156. 位置1 = "E2:E" & N2 + 4 : xlSheet.Range(位置1).Select()
  157. myExcel.Selection.Style = "Comma"
  158. With myExcel.Selection : .HorizontalAlignment = xlRight : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  159. .ReadingOrder = xlContext : .MergeCells = False : End With
  160. xlSheet.Range("E2").Select()
  161. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlBottom : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  162. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  163. 位置1 = "E" & N2 + 4 : xlSheet.Range(位置1).Select()
  164. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  165. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  166. 位置1 = "G" & N2 + 4 : xlSheet.Range(位置1).Select()
  167. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  168. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  169. 位置1 = "F" & N2 + 4 : xlSheet.Range(位置1).Select()
  170. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  171. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  172. 位置1 = "F" & N2 + 5 : xlSheet.Range(位置1).Select()
  173. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  174. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  175. 位置1 = "F" & N2 + 6 : xlSheet.Range(位置1).Select()
  176. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  177. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  178. 位置1 = "H" & N2 + 4 : xlSheet.Range(位置1).Select()
  179. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  180. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  181. xlSheet.Range("G2").Select()
  182. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  183. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  184. xlSheet.Range("F2").Select()
  185. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  186. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  187. xlSheet.Range("A1:I1").Select()
  188. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  189. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  190. xlSheet.Range("F2:G2").Select()
  191. With myExcel.Selection : .VerticalAlignment = xlBottom : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  192. .ReadingOrder = xlContext : .MergeCells = False : End With
  193. For I As Integer = 4 To N2
  194. xlSheet.Range("B" & I & ":D" & I).Select()
  195. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  196. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  197. myExcel.Selection.Merge
  198. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False
  199. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  200. Next
  201. End Sub
  202. Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  203. Clipboard.SetDataObject(PictureBox1.Image)
  204. 位置1 = "C" & N2 + 4 : xlSheet.Range(位置1).Select()
  205. myExcel.ActiveSheet.Pictures.Paste.Select
  206. myExcel.Selection.ShapeRange.Height = 43
  207. End Sub
  208. Private Sub CC(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  209. myExcel.Application.PrintCommunication = False
  210. With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
  211. myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
  212. With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
  213. .LeftMargin = myExcel.Application.InchesToPoints(0.25) : .RightMargin = myExcel.Application.InchesToPoints(0.25)
  214. .TopMargin = myExcel.Application.InchesToPoints(0.75) : .BottomMargin = myExcel.Application.InchesToPoints(0.75)
  215. .HeaderMargin = myExcel.Application.InchesToPoints(0.3) : .FooterMargin = myExcel.Application.InchesToPoints(0.3)
  216. .PrintHeadings = False : .PrintGridlines = False : .PrintQuality = 600 : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
  217. .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1 : .OddAndEvenPagesHeaderFooter = False
  218. .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True : .EvenPage.LeftHeader.Text = ""
  219. .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
  220. .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = ""
  221. .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
  222. End With
  223. myExcel.Application.PrintCommunication = True
  224. End Sub
  225. End Class