Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

列印_訂單明細.vb 30KB

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