Ei kuvausta
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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. Imports Microsoft.Office.Interop.Excel
  11. Public Class 列印_產品標籤介面
  12. ReadOnly ds As New DataSet : Dim N1 As Integer : Dim N2 As Integer
  13. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  14. Private Sub Set_清單()
  15. DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView1.ColumnHeadersHeight = 40
  16. DataGridView1.AllowUserToAddRows = False : DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView1.MultiSelect = True
  17. SQL_列印_產品標籤清單()
  18. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  19. End Sub
  20. Private Sub 列印_產品標籤介面_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  21. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  22. Set_清單()
  23. CheckBox1.Checked = True
  24. End Sub
  25. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  26. 列印用SQL = "" : PA = "" : Me.Close()
  27. End Sub
  28. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  29. xlApp = CType(CreateObject("Excel.Application"), Application)
  30. xlBook = xlApp.Workbooks.Add
  31. xlApp.DisplayAlerts = True
  32. xlApp.Visible = True
  33. xlApp.Application.WindowState = xlMaximized
  34. For I As Integer = 0 To DataGridView1.Rows.Count - 1
  35. xlSheet = NewMethod(xlBook) : xlBook.Activate() : xlSheet.Activate()
  36. xlApp.Sheets(1).Name = DataGridView1.Rows(I).Cells("料號").Value
  37. AA(xlApp, xlSheet)
  38. If PA = "維修申請單" Then
  39. TextBox1.Text = DataGridView1.Rows(I).Cells("出庫").Value : PA1 = "維修申請單-出庫"
  40. ElseIf PA = "銷售退貨單" Then
  41. TextBox1.Text = DataGridView1.Rows(I).Cells("出庫").Value * -1 : PA1 = "銷售退貨單-退庫"
  42. ElseIf PA = "銷售出貨單" Then
  43. TextBox1.Text = DataGridView1.Rows(I).Cells("出庫").Value : PA1 = "銷售出貨單-出庫"
  44. ElseIf PA = "採購訂貨單" Then
  45. TextBox1.Text = DataGridView1.Rows(I).Cells("入庫").Value : PA1 = "採購訂貨單-入庫"
  46. ElseIf PA = "採購退貨單" Then
  47. TextBox1.Text = DataGridView1.Rows(I).Cells("入庫").Value * -1 : PA1 = "採購退貨單-退庫"
  48. End If
  49. If CheckBox1.Checked = True Then
  50. N1 = 0
  51. For II As Integer = 1 To Val(TextBox1.Text)
  52. xlSheet.Cells(1 + N1, 1) = MAOJI_ERP_SYS.ComboBox2.Text : xlSheet.Cells(2 + N1, 1) = PA1
  53. xlSheet.Cells(3 + N1, 1) = "系統單號 : " : xlSheet.Cells(3 + N1, 2) = DataGridView1.Rows(I).Cells("單據編號").Value : xlSheet.Cells(3 + N1, 3) = "單據數量"
  54. xlSheet.Cells(4 + N1, 1) = "系統料號 : " : xlSheet.Cells(4 + N1, 2) = DataGridView1.Rows(I).Cells("料號").Value : xlSheet.Cells(4 + N1, 3) = TextBox1.Text
  55. xlSheet.Cells(5 + N1, 1) = "產品頁碼 : " : xlSheet.Cells(5 + N1, 2) = DataGridView1.Rows(I).Cells("頁碼").Value
  56. xlSheet.Cells(6 + N1, 1) = "產品名稱 : " : xlSheet.Cells(6 + N1, 2) = DataGridView1.Rows(I).Cells("品名").Value
  57. xlSheet.Cells(7 + N1, 1) = "產品件數 : 共 ( )"
  58. BB(xlApp, xlSheet)
  59. N1 += 8
  60. Next
  61. Else
  62. xlSheet.Cells(1, 1) = MAOJI_ERP_SYS.ComboBox2.Text : xlSheet.Cells(2, 1) = PA1
  63. xlSheet.Cells(3, 1) = "系統單號 : " : xlSheet.Cells(3, 2) = DataGridView1.Rows(I).Cells("項次").Value : xlSheet.Cells(6, 3) = "單據數量"
  64. xlSheet.Cells(4, 1) = "系統料號 : " : xlSheet.Cells(4, 2) = DataGridView1.Rows(I).Cells("項次").Value : xlSheet.Cells(4, 3) = TextBox1.Text
  65. xlSheet.Cells(5, 1) = "產品頁碼 : " : xlSheet.Cells(5, 2) = DataGridView1.Rows(I).Cells("項次").Value
  66. xlSheet.Cells(6, 1) = "產品名稱 : " : xlSheet.Cells(6, 2) = DataGridView1.Rows(I).Cells("項次").Value
  67. xlSheet.Cells(7, 1) = "產品件數 : 共 ( )"
  68. BB(xlApp, xlSheet)
  69. End If
  70. CC(xlApp, xlSheet)
  71. Next
  72. N2 = DataGridView1.Rows.Count + 1 : xlApp.Sheets(N2).Delete
  73. xlSheet.PageSetup.PrintArea = ""
  74. xlApp.Cells.Select()
  75. xlSheet.Range("B1").Select()
  76. xlApp.Application.WindowState = xlMinimized
  77. xlSheet.Cells.Select()
  78. MsgBox("列印完成。")
  79. 列印用SQL = "" : PA = "" : Me.Close()
  80. End Sub
  81. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  82. Return CType(xlBook.Worksheets.Add, Worksheet)
  83. End Function
  84. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  85. xlSheet.Cells.Select()
  86. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  87. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  88. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 10
  89. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 30
  90. xlSheet.Columns("C:C").Select
  91. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  92. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  93. myExcel.ActiveWindow.DisplayGridlines = False
  94. End Sub
  95. Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  96. xlSheet.Range("A" & 1 + N1 & ":C" & 1 + N1).Select()
  97. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  98. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  99. xlSheet.Range("A" & 2 + N1 & ":C" & 2 + N1).Select()
  100. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  101. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  102. xlSheet.Range("A" & 1 + N1 & ":C" & 7 + N1).Select()
  103. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  104. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  105. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  106. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  107. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  108. myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  109. xlSheet.Rows(1 + N1 & ":" & 7 + N1).Select : myExcel.Selection.RowHeight = 22
  110. xlSheet.Rows(8 + N1 & ":" & 8 + N1).Select : myExcel.Selection.RowHeight = 5
  111. End Sub
  112. Private Sub CC(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  113. myExcel.Application.PrintCommunication = False
  114. With myExcel.ActiveSheet.PageSetup
  115. .PrintTitleRows = ""
  116. .PrintTitleColumns = ""
  117. End With
  118. myExcel.Application.PrintCommunication = True
  119. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  120. myExcel.Application.PrintCommunication = False
  121. With myExcel.ActiveSheet.PageSetup
  122. .LeftHeader = ""
  123. .CenterHeader = ""
  124. .RightHeader = ""
  125. .LeftFooter = ""
  126. .CenterFooter = ""
  127. .RightFooter = ""
  128. .LeftMargin = myExcel.Application.InchesToPoints(0.118110236220472)
  129. .RightMargin = myExcel.Application.InchesToPoints(0.118110236220472)
  130. .TopMargin = myExcel.Application.InchesToPoints(0.196850393700787)
  131. .BottomMargin = myExcel.Application.InchesToPoints(0.196850393700787)
  132. .HeaderMargin = myExcel.Application.InchesToPoints(0.31496062992126)
  133. .FooterMargin = myExcel.Application.InchesToPoints(0.31496062992126)
  134. .PrintHeadings = False
  135. .PrintGridlines = False
  136. '.PrintQuality = 203
  137. .CenterHorizontally = True
  138. .CenterVertically = True
  139. .Draft = False
  140. '.PaperSize = 260
  141. .FirstPageNumber = xlAutomatic
  142. .BlackAndWhite = False
  143. .Zoom = 90
  144. .OddAndEvenPagesHeaderFooter = False
  145. .DifferentFirstPageHeaderFooter = False
  146. .ScaleWithDocHeaderFooter = True
  147. .AlignMarginsHeaderFooter = True
  148. .EvenPage.LeftHeader.Text = ""
  149. .EvenPage.CenterHeader.Text = ""
  150. .EvenPage.RightHeader.Text = ""
  151. .EvenPage.LeftFooter.Text = ""
  152. .EvenPage.CenterFooter.Text = ""
  153. .EvenPage.RightFooter.Text = ""
  154. .FirstPage.LeftHeader.Text = ""
  155. .FirstPage.CenterHeader.Text = ""
  156. .FirstPage.RightHeader.Text = ""
  157. .FirstPage.LeftFooter.Text = ""
  158. .FirstPage.CenterFooter.Text = ""
  159. .FirstPage.RightFooter.Text = ""
  160. End With
  161. myExcel.Application.PrintCommunication = True
  162. End Sub
  163. End Class