暫無描述
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 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 ds1 As New DataSet : ReadOnly ds2 As New DataSet
  13. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  14. Dim N1 As Integer
  15. Private Sub Set_採購清單()
  16. DataGridView2.DataSource = Nothing : ds1.Clear() : DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView2.ColumnHeadersHeight = 25
  17. DataGridView2.AllowUserToAddRows = False : DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView2.MultiSelect = True
  18. SQL_採購退貨清單_單號彙總()
  19. da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
  20. DataGridView2.Columns(0).FillWeight = 135 : DataGridView2.Columns(1).FillWeight = 90 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).FillWeight = 100
  21. DataGridView2.Columns(4).FillWeight = 90
  22. End Sub
  23. Private Sub Set_單據明細()
  24. DataGridView3.DataSource = Nothing : ds2.Clear() : DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView3.ColumnHeadersHeight = 25
  25. DataGridView3.AllowUserToAddRows = False : DataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView3.MultiSelect = True
  26. SQL_採購退貨清單明細()
  27. da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close()
  28. TextBox15.Text = "0"
  29. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  30. DataGridView3(1, i).Value = i + 1 : TextBox15.Text = Val(TextBox15.Text) + DataGridView3.Rows(i).Cells("進貨成本_台幣").Value
  31. DataGridView3.Rows(i).Cells("選擇").Value = False
  32. Next
  33. TextBox15.Text = Strings.Format(Val(TextBox15.Text), "#,#00")
  34. DataGridView3.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(7).DefaultCellStyle.Format = "#,##0.00"
  35. DataGridView3.Columns(8).DefaultCellStyle.Format = "#,##0.0000" : DataGridView3.Columns(9).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(10).DefaultCellStyle.Format = "#,##0"
  36. DataGridView3.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  37. DataGridView3.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  38. DataGridView3.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  39. DataGridView3.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  40. DataGridView3.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  41. DataGridView3.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  42. DataGridView3.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  43. DataGridView3.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  44. DataGridView3.Columns(0).Visible = False : DataGridView3.Columns(1).FillWeight = 50 : DataGridView3.Columns(2).FillWeight = 80 : DataGridView3.Columns(3).FillWeight = 200
  45. DataGridView3.Columns(4).Visible = False : DataGridView3.Columns(5).Visible = False : DataGridView3.Columns(6).FillWeight = 50 : DataGridView3.Columns(7).FillWeight = 50
  46. DataGridView3.Columns(8).FillWeight = 50 : DataGridView3.Columns(9).FillWeight = 50 : DataGridView3.Columns(10).FillWeight = 65 : DataGridView3.Columns(11).FillWeight = 100
  47. DataGridView3.Columns(12).FillWeight = 80 : DataGridView3.Columns(13).Visible = False : DataGridView3.Columns(14).Visible = False : DataGridView3.Columns(15).Visible = False
  48. DataGridView3.Columns(16).Visible = False : DataGridView3.Columns(17).FillWeight = 50
  49. DataGridView3.EditMode = DataGridViewEditMode.EditOnEnter
  50. DataGridView3.Columns(1).ReadOnly = True : DataGridView3.Columns(2).ReadOnly = True : DataGridView3.Columns(3).ReadOnly = True : DataGridView3.Columns(4).ReadOnly = True
  51. DataGridView3.Columns(5).ReadOnly = True : DataGridView3.Columns(8).ReadOnly = True : DataGridView3.Columns(9).ReadOnly = True : DataGridView3.Columns(10).ReadOnly = True
  52. DataGridView3.Columns(12).ReadOnly = True
  53. End Sub
  54. Private Sub ComboBox2下拉表單資料載入()
  55. SQL_供應商資料表下拉清單()
  56. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close()
  57. End Sub
  58. Private Sub 採購退貨清單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  59. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  60. ComboBox2.Enabled = False : ComboBox3.Enabled = False : TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox4.Enabled = False : TextBox26.Enabled = False
  61. TextBox6.Enabled = False : TextBox8.Enabled = False : TextBox9.Enabled = False : TextBox10.Enabled = False : TextBox11.Enabled = False : TextBox12.Enabled = False
  62. TextBox13.Enabled = False : TextBox14.Enabled = False : TextBox15.Enabled = False : DateTimePicker1.Enabled = False : DateTimePicker2.Enabled = False
  63. Set_採購清單() : ComboBox2下拉表單資料載入()
  64. End Sub
  65. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  66. If e.RowIndex = -1 Then : Else
  67. TextBox9.Text = DataGridView2.Rows(e.RowIndex).Cells("單據編號").Value.ToString : ComboBox3.Text = DataGridView2.Rows(e.RowIndex).Cells("供應商編號").Value.ToString
  68. DateTimePicker1.Value = DataGridView2.Rows(e.RowIndex).Cells("採購下單").Value.ToString : DateTimePicker2.Value = DataGridView2.Rows(e.RowIndex).Cells("交期").Value.ToString
  69. Set_單據明細()
  70. End If
  71. End Sub
  72. Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellClick
  73. If e.RowIndex = -1 Then : Else
  74. TextBox14.Text = DataGridView3.Rows(e.RowIndex).Cells("資料流水號").Value.ToString
  75. For i As Integer = 0 To DataGridView3.Rows.Count - 1 : DataGridView3.Rows(i).Cells("選擇").Value = False : Next
  76. DataGridView3.Rows(e.RowIndex).Cells("選擇").Value = True
  77. End If
  78. End Sub
  79. Private Sub DataGridView3_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView3.CellEnter
  80. TextBox15.Text = "0"
  81. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  82. DataGridView3.Rows(i).Cells("台幣單價").Value = DataGridView3.Rows(i).Cells("單價").Value * DataGridView3.Rows(i).Cells("匯率").Value
  83. DataGridView3.Rows(i).Cells("進貨成本_台幣").Value = DataGridView3.Rows(i).Cells("單價").Value * DataGridView3.Rows(i).Cells("匯率").Value * DataGridView3.Rows(i).Cells("數量").Value
  84. DataGridView3(1, i).Value = i + 1
  85. TextBox15.Text = Val(TextBox15.Text) + DataGridView3.Rows(i).Cells("進貨成本_台幣").Value
  86. Next i
  87. TextBox15.Text = Strings.Format(Val(TextBox15.Text), "#,#00")
  88. End Sub
  89. Private Sub 供應商資料()
  90. SQL_採購退貨清單_供應商資料表讀取()
  91. If (dr.Read()) Then
  92. TextBox2.Text = dr("名稱") : TextBox6.Text = dr("公司電話1") : TextBox3.Text = dr("公司電話2") : TextBox8.Text = dr("傳真1") : TextBox11.Text = dr("郵遞區號1")
  93. TextBox10.Text = dr("地址1") : TextBox13.Text = dr("郵遞區號2") : TextBox12.Text = dr("地址2") : TextBox26.Text = dr("統一編號") : TextBox4.Text = dr("付款方式")
  94. End If : conn.Close()
  95. End Sub
  96. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
  97. ComboBox3.SelectedIndex = ComboBox2.SelectedIndex : 供應商資料()
  98. End Sub
  99. Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
  100. ComboBox2.SelectedIndex = ComboBox3.SelectedIndex : 供應商資料()
  101. End Sub
  102. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  103. xlApp = CType(CreateObject("Excel.Application"), Application)
  104. xlBook = xlApp.Workbooks.Add
  105. xlApp.DisplayAlerts = True
  106. xlBook.Activate()
  107. xlSheet = NewMethod(xlBook)
  108. xlSheet.Activate()
  109. xlApp.Visible = True
  110. xlApp.Application.WindowState = xlMaximized
  111. xlSheet.Cells(1, 1) = MAOJI_ERP_SYS.ComboBox2.Text : xlSheet.Cells(2, 1) = 公司地址 : xlSheet.Cells(3, 1) = "採購訂單-退貨單" : xlSheet.Cells(4, 1) = "採購編號 : "
  112. xlSheet.Cells(4, 3) = TextBox9.Text
  113. xlSheet.Cells(5, 1) = "採購日期 : " : xlSheet.Cells(5, 3) = DateTimePicker1.Value : xlSheet.Cells(5, 6) = "付款方式 : " : xlSheet.Cells(5, 7) = TextBox4.Text : xlSheet.Cells(5, 9) = "需求交期 : "
  114. xlSheet.Cells(5, 10) = DateTimePicker2.Value : xlSheet.Cells(4, 9) = "統一編號 : " : xlSheet.Cells(4, 10) = 公司統編 : xlSheet.Cells(7, 1) = "TO : " : xlSheet.Cells(8, 1) = "郵號1 : "
  115. xlSheet.Cells(9, 1) = "郵號1 : " : xlSheet.Cells(7, 2) = TextBox2.Text : xlSheet.Cells(8, 2) = TextBox11.Text : xlSheet.Cells(9, 2) = TextBox13.Text : xlSheet.Cells(8, 3) = "地址1 : "
  116. xlSheet.Cells(9, 3) = "地址2 : " : xlSheet.Cells(8, 4) = TextBox10.Text : xlSheet.Cells(9, 4) = TextBox12.Text : xlSheet.Cells(7, 9) = "公司電話1 : " : xlSheet.Cells(8, 9) = "公司電話2 : "
  117. xlSheet.Cells(9, 9) = "傳真 : " : xlSheet.Cells(7, 10) = TextBox6.Text : xlSheet.Cells(8, 10) = TextBox3.Text : xlSheet.Cells(9, 10) = TextBox8.Text : xlSheet.Cells(11, 1) = "項次"
  118. xlSheet.Cells(11, 2) = "料號" : xlSheet.Cells(11, 4) = "品名" : xlSheet.Cells(11, 6) = "數量" : xlSheet.Cells(11, 7) = "單價" : xlSheet.Cells(11, 8) = "匯率" : xlSheet.Cells(11, 9) = "採購金額"
  119. xlSheet.Cells(11, 10) = "備註"
  120. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  121. xlSheet.Cells(i + 12, 1) = DataGridView3.Rows(i).Cells("項次").Value
  122. xlSheet.Cells(i + 12, 2) = DataGridView3.Rows(i).Cells("料號").Value
  123. xlSheet.Cells(i + 12, 4) = DataGridView3.Rows(i).Cells("品名").Value
  124. xlSheet.Cells(i + 12, 6) = DataGridView3.Rows(i).Cells("數量").Value
  125. xlSheet.Cells(i + 12, 7) = DataGridView3.Rows(i).Cells("單價").Value
  126. xlSheet.Cells(i + 12, 8) = DataGridView3.Rows(i).Cells("匯率").Value
  127. xlSheet.Cells(i + 12, 9) = "=F" & i + 12 & "*G" & i + 12 & "*H" & i + 12
  128. xlSheet.Cells(i + 12, 10) = DataGridView3.Rows(i).Cells("備註").Value
  129. N1 = i + 12
  130. Next
  131. xlSheet.Cells(N1 + 1, 5) = "TOTAL : " : xlSheet.Cells(N1 + 1, 6) = "=SUM(F12:F" & N1 & ")" : xlSheet.Cells(N1 + 1, 9) = "=SUM(I12:I" & N1 & ")" : xlSheet.Cells(N1 + 2, 1) = "核准 : "
  132. xlSheet.Cells(N1 + 2, 9) = "製表人 : " : xlSheet.Cells(N1 + 2, 10) = gUserName
  133. AA(xlApp, xlSheet)
  134. xlSheet.PageSetup.PrintArea = ""
  135. xlApp.Cells.Select()
  136. xlSheet.Range("B1").Select()
  137. xlApp.Application.WindowState = xlMinimized
  138. xlSheet.Cells.Select()
  139. xlApp.ActiveSheet.Protect(DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="0911274990")
  140. xlApp.ActiveSheet.EnableSelection = 1
  141. MsgBox("列印完成。")
  142. End Sub
  143. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  144. Return CType(xlBook.Worksheets.Add, Worksheet)
  145. End Function
  146. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  147. xlSheet.Cells.Select()
  148. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  149. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  150. xlSheet.Columns("A:C").Select : myExcel.Selection.ColumnWidth = 6
  151. xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 10
  152. xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 20
  153. xlSheet.Columns("F:G").Select : myExcel.Selection.ColumnWidth = 10
  154. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 8
  155. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 12
  156. xlSheet.Columns("J:J").Select : myExcel.Selection.ColumnWidth = 30
  157. xlSheet.Rows("1:1").Select
  158. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 28 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  159. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  160. xlSheet.Rows("2:2").Select
  161. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  162. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  163. xlSheet.Rows("3:3").Select
  164. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  165. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  166. xlSheet.Range("A1:J1").Select()
  167. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  168. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  169. xlSheet.Range("A2:J2").Select()
  170. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  171. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  172. xlSheet.Range("A3:J3").Select()
  173. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  174. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  175. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  176. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  177. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  178. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  179. xlSheet.Range("A4:B4").Select()
  180. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  181. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  182. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  183. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  184. xlSheet.Range("A5:B5").Select()
  185. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  186. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  187. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  188. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  189. xlSheet.Range("C4:D4").Select()
  190. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  191. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  192. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  193. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  194. xlSheet.Range("C5:D5").Select()
  195. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  196. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  197. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  198. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  199. xlSheet.Range("J4").Select()
  200. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  201. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  202. xlSheet.Range("J5").Select()
  203. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  204. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  205. xlSheet.Range("A7:A9").Select()
  206. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  207. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  208. xlSheet.Range("I4:I9").Select()
  209. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  210. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  211. xlSheet.Range("B8").Select()
  212. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  213. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  214. xlSheet.Range("C8:C9").Select()
  215. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  216. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  217. xlSheet.Rows("4:9").Select : myExcel.Selection.RowHeight = 18
  218. xlSheet.Rows("6:6").Select : myExcel.Selection.RowHeight = 5
  219. xlSheet.Rows("10:10").Select : myExcel.Selection.RowHeight = 5
  220. xlSheet.Rows("11:11").Select : myExcel.Selection.RowHeight = 25
  221. xlSheet.Rows("12:" & N1 + 1).Select : myExcel.Selection.RowHeight = 18
  222. xlSheet.Rows(N1 + 2 & ":" & N1 + 2).Select : myExcel.Selection.RowHeight = 30
  223. xlSheet.Range("A4:B5").Select()
  224. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  225. xlSheet.Range("F5").Select()
  226. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  227. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  228. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  229. xlSheet.Range("I4:I5").Select()
  230. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  231. xlSheet.Range("A5:J5").Select()
  232. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  233. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  234. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  235. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  236. xlSheet.Range("A7:A9").Select()
  237. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  238. xlSheet.Range("C8:C9").Select()
  239. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  240. xlSheet.Range("I7:I9").Select()
  241. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  242. xlSheet.Range("A9:J9").Select()
  243. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  244. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  245. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  246. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  247. xlSheet.Range("A11:J" & N1).Select()
  248. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  249. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  250. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  251. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  252. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  253. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  254. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  255. xlSheet.Range("A" & N1 + 1 & ":J" & N1 + 1).Select()
  256. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  257. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  258. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  259. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  260. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  261. myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  262. xlSheet.Range("A11:A" & N1).Select()
  263. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  264. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  265. For i As Integer = 11 To N1
  266. xlSheet.Range("B" & i & ":C" & i).Select()
  267. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  268. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  269. xlSheet.Range("D" & i & ":E" & i).Select()
  270. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  271. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  272. Next
  273. xlSheet.Range("F11:F" & N1 + 1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
  274. xlSheet.Range("F11").Select()
  275. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  276. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  277. xlSheet.Range("G11:G" & N1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0.0_-;-* #,##0.0_-;_-* ""-""??_-;_-@_-"
  278. xlSheet.Range("G11").Select()
  279. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  280. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  281. xlSheet.Range("H11:H" & N1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0.000_-;-* #,##0.000_-;_-* ""-""??_-;_-@_-"
  282. xlSheet.Range("H11").Select()
  283. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  284. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  285. xlSheet.Range("I11:I" & N1 + 1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
  286. xlSheet.Range("I11").Select()
  287. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  288. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  289. xlSheet.Range("E" & N1 + 1).Select()
  290. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  291. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  292. xlSheet.Range("A" & N1 + 2).Select()
  293. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  294. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  295. xlSheet.Range("I" & N1 + 2).Select()
  296. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  297. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  298. myExcel.ActiveWindow.DisplayGridlines = False
  299. End Sub
  300. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  301. If TextBox9.Text = "" Then : MsgBox("沒有選擇要列印的單號 。") : Else : 列印用SQL = TextBox9.Text : PA = "採購退貨單" : 列印_產品標籤介面.ShowDialog() : End If
  302. End Sub
  303. '-----------------------------滑鼠右鍵------------------------------------------------------------------------------------------------------------------------------------------
  304. Private Sub 重新整理ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新整理ToolStripMenuItem.Click
  305. Set_採購清單() : ComboBox2下拉表單資料載入()
  306. End Sub
  307. Private Sub 列印退貨單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 列印退貨單ToolStripMenuItem.Click
  308. Me.Button3.PerformClick()
  309. End Sub
  310. Private Sub 列印產品標籤ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 列印產品標籤ToolStripMenuItem.Click
  311. Me.Button1.PerformClick()
  312. End Sub
  313. End Class