Nessuna descrizione
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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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 System.IO
  11. Imports Microsoft.Office.Interop.Excel
  12. Imports System.Threading
  13. Public Class 列印_訂單明細
  14. Private ReadOnly ds, ds2 As New DataSet
  15. Dim N1 As Integer = 5 : Dim N2 As Integer
  16. Dim M0, M1 As String
  17. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  18. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  19. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  20. Private Sub Set_訂單清單()
  21. DataGridView1.DataSource = Nothing : ds.Clear()
  22. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  23. DataGridView1.ColumnHeadersHeight = 25
  24. DataGridView1.AllowUserToAddRows = False
  25. SQL_訂單清單1()
  26. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  27. End Sub
  28. Private Sub Set_清單2()
  29. DataGridView2.DataSource = Nothing : ds2.Clear()
  30. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  31. DataGridView2.ColumnHeadersHeight = 25
  32. DataGridView2.AllowUserToAddRows = False
  33. ConnOpen()
  34. SQL1 = "SELECT 訂單流水號, 附件數 FROM 訂單附件資料 WHERE 訂單流水號 LIKE N'" & 列印用SQL1 & "' ORDER BY 附件數"
  35. CmdSet_For_DGV()
  36. da.Fill(ds2) : DataGridView2.DataSource = ds2.Tables(0) : conn.Close()
  37. End Sub
  38. Private Sub Set_格式設定()
  39. DataGridView1.Visible = False
  40. End Sub
  41. Private Sub 列印_訂單明細_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  42. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  43. Set_清單2() : Set_訂單清單() : Set_格式設定()
  44. End Sub
  45. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  46. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  47. xlBook = xlApp.Workbooks.Add
  48. xlApp.DisplayAlerts = True
  49. xlApp.Visible = True
  50. xlApp.Application.WindowState = xlMaximized
  51. For i As Integer = 0 To DataGridView2.Rows.Count - 1
  52. xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Name = "附件_" & i + 1 : xlBook.Activate() : xlSheet.Activate()
  53. PictureBox2.Image = Nothing
  54. ConnOpen()
  55. SQL1 = "SELECT TOP(1) 圖片 FROM 訂單附件資料
  56. WHERE 訂單流水號 LIKE N'" & DataGridView2.Rows(i).Cells("訂單流水號").Value & "' AND 附件數 LIKE N'" & DataGridView2.Rows(i).Cells("附件數").Value & "'"
  57. CmdSet_For_dr()
  58. While dr.Read() = True
  59. Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("圖片"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox2.Image = Bitmap.FromStream(oStream)
  60. End While
  61. conn.Close()
  62. PictureBox2.SizeMode = 4
  63. AA(xlApp, xlSheet)
  64. Next
  65. xlSheet = NewMethod(xlBook) : xlApp.Sheets(1).Name = "訂單" : xlBook.Activate() : xlSheet.Activate()
  66. CC(xlApp, xlSheet)
  67. xlSheet.Cells(2, 1) = "Number" : xlSheet.Cells(2, 3) = OD(0)
  68. xlSheet.Cells(3, 1) = "Created Date"
  69. xlSheet.Cells(3, 3) = OD(20) 'OD(1)
  70. xlSheet.Cells(4, 1) = "Brand" : xlSheet.Cells(4, 3) = OD(2) : xlSheet.Cells(5, 1) = "Vendor Name" : xlSheet.Cells(5, 3) = OD(3)
  71. xlSheet.Cells(7, 1) = "Mode Of Delivery" : xlSheet.Cells(7, 3) = OD(4) : xlSheet.Cells(8, 1) = "Delivery Terms" : xlSheet.Cells(8, 3) = OD(5)
  72. xlSheet.Cells(9, 1) = "Ship from name Ship from address" : xlSheet.Cells(9, 3) = OD(6)
  73. xlSheet.Cells(2, 4) = "Org. Ship Date" : xlSheet.Cells(2, 6) = OD(21) : xlSheet.Cells(3, 4) = "From Port" : xlSheet.Cells(3, 6) = OD(8)
  74. xlSheet.Cells(4, 4) = "To Port" : xlSheet.Cells(4, 6) = OD(9) : xlSheet.Cells(5, 4) = "Shipping Carrier" : xlSheet.Cells(5, 6) = OD(10)
  75. xlSheet.Cells(6, 4) = "Customer Requisition" : xlSheet.Cells(6, 6) = OD(39) : xlSheet.Cells(7, 4) = "Vendor Reference" : xlSheet.Cells(7, 6) = OD(11)
  76. xlSheet.Cells(8, 4) = "訂單屬性" : xlSheet.Cells(8, 6) = OD(45)
  77. 'xlSheet.Cells(2, 8) = "Modified Date" : xlSheet.Cells(2, 10) = OD(12)
  78. xlSheet.Cells(3, 8) = "Customer Name" : xlSheet.Cells(3, 10) = OD(13)
  79. xlSheet.Cells(4, 8) = "Ship Date" : xlSheet.Cells(4, 10) = OD(14)
  80. 'xlSheet.Cells(5, 8) = "Sales Order" : xlSheet.Cells(5, 10) = OD(15) : xlSheet.Cells(6, 8) = "ETA Date" : xlSheet.Cells(6, 10) = OD(16)
  81. xlSheet.Cells(8, 8) = "Delivery Address" : xlSheet.Cells(8, 10) = OD(17)
  82. xlSheet.Cells(2, 13) = OD(18) : xlSheet.Cells(3, 13) = "工廠:" : xlSheet.Cells(3, 14) = OD(19)
  83. xlSheet.Cells(4, 13) = "下單日:" : xlSheet.Cells(4, 14) = OD(20) : xlSheet.Cells(5, 13) = "交期:" : xlSheet.Cells(5, 14) = OD(21) : xlSheet.Cells(6, 13) = OD(40)
  84. xlSheet.Cells(16, 1) = "Item Number" : xlSheet.Cells(16, 2) = "Product Name" : xlSheet.Cells(16, 3) = "Color" : xlSheet.Cells(16, 4) = "DM"
  85. If OD(43) <> 0 Then : xlSheet.Cells(16, N1) = "4" : N1 += 1 : End If : If OD(44) <> 0 Then : xlSheet.Cells(16, N1) = "4.5" : N1 += 1 : End If
  86. If OD(22) <> 0 Then : xlSheet.Cells(16, N1) = "5" : N1 += 1 : End If : If OD(23) <> 0 Then : xlSheet.Cells(16, N1) = "5.5" : N1 += 1 : End If
  87. If OD(24) <> 0 Then : xlSheet.Cells(16, N1) = "6" : N1 += 1 : End If : If OD(25) <> 0 Then : xlSheet.Cells(16, N1) = "6.5" : N1 += 1 : End If
  88. If OD(26) <> 0 Then : xlSheet.Cells(16, N1) = "7" : N1 += 1 : End If : If OD(27) <> 0 Then : xlSheet.Cells(16, N1) = "7.5" : N1 += 1 : End If
  89. If OD(28) <> 0 Then : xlSheet.Cells(16, N1) = "8" : N1 += 1 : End If : If OD(29) <> 0 Then : xlSheet.Cells(16, N1) = "8.5" : N1 += 1 : End If
  90. If OD(30) <> 0 Then : xlSheet.Cells(16, N1) = "9" : N1 += 1 : End If : If OD(31) <> 0 Then : xlSheet.Cells(16, N1) = "9.5" : N1 += 1 : End If
  91. If OD(32) <> 0 Then : xlSheet.Cells(16, N1) = "10" : N1 += 1 : End If : If OD(33) <> 0 Then : xlSheet.Cells(16, N1) = "10.5" : N1 += 1 : End If
  92. If OD(34) <> 0 Then : xlSheet.Cells(16, N1) = "11" : N1 += 1 : End If : If OD(41) <> 0 Then : xlSheet.Cells(16, N1) = "11.5" : N1 += 1 : End If
  93. If OD(35) <> 0 Then : xlSheet.Cells(16, N1) = "12" : N1 += 1 : End If : If OD(42) <> 0 Then : xlSheet.Cells(16, N1) = "12.5" : N1 += 1 : End If
  94. If OD(36) <> 0 Then : xlSheet.Cells(16, N1) = "13" : N1 += 1 : End If : If OD(37) <> 0 Then : xlSheet.Cells(16, N1) = "14" : N1 += 1 : End If
  95. xlSheet.Cells(16, N1) = "TOTAL" : xlSheet.Cells(16, N1 + 1) = "備註"
  96. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  97. xlSheet.Cells(i + 17, 1) = DataGridView1.Rows(i).Cells("ItemNumber").Value
  98. xlSheet.Cells(i + 17, 2) = DataGridView1.Rows(i).Cells("ProductName").Value
  99. xlSheet.Cells(i + 17, 3) = DataGridView1.Rows(i).Cells("Color").Value
  100. xlSheet.Cells(i + 17, 4) = DataGridView1.Rows(i).Cells("DM").Value
  101. N1 = 5
  102. If OD(43) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("4").Value : N1 += 1 : End If
  103. If OD(44) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("4.5").Value : N1 += 1 : End If
  104. If OD(22) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("5").Value : N1 += 1 : End If
  105. If OD(23) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("5.5").Value : N1 += 1 : End If
  106. If OD(24) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("6").Value : N1 += 1 : End If
  107. If OD(25) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("6.5").Value : N1 += 1 : End If
  108. If OD(26) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("7").Value : N1 += 1 : End If
  109. If OD(27) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("7.5").Value : N1 += 1 : End If
  110. If OD(28) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("8").Value : N1 += 1 : End If
  111. If OD(29) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("8.5").Value : N1 += 1 : End If
  112. If OD(30) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("9").Value : N1 += 1 : End If
  113. If OD(31) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("9.5").Value : N1 += 1 : End If
  114. If OD(32) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("10").Value : N1 += 1 : End If
  115. If OD(33) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("10.5").Value : N1 += 1 : End If
  116. If OD(34) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("11").Value : N1 += 1 : End If
  117. If OD(41) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("11.5").Value : N1 += 1 : End If
  118. If OD(35) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("12").Value : N1 += 1 : End If
  119. If OD(42) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("12.5").Value : N1 += 1 : End If
  120. If OD(36) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("13").Value : N1 += 1 : End If
  121. If OD(37) <> 0 Then : xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("14").Value : N1 += 1 : End If
  122. xlSheet.Cells(i + 17, N1) = DataGridView1.Rows(i).Cells("TOTAL").Value
  123. xlSheet.Cells(i + 17, N1 + 1) = DataGridView1.Rows(i).Cells("備註").Value
  124. With xlApp.Selection
  125. .Font.Bold = True
  126. End With
  127. N2 = i
  128. Next i
  129. N1 = 5 : N2 += 3
  130. xlSheet.Cells(N2 + 17, N1) = "合計" : N1 = N1
  131. If OD(43) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(43) : N1 += 1 : End If : If OD(44) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(44) : N1 += 1 : End If '4 4.5
  132. If OD(22) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(22) : N1 += 1 : End If : If OD(23) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(23) : N1 += 1 : End If '5 5.5
  133. If OD(24) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(24) : N1 += 1 : End If : If OD(25) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(25) : N1 += 1 : End If '6 6.5
  134. If OD(26) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(26) : N1 += 1 : End If : If OD(27) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(27) : N1 += 1 : End If '7 7.5
  135. If OD(28) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(28) : N1 += 1 : End If : If OD(29) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(29) : N1 += 1 : End If '8 8.5
  136. If OD(30) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(30) : N1 += 1 : End If : If OD(31) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(31) : N1 += 1 : End If '9 9.5
  137. If OD(32) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(32) : N1 += 1 : End If : If OD(33) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(33) : N1 += 1 : End If '10 10.5
  138. If OD(34) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(34) : N1 += 1 : End If : If OD(41) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(41) : N1 += 1 : End If '11 11.5
  139. If OD(35) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(35) : N1 += 1 : End If : If OD(42) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(42) : N1 += 1 : End If '12 12.5
  140. If OD(36) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(36) : N1 += 1 : End If : If OD(37) <> 0 Then : xlSheet.Cells(N2 + 17, N1) = OD(37) : N1 += 1 : End If '13 14
  141. xlSheet.Cells(N2 + 17, N1) = OD(38) : N1 += 3
  142. BB(xlApp, xlSheet)
  143. xlSheet.PageSetup.PrintArea = ""
  144. xlApp.Cells.Select()
  145. xlSheet.Range("B1").Select()
  146. xlApp.Application.WindowState = xlMinimized
  147. MsgBox("列印完成")
  148. Me.Close()
  149. End Sub
  150. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  151. 列印用SQL = "" : Me.Close()
  152. End Sub
  153. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  154. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  155. End Function
  156. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  157. Clipboard.SetDataObject(PictureBox2.Image)
  158. xlSheet.Cells(1, 1).Select
  159. Thread.Sleep(100) '延迟0.1秒
  160. xlSheet.Range("A1").Select()
  161. myExcel.ActiveSheet.Paste
  162. If PictureBox2.Image.Height < PictureBox2.Image.Width Then
  163. myExcel.Selection.ShapeRange.Width = 900
  164. Else
  165. myExcel.Selection.ShapeRange.Height = 900
  166. End If
  167. myExcel.Selection.ShapeRange.IncrementLeft(2)
  168. myExcel.Selection.ShapeRange.IncrementTop(2)
  169. End Sub
  170. Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  171. Dim 位置1 As String
  172. If N1 = 6 Then : M0 = "D" : M1 = "F" : ElseIf N1 = 7 Then : M0 = "E" : M1 = "G" : ElseIf N1 = 8 Then : M0 = "F" : M1 = "H" : ElseIf N1 = 9 Then : M0 = "G" : M1 = "I"
  173. ElseIf N1 = 10 Then : M0 = "H" : M1 = "J" : ElseIf N1 = 11 Then : M0 = "I" : M1 = "K" : ElseIf N1 = 12 Then : M0 = "J" : M1 = "L" : ElseIf N1 = 13 Then : M0 = "K" : M1 = "M"
  174. ElseIf N1 = 14 Then : M0 = "L" : M1 = "N" : ElseIf N1 = 15 Then : M0 = "M" : M1 = "O" : ElseIf N1 = 16 Then : M0 = "N" : M1 = "P" : ElseIf N1 = 17 Then : M0 = "O" : M1 = "Q"
  175. ElseIf N1 = 18 Then : M0 = "P" : M1 = "R" : ElseIf N1 = 19 Then : M0 = "Q" : M1 = "S" : ElseIf N1 = 20 Then : M0 = "R" : M1 = "T" : ElseIf N1 = 21 Then : M0 = "S" : M1 = "U"
  176. ElseIf N1 = 22 Then : M0 = "T" : M1 = "V" : ElseIf N1 = 23 Then : M0 = "U" : M1 = "W" : ElseIf N1 = 24 Then : M0 = "V" : M1 = "X" : ElseIf N1 = 25 Then : M0 = "W" : M1 = "Y"
  177. ElseIf N1 = 26 Then : M0 = "X" : M1 = "Z" : ElseIf N1 = 27 Then : M0 = "Y" : M1 = "AA" : ElseIf N1 = 28 Then : M0 = "Z" : M1 = "AB" : ElseIf N1 = 29 Then : M0 = "AA" : M1 = "AC"
  178. ElseIf N1 = 30 Then : M0 = "AB" : M1 = "AD" : End If
  179. xlSheet.Cells.Select()
  180. With myExcel.Selection.Font
  181. .Name = "微軟正黑體" : .Size = 9 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  182. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  183. End With
  184. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 10
  185. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 18
  186. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 20
  187. xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 10
  188. xlSheet.Columns("E:Z").Select : myExcel.Selection.ColumnWidth = 6
  189. xlSheet.Rows("16:16").Select : myExcel.Selection.RowHeight = 30
  190. 位置1 = "17:" & N2 + 14 : xlSheet.Rows(位置1).Select : myExcel.Selection.RowHeight = 25
  191. 位置1 = "A17:D" & N2 + 14
  192. xlSheet.Range(位置1).Select()
  193. With myExcel.Selection
  194. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  195. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  196. End With
  197. With myExcel.Selection
  198. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  199. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  200. End With
  201. 位置1 = "E17:F" & N2 + 17 : xlSheet.Range(位置1).Select() : myExcel.Selection.NumberFormatLocal = "#,##0"
  202. 位置1 = "A16:" & M1 & N2 + 14 : xlSheet.Range(位置1).Select()
  203. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  204. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  205. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  206. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  207. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  208. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  209. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  210. 位置1 = "A16:" & M1 & "16" : xlSheet.Range(位置1).Select()
  211. With myExcel.Selection.Interior
  212. .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.599993896298105 : .PatternTintAndShade = 0
  213. End With
  214. 位置1 = "A16:" & M1 & "16" : xlSheet.Range(位置1).Select()
  215. With myExcel.Selection
  216. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  217. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  218. End With
  219. 位置1 = M0 & "16:" & M1 & "16" : xlSheet.Range(位置1).Select()
  220. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  221. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  222. For I As Integer = 17 To N2 + 14
  223. 位置1 = M0 & I & ":" & M1 & I : xlSheet.Range(位置1).Select()
  224. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  225. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  226. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  227. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  228. Next
  229. xlSheet.Range("A2:B2,A3:B3,A4:B4,A5:B6,C5:C6,A7:B7,A8:B8,A9:B15,C9:C15").Select() : xlSheet.Range("C9").Activate()
  230. With myExcel.Selection
  231. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  232. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  233. End With
  234. myExcel.Selection.Merge
  235. xlSheet.Range("D2:E2,D3:E3,D4:E4,D5:E5,D6:E6,D8:E8,F2:G2,F3:G3,F4:G4,F5:G5,F6:G6,F8:G8").Select() : xlSheet.Range("F6").Activate()
  236. With myExcel.Selection
  237. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  238. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  239. End With
  240. myExcel.Selection.Merge
  241. xlSheet.Range("H2:I2,H3:I3,H4:I4,H5:I5,H6:I7,H8:I15,J2:L2,J3:L3,J4:L4,J5:L5,J6:L7,J8:L15").Select() : xlSheet.Range("J8").Activate()
  242. With myExcel.Selection
  243. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  244. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  245. End With
  246. myExcel.Selection.Merge
  247. xlSheet.Range("M2:O2,N3:O3,N4:O4,N5:O5").Select() : xlSheet.Range("N5").Activate()
  248. With myExcel.Selection
  249. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  250. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  251. End With
  252. myExcel.Selection.Merge
  253. xlSheet.Range("A2:O15").Select()
  254. With myExcel.Selection
  255. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  256. .ShrinkToFit = False : .ReadingOrder = xlContext
  257. End With
  258. With myExcel.Selection
  259. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  260. .ShrinkToFit = False : .ReadingOrder = xlContext
  261. End With
  262. With myExcel.Selection
  263. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  264. .ShrinkToFit = False : .ReadingOrder = xlContext
  265. End With
  266. xlSheet.Range("A2:B15,D2:E8,H2:I15,M3:M5").Select() : xlSheet.Range("M3").Activate()
  267. With myExcel.Selection.Interior
  268. .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0
  269. End With
  270. xlSheet.Range("A1").Select() : myExcel.ActiveWindow.DisplayGridlines = False
  271. xlSheet.Range("D7:E7,F7:G7").Select() : xlSheet.Range("F7").Activate()
  272. With myExcel.Selection
  273. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  274. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  275. End With
  276. myExcel.Selection.Merge
  277. xlSheet.Range("D7:D7").Select()
  278. With myExcel.Selection.Interior
  279. .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent4 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0
  280. End With
  281. xlSheet.Rows("7:7").Select : xlSheet.Rows("7:7").EntireRow.AutoFit : xlSheet.Range("F10").Select()
  282. xlSheet.Range("D7:G7").Select()
  283. With myExcel.Selection
  284. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  285. .ShrinkToFit = False : .ReadingOrder = xlContext
  286. End With
  287. xlSheet.Range("C9:D15").Select()
  288. With myExcel.Selection
  289. .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  290. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  291. End With
  292. myExcel.Selection.UnMerge
  293. xlSheet.Range("J8:M15").Select()
  294. With myExcel.Selection
  295. .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  296. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  297. End With
  298. myExcel.Selection.UnMerge
  299. xlSheet.Range("C9:E15").Select()
  300. With myExcel.Selection
  301. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  302. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  303. End With
  304. myExcel.Selection.Merge
  305. xlSheet.Range("J8:N15").Select()
  306. With myExcel.Selection
  307. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  308. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  309. End With
  310. myExcel.Selection.Merge
  311. xlSheet.Range("C9:E15").Select()
  312. With myExcel.Selection
  313. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  314. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True
  315. End With
  316. xlSheet.Range("J8:N15").Select()
  317. With myExcel.Selection
  318. .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  319. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True
  320. End With
  321. xlSheet.Rows("8:9").Select
  322. xlSheet.Rows("8:9").EntireRow.AutoFit
  323. xlSheet.Range("C1").Select()
  324. xlApp.Application.PrintCommunication = False
  325. With xlBook.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
  326. xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.PrintArea = "" : xlApp.Application.PrintCommunication = False
  327. With xlBook.ActiveSheet.PageSetup
  328. .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
  329. .LeftMargin = xlApp.Application.InchesToPoints(0.7) : .RightMargin = xlApp.Application.InchesToPoints(0.7)
  330. .TopMargin = xlApp.Application.InchesToPoints(0.75) : .BottomMargin = xlApp.Application.InchesToPoints(0.75)
  331. .HeaderMargin = xlApp.Application.InchesToPoints(0.3) : .FooterMargin = xlApp.Application.InchesToPoints(0.3)
  332. .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
  333. .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = 100 : .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False
  334. .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True : .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = ""
  335. .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = ""
  336. .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = ""
  337. .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
  338. End With
  339. xlApp.Application.PrintCommunication = True : xlApp.Application.PrintCommunication = False
  340. With xlBook.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
  341. xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.PrintArea = "" : xlApp.Application.PrintCommunication = False
  342. With xlBook.ActiveSheet.PageSetup
  343. .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
  344. .LeftMargin = xlApp.Application.InchesToPoints(0.708661417322835) : .RightMargin = xlApp.Application.InchesToPoints(0.708661417322835)
  345. .TopMargin = xlApp.Application.InchesToPoints(0.748031496062992) : .BottomMargin = xlApp.Application.InchesToPoints(0.748031496062992)
  346. .HeaderMargin = xlApp.Application.InchesToPoints(0.31496062992126) : .FooterMargin = xlApp.Application.InchesToPoints(0.31496062992126)
  347. .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
  348. .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1
  349. .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
  350. .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = ""
  351. .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = ""
  352. .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
  353. End With
  354. xlApp.Application.PrintCommunication = True : xlApp.Application.PrintCommunication = False
  355. With xlBook.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
  356. xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.PrintArea = "" : xlApp.Application.PrintCommunication = False
  357. With xlBook.ActiveSheet.PageSetup
  358. .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = ""
  359. .LeftMargin = xlApp.Application.InchesToPoints(0.25) : .RightMargin = xlApp.Application.InchesToPoints(0.25)
  360. .TopMargin = xlApp.Application.InchesToPoints(0.75) : .BottomMargin = xlApp.Application.InchesToPoints(0.75)
  361. .HeaderMargin = xlApp.Application.InchesToPoints(0.3) : .FooterMargin = xlApp.Application.InchesToPoints(0.3)
  362. .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
  363. .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1
  364. .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True
  365. .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = ""
  366. .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = ""
  367. .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
  368. End With
  369. xlApp.Application.PrintCommunication = True : xlBook.ActiveSheet.PageSetup.Orientation = 2
  370. xlBook.ActiveSheet.PageSetup.CenterFooter = OD(18) & "-" & OD(0)
  371. xlSheet.Range("M6:N6").Select()
  372. With myExcel.Selection
  373. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  374. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  375. End With
  376. myExcel.Selection.Merge
  377. xlSheet.Rows("6:6").Select : xlSheet.Range("O6").Activate() : myExcel.Selection.RowHeight = 12.75
  378. xlSheet.Range("O7").Select()
  379. End Sub
  380. Private Sub CC(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  381. xlSheet.Range("C2").Select() : myExcel.Selection.NumberFormatLocal = "@"
  382. End Sub
  383. End Class