Няма описание
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 69KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. Public Class 訂單列印選擇
  11. ReadOnly ds As New DataSet
  12. ReadOnly OPEXC(2) As Boolean
  13. Dim selectdate As Date : Dim DTP As Date
  14. Dim P As Integer = 0 : Dim R As Integer = 0 : Dim A As Integer = 0 : Dim Q As Integer = 0
  15. Dim Index_PRS As Integer = 0 : Dim Index_FTY_XF As Integer = 0 : Dim Index_月_total As Integer = 0
  16. Dim 位置1 As String : Dim 位置2 As String : Dim 位置3 As String : Dim 位置4 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. ReadOnly SQL字串1 As String = "SELECT " & 訂單資料表(1) & ".訂單流水號, " & 訂單資料表(1) & ".年份季度, " & 訂單資料表(1) & ".客戶訂單號, " & 訂單資料表(1) & ".形體號, " & 訂單資料表(1) & ".顏色,
  21. " & 訂單資料表(1) & ".楦型, " & 訂單資料表(1) & ".訂單數量, " & 訂單資料表(1) & ".客戶交期, " & 訂單資料表(1) & ".單價, " & 訂單資料表(1) & ".總金額,
  22. " & 訂單資料表(1) & ".備註, " & 訂單資料表(1) & ".生產工廠, " & 訂單資料表(1) & ".訂單種類, " & 訂單資料表(1) & ".工廠回復交期, " & 訂單資料表(1) & ".CFMSPEC,
  23. " & 訂單資料表(1) & ".CFMSAMPLE, " & 訂單資料表(1) & ".TRIAL1, " & 訂單資料表(1) & ".TRIAL2, " & 訂單資料表(1) & ".TRIAL3, " & 訂單資料表(1) & ".TRIAL4,
  24. " & 訂單資料表(1) & ".包裝確認時間, " & 訂單資料表(1) & ".貼標時間, " & 訂單資料表(1) & ".裁斷時間, " & 訂單資料表(1) & ".針車時間,
  25. " & 訂單資料表(1) & ".成型時間, " & 訂單資料表(1) & ".驗貨時間, " & 訂單資料表(1) & ".實際離廠日, " & 訂單資料表(1) & ".資料流水號,
  26. " & 訂單資料表(1) & ".明細建檔, " & 訂單資料表(1) & ".GOODBOX, " & 訂單資料表(1) & ".LEATHER, " & 訂單資料表(1) & ".LEA_Note, " & 訂單資料表(1) & ".出貨數量,
  27. " & 訂單資料表(1) & ".PO_S_Date AS 接單日, " & 訂單資料表(1) & ".Requested_XF AS 需求日期, " & 訂單資料表(1) & ".Confirm_XF AS 確認日期,
  28. " & 訂單資料表(1) & ".Revised_XF AS 修訂日期, " & 訂單資料表(1) & ".工廠回復交期 AS 工廠交期, " & 訂單資料表(1) & ".Special_Packaging,
  29. " & 訂單資料表(1) & ".Remarks, " & 訂單資料表(1) & ".出貨地, " & 訂單資料表(1) & ".TVW, " & 訂單資料表(1) & ".楦頭號, " & 訂單資料表(1) & ".材質,
  30. " & 訂單資料表(1) & ".七號模具, " & 訂單資料表(1) & ".TRIAL1 AS T1, " & 訂單資料表(1) & ".TRIAL2 AS T2, " & 訂單資料表(1) & ".長期試穿 AS WEAR_TEST,
  31. " & 訂單資料表(1) & ".CFMSAMPLE AS CFM, " & 訂單資料表(1) & ".TRIAL3 AS T3, " & 訂單資料表(1) & ".TRIAL4 AS T4, " & 訂單資料表(1) & ".CFMSPEC AS TEST,
  32. " & 訂單資料表(1) & ".面料, " & 訂單資料表(1) & ".副料, " & 訂單資料表(1) & ".中底, " & 訂單資料表(1) & ".鞋墊, " & 訂單資料表(1) & ".大底,
  33. " & 訂單資料表(1) & ".跟, " & 訂單資料表(1) & ".包裝確認時間 AS 包裝, " & 訂單資料表(1) & ".裁斷時間 AS 裁斷, " & 訂單資料表(1) & ".針車時間 AS 針車,
  34. " & 訂單資料表(1) & ".成型時間 AS 成型, " & 訂單資料表(1) & ".驗貨時間 AS 驗貨, " & 訂單資料表(1) & ".工廠進度表備註1, " & 訂單資料表(1) & ".工廠進度表備註2,
  35. " & 訂單資料表(1) & ".客戶包裝確認, " & 訂單資料表(1) & ".東莞業務備註, " & 訂單資料表(1) & ".工廠確認, " & 訂單資料表(1) & ".利威確認,
  36. " & 訂單資料表(1) & ".結關日, " & 訂單資料表(1) & ".SMS簽回, " & 訂單資料表(1) & ".FRS簽回, " & 訂單資料表(1) & ".MASTER_SWATCH, " & 訂單資料表(1) & ".力威訂單號,
  37. " & 訂單資料表(1) & ".ProductID, " & 訂單資料表(1) & ".UoM, " & 訂單資料表(2) & ".HS, " & 訂單資料表(0) & ".CustomerName
  38. FROM " & 訂單資料表(1) & " LEFT OUTER JOIN " & 訂單資料表(0) & " ON " & 訂單資料表(1) & ".訂單流水號 = " & 訂單資料表(0) & ".天盾流水號 LEFT OUTER JOIN
  39. " & 訂單資料表(2) & " ON " & 訂單資料表(1) & ".顏色 = " & 訂單資料表(2) & ".Colorway AND
  40. " & 訂單資料表(1) & ".ProductID = " & 訂單資料表(2) & ".ProductID AND " & 訂單資料表(1) & ".訂單流水號 = " & 訂單資料表(2) & ".天盾流水號 AND
  41. " & 訂單資料表(1) & ".客戶訂單號 = " & 訂單資料表(2) & ".客戶訂單號"
  42. ReadOnly SQL字串2 As String = " GROUP BY " & 訂單資料表(1) & ".訂單流水號, " & 訂單資料表(1) & ".年份季度, " & 訂單資料表(1) & ".客戶訂單號, " & 訂單資料表(1) & ".形體號, " & 訂單資料表(1) & ".顏色,
  43. " & 訂單資料表(1) & ".楦型, " & 訂單資料表(1) & ".訂單數量, " & 訂單資料表(1) & ".客戶交期, " & 訂單資料表(1) & ".單價, " & 訂單資料表(1) & ".總金額,
  44. " & 訂單資料表(1) & ".備註, " & 訂單資料表(1) & ".生產工廠, " & 訂單資料表(1) & ".訂單種類, " & 訂單資料表(1) & ".工廠回復交期, " & 訂單資料表(1) & ".CFMSPEC,
  45. " & 訂單資料表(1) & ".CFMSAMPLE, " & 訂單資料表(1) & ".TRIAL1, " & 訂單資料表(1) & ".TRIAL2, " & 訂單資料表(1) & ".TRIAL3, " & 訂單資料表(1) & ".TRIAL4,
  46. " & 訂單資料表(1) & ".包裝確認時間, " & 訂單資料表(1) & ".貼標時間, " & 訂單資料表(1) & ".裁斷時間, " & 訂單資料表(1) & ".針車時間,
  47. " & 訂單資料表(1) & ".成型時間, " & 訂單資料表(1) & ".驗貨時間, " & 訂單資料表(1) & ".實際離廠日, " & 訂單資料表(1) & ".資料流水號,
  48. " & 訂單資料表(1) & ".明細建檔, " & 訂單資料表(1) & ".GOODBOX, " & 訂單資料表(1) & ".LEATHER, " & 訂單資料表(1) & ".LEA_Note, " & 訂單資料表(1) & ".出貨數量,
  49. " & 訂單資料表(1) & ".PO_S_Date, " & 訂單資料表(1) & ".Requested_XF, " & 訂單資料表(1) & ".Confirm_XF, " & 訂單資料表(1) & ".Revised_XF,
  50. " & 訂單資料表(1) & ".工廠回復交期, " & 訂單資料表(1) & ".Special_Packaging, " & 訂單資料表(1) & ".Remarks, " & 訂單資料表(1) & ".出貨地,
  51. " & 訂單資料表(1) & ".TVW, " & 訂單資料表(1) & ".楦頭號, " & 訂單資料表(1) & ".材質, " & 訂單資料表(1) & ".七號模具, " & 訂單資料表(1) & ".TRIAL1,
  52. " & 訂單資料表(1) & ".TRIAL2, " & 訂單資料表(1) & ".長期試穿, " & 訂單資料表(1) & ".CFMSAMPLE, " & 訂單資料表(1) & ".TRIAL3, " & 訂單資料表(1) & ".TRIAL4,
  53. " & 訂單資料表(1) & ".CFMSPEC, " & 訂單資料表(1) & ".面料, " & 訂單資料表(1) & ".副料, " & 訂單資料表(1) & ".中底, " & 訂單資料表(1) & ".鞋墊,
  54. " & 訂單資料表(1) & ".大底, " & 訂單資料表(1) & ".跟, " & 訂單資料表(1) & ".包裝確認時間, " & 訂單資料表(1) & ".裁斷時間, " & 訂單資料表(1) & ".針車時間,
  55. " & 訂單資料表(1) & ".成型時間, " & 訂單資料表(1) & ".驗貨時間, " & 訂單資料表(1) & ".工廠進度表備註1, " & 訂單資料表(1) & ".工廠進度表備註2,
  56. " & 訂單資料表(1) & ".客戶包裝確認, " & 訂單資料表(1) & ".東莞業務備註, " & 訂單資料表(1) & ".工廠確認, " & 訂單資料表(1) & ".利威確認,
  57. " & 訂單資料表(1) & ".結關日, " & 訂單資料表(1) & ".SMS簽回, " & 訂單資料表(1) & ".FRS簽回, " & 訂單資料表(1) & ".MASTER_SWATCH,
  58. " & 訂單資料表(1) & ".力威訂單號, " & 訂單資料表(1) & ".ProductID, " & 訂單資料表(1) & ".UoM, " & 訂單資料表(2) & ".HS,
  59. " & 訂單資料表(0) & ".CustomerName
  60. ORDER BY SUBSTRING(" & 訂單資料表(1) & ".訂單流水號, 4, 6) DESC"
  61. Private Sub Set_DGV1載入前設定()
  62. DataGridView1.DataSource = Nothing : ds.Clear()
  63. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  64. DataGridView1.ColumnHeadersHeight = 25
  65. DataGridView1.AllowUserToAddRows = False
  66. ConnOpen()
  67. End Sub
  68. Private Sub Set_DGV1載入後設定()
  69. CmdSet_For_DGV() : da.SelectCommand.CommandTimeout = 900 : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  70. End Sub
  71. Private Sub Set_訂單清單()
  72. Set_DGV1載入前設定()
  73. If OPEXC(0) = True Then
  74. SQL1 = SQL字串1 & 列印用SQL & "AND (" & 訂單資料表(1) & ".生產工廠 LIKE 'JH')" & SQL字串2
  75. ElseIf OPEXC(1) = True Then
  76. SQL1 = SQL字串1 & 列印用SQL & "AND (" & 訂單資料表(1) & ".生產工廠 LIKE 'SK')" & SQL字串2
  77. ElseIf OPEXC(2) = True Then
  78. SQL1 = SQL字串1 & 列印用SQL & "AND (" & 訂單資料表(1) & ".生產工廠 LIKE 'NJ')" & SQL字串2
  79. End If
  80. Set_DGV1載入後設定()
  81. End Sub
  82. Private Sub Set_格式設定()
  83. DataGridView1.Visible = True
  84. If CC(7) = False Then
  85. CheckBox9.Visible = False : Label9.Visible = False : CheckBox10.Visible = False : Label10.Visible = False
  86. End If
  87. End Sub
  88. Private Sub Set_循環列印()
  89. Dim W As Integer = 2
  90. If CheckBox1.Checked = True Then : xlSheet.Cells(3, W) = "TENDENZA PO#" : Q = W : W += 1 : End If
  91. If CheckBox2.Checked = True Then : xlSheet.Cells(3, W) = "SEASON" : Q = W : W += 1 : End If
  92. If CheckBox3.Checked = True Then : xlSheet.Cells(3, W) = "VIONIC PO#" : Q = W : W += 1 : End If
  93. If CheckBox4.Checked = True Then : xlSheet.Cells(3, W) = "STYLE" : Q = W : W += 1 : End If
  94. If CheckBox5.Checked = True Then : xlSheet.Cells(3, W) = "COLOR" : Q = W : W += 1 : End If
  95. If CheckBox6.Checked = True Then : xlSheet.Cells(3, W) = "DM" : Q = W : W += 1 : End If
  96. If CheckBox7.Checked = True Then : xlSheet.Cells(3, W) = "PRS" : Q = W : W += 1 : Index_PRS = Q : End If
  97. If CheckBox8.Checked = True Then : xlSheet.Cells(3, W) = "CUST X/F" : Q = W : W += 1 : End If
  98. If CheckBox9.Checked = True Then : xlSheet.Cells(3, W) = "PRICE" : Q = W : W += 1 : End If
  99. If CheckBox10.Checked = True Then : xlSheet.Cells(3, W) = "AMOUNT" : Q = W : W += 1 : End If
  100. If CheckBox11.Checked = True Then : xlSheet.Cells(3, W) = "REMARK" : Q = W : W += 1 : End If
  101. If CheckBox12.Checked = True Then : xlSheet.Cells(3, W) = "FTY" : Q = W : W += 1 : End If
  102. If CheckBox13.Checked = True Then : xlSheet.Cells(3, W) = "DIV" : Q = W : W += 1 : End If
  103. If CheckBox14.Checked = True Then : xlSheet.Cells(3, W) = "GOODBOX" : Q = W : W += 1 : End If
  104. If CheckBox15.Checked = True Then : xlSheet.Cells(3, W) = "LEATHER" : Q = W : W += 1 : End If
  105. If CheckBox16.Checked = True Then : xlSheet.Cells(3, W) = "LEA_Note" : Q = W : W += 1 : End If
  106. If CheckBox17.Checked = True Then : xlSheet.Cells(3, W) = "PO_S_Date" : Q = W : W += 1 : End If
  107. If CheckBox18.Checked = True Then : xlSheet.Cells(3, W) = "Requested_XF" : Q = W : W += 1 : End If
  108. If CheckBox19.Checked = True Then : xlSheet.Cells(3, W) = "Confirm_XF" : Q = W : W += 1 : End If
  109. If CheckBox20.Checked = True Then : xlSheet.Cells(3, W) = "Revised_XF" : Q = W : W += 1 : End If
  110. If CheckBox21.Checked = True Then : xlSheet.Cells(3, W) = "FTY X/F" : Q = W : W += 1 : Index_FTY_XF = Q : End If
  111. If CheckBox22.Checked = True Then : xlSheet.Cells(3, W) = "Special_Packaging" : Q = W : W += 1 : End If
  112. If CheckBox23.Checked = True Then : xlSheet.Cells(3, W) = "Remarks" : Q = W : W += 1 : End If
  113. If CheckBox24.Checked = True Then : xlSheet.Cells(3, W) = "TVW" : Q = W : W += 1 : End If
  114. If CheckBox25.Checked = True Then : xlSheet.Cells(3, W) = "楦頭號" : Q = W : W += 1 : End If
  115. If CheckBox26.Checked = True Then : xlSheet.Cells(3, W) = "材質" : Q = W : W += 1 : End If
  116. If CheckBox27.Checked = True Then : xlSheet.Cells(3, W) = "七號模具" : Q = W : W += 1 : End If
  117. If CheckBox28.Checked = True Then : xlSheet.Cells(3, W) = "T1" : Q = W : W += 1 : End If
  118. If CheckBox29.Checked = True Then : xlSheet.Cells(3, W) = "T2" : Q = W : W += 1 : End If
  119. If CheckBox30.Checked = True Then : xlSheet.Cells(3, W) = "WEAR_TEST" : Q = W : W += 1 : End If
  120. If CheckBox31.Checked = True Then : xlSheet.Cells(3, W) = "CFM" : Q = W : W += 1 : End If
  121. If CheckBox32.Checked = True Then : xlSheet.Cells(3, W) = "T3" : Q = W : W += 1 : End If
  122. If CheckBox33.Checked = True Then : xlSheet.Cells(3, W) = "T4" : Q = W : W += 1 : End If
  123. If CheckBox34.Checked = True Then : xlSheet.Cells(3, W) = "TEST" : Q = W : W += 1 : End If
  124. If CheckBox35.Checked = True Then : xlSheet.Cells(3, W) = "面料" : Q = W : W += 1 : End If
  125. If CheckBox36.Checked = True Then : xlSheet.Cells(3, W) = "副料" : Q = W : W += 1 : End If
  126. If CheckBox37.Checked = True Then : xlSheet.Cells(3, W) = "中底" : Q = W : W += 1 : End If
  127. If CheckBox38.Checked = True Then : xlSheet.Cells(3, W) = "鞋墊" : Q = W : W += 1 : End If
  128. If CheckBox39.Checked = True Then : xlSheet.Cells(3, W) = "大底" : Q = W : W += 1 : End If
  129. If CheckBox40.Checked = True Then : xlSheet.Cells(3, W) = "跟" : Q = W : W += 1 : End If
  130. If CheckBox41.Checked = True Then : xlSheet.Cells(3, W) = "包裝" : Q = W : W += 1 : End If
  131. If CheckBox42.Checked = True Then : xlSheet.Cells(3, W) = "裁斷" : Q = W : W += 1 : End If
  132. If CheckBox43.Checked = True Then : xlSheet.Cells(3, W) = "針車" : Q = W : W += 1 : End If
  133. If CheckBox44.Checked = True Then : xlSheet.Cells(3, W) = "成型" : Q = W : W += 1 : End If
  134. If CheckBox45.Checked = True Then : xlSheet.Cells(3, W) = "驗貨" : Q = W : W += 1 : End If
  135. If CheckBox46.Checked = True Then : xlSheet.Cells(3, W) = "工廠進度表備註1" : Q = W : W += 1 : End If
  136. If CheckBox47.Checked = True Then : xlSheet.Cells(3, W) = "工廠進度表備註2" : Q = W : W += 1 : End If
  137. If CheckBox48.Checked = True Then : xlSheet.Cells(3, W) = "客戶包裝確認" : Q = W : W += 1 : End If
  138. If CheckBox50.Checked = True Then : xlSheet.Cells(3, W) = "工廠包裝確認" : Q = W : W += 1 : End If
  139. If CheckBox51.Checked = True Then : xlSheet.Cells(3, W) = "利威驗貨確認" : Q = W : W += 1 : End If
  140. If CheckBox52.Checked = True Then : xlSheet.Cells(3, W) = "結關日" : Q = W : W += 1 : End If
  141. If CheckBox53.Checked = True Then : xlSheet.Cells(3, W) = "SMS簽回" : Q = W : W += 1 : End If
  142. If CheckBox54.Checked = True Then : xlSheet.Cells(3, W) = "FRS簽回" : Q = W : W += 1 : End If
  143. If CheckBox55.Checked = True Then : xlSheet.Cells(3, W) = "MASTER SWATCH" : Q = W : W += 1 : End If
  144. If CheckBox56.Checked = True Then : xlSheet.Cells(3, W) = "力威訂單號" : Q = W : W += 1 : End If
  145. If CheckBox57.Checked = True Then : xlSheet.Cells(3, W) = "ProductID" : Q = W : W += 1 : End If
  146. If CheckBox58.Checked = True Then : xlSheet.Cells(3, W) = "UoM" : Q = W : W += 1 : End If
  147. If CheckBox59.Checked = True Then : xlSheet.Cells(3, W) = "HS#" : Q = W : W += 1 : End If
  148. If CheckBox60.Checked = True Then : xlSheet.Cells(3, W) = "Company Code" : Q = W : W += 1 : End If
  149. If CheckBox49.Checked = True Then : xlSheet.Cells(3, W) = "東莞業務備註" : Q = W : W += 1 : End If
  150. Set_訂單清單()
  151. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  152. W = 2
  153. If CheckBox1.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("訂單流水號").Value : W += 1 : End If
  154. If CheckBox2.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("年份季度").Value : W += 1 : End If
  155. If CheckBox3.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("客戶訂單號").Value : W += 1 : End If
  156. If CheckBox4.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("形體號").Value : W += 1 : End If
  157. If CheckBox5.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("顏色").Value : W += 1 : End If
  158. If CheckBox6.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("楦型").Value : W += 1 : End If
  159. If CheckBox7.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("訂單數量").Value : P = W : W += 1 : End If
  160. If CheckBox8.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("客戶交期").Value : W += 1 : End If
  161. If CheckBox9.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("單價").Value : R = W : W += 1 : End If
  162. If CheckBox10.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("總金額").Value : A = W : W += 1 : End If
  163. If CheckBox11.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("備註").Value : W += 1 : End If
  164. If CheckBox12.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("生產工廠").Value : W += 1 : End If
  165. If CheckBox13.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("訂單種類").Value : W += 1 : End If
  166. If CheckBox14.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("GOODBOX").Value : W += 1 : End If
  167. If CheckBox15.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("LEATHER").Value : W += 1 : End If
  168. If CheckBox16.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("LEA_Note").Value : W += 1 : End If
  169. If CheckBox17.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("接單日").Value : W += 1 : End If
  170. If CheckBox18.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("需求日期").Value : W += 1 : End If
  171. If CheckBox19.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("確認日期").Value : W += 1 : End If
  172. If CheckBox20.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("修訂日期").Value : W += 1 : End If
  173. If CheckBox21.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("工廠交期").Value : W += 1 : End If
  174. If CheckBox22.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("Special_Packaging").Value : W += 1 : End If
  175. If CheckBox23.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("Remarks").Value : W += 1 : End If
  176. If CheckBox24.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("TVW").Value : W += 1 : End If
  177. If CheckBox25.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("楦頭號").Value : W += 1 : End If
  178. If CheckBox26.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("材質").Value : W += 1 : End If
  179. If CheckBox27.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("七號模具").Value : W += 1 : End If
  180. If CheckBox28.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("T1").Value : W += 1 : End If
  181. If CheckBox29.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("T2").Value : W += 1 : End If
  182. If CheckBox30.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("WEAR_TEST").Value : W += 1 : End If
  183. If CheckBox31.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("CFM").Value : W += 1 : End If
  184. If CheckBox32.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("T3").Value : W += 1 : End If
  185. If CheckBox33.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("T4").Value : W += 1 : End If
  186. If CheckBox34.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("TEST").Value : W += 1 : End If
  187. If CheckBox35.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("面料").Value : W += 1 : End If
  188. If CheckBox36.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("副料").Value : W += 1 : End If
  189. If CheckBox37.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("中底").Value : W += 1 : End If
  190. If CheckBox38.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("鞋墊").Value : W += 1 : End If
  191. If CheckBox39.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("大底").Value : W += 1 : End If
  192. If CheckBox40.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("跟").Value : W += 1 : End If
  193. If CheckBox41.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("包裝").Value : W += 1 : End If
  194. If CheckBox42.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("裁斷").Value : W += 1 : End If
  195. If CheckBox43.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("針車").Value : W += 1 : End If
  196. If CheckBox44.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("成型").Value : W += 1 : End If
  197. If CheckBox45.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("驗貨").Value : W += 1 : End If
  198. If CheckBox46.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("工廠進度表備註1").Value : W += 1 : End If
  199. If CheckBox47.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("工廠進度表備註2").Value : W += 1 : End If
  200. If CheckBox48.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("客戶包裝確認").Value : W += 1 : End If
  201. If CheckBox50.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("工廠確認").Value : W += 1 : End If
  202. If CheckBox51.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("利威確認").Value : W += 1 : End If
  203. If CheckBox52.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("結關日").Value : W += 1 : End If
  204. If CheckBox53.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("SMS簽回").Value : W += 1 : End If
  205. If CheckBox54.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("FRS簽回").Value : W += 1 : End If
  206. If CheckBox55.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("MASTER_SWATCH").Value : W += 1 : End If
  207. If CheckBox56.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("力威訂單號").Value : W += 1 : End If
  208. If CheckBox57.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("ProductID").Value : W += 1 : End If
  209. If CheckBox58.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("UoM").Value : W += 1 : End If
  210. If CheckBox59.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("HS").Value : W += 1 : End If
  211. If CheckBox59.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("CustomerName").Value : W += 1 : End If
  212. If CheckBox49.Checked = True Then : xlSheet.Cells(i + 4, W) = DataGridView1.Rows(i).Cells("東莞業務備註").Value : W += 1 : End If
  213. With xlApp.Selection
  214. .Font.Bold = True
  215. End With
  216. Next i
  217. BB(xlApp, xlSheet)
  218. End Sub
  219. Private Sub 列印選擇_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  220. FormBorderStyle = FormBorderStyle.SizableToolWindow
  221. 月選_起始_dtp.Value = Today() : 月選_結束_dtp.Value = Today()
  222. 週選_日期_CB.Text = DateAndTime.Day(Today)
  223. 週選_月份_CB.Text = DateAndTime.Month(Today)
  224. 週選_年份_CB.Text = DateAndTime.Year(Today)
  225. 週選_週數_cb.Text = "7"
  226. 月選_起始月_cb.Text = DateAndTime.Month(Today)
  227. 月選_結束月_cb.Text = DateAndTime.Month(Today)
  228. 月選_年_cb.Text = DateAndTime.Year(Today)
  229. 月選_結束年_cb.Text = DateAndTime.Year(Today)
  230. Set_格式設定()
  231. End Sub
  232. Private Sub 週選_年份_CB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 週選_年份_CB.SelectedIndexChanged
  233. selectdate = CDate((週選_月份_CB.Text) & "/" & (週選_日期_CB.Text) & "/" & (週選_年份_CB.Text))
  234. 週選_DTP.Value = selectdate
  235. 週選_起日_tb.Text = Strings.Left(Strings.Format(週選_DTP.Value, "yyyy/MM/dd"), 10)
  236. End Sub
  237. Private Sub 週選_月份_CB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 週選_月份_CB.SelectedIndexChanged
  238. If 週選_年份_CB.Text = "" Then
  239. Exit Sub
  240. Else
  241. selectdate = CDate((週選_月份_CB.Text) & "/" & (週選_日期_CB.Text) & "/" & (週選_年份_CB.Text))
  242. 週選_DTP.Value = selectdate
  243. 週選_起日_tb.Text = Strings.Left(Strings.Format(週選_DTP.Value, "yyyy/MM/dd"), 10)
  244. End If
  245. End Sub
  246. Private Sub 週選_日期_CB_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 週選_日期_CB.SelectedIndexChanged
  247. If 週選_年份_CB.Text = "" Then
  248. Exit Sub
  249. ElseIf 週選_月份_CB.Text = "" Then
  250. Exit Sub
  251. Else
  252. selectdate = CDate((週選_月份_CB.Text) & "/" & (週選_日期_CB.Text) & "/" & (週選_年份_CB.Text))
  253. 週選_DTP.Value = selectdate
  254. 週選_起日_tb.Text = Strings.Left(Strings.Format(週選_DTP.Value, "yyyy/MM/dd"), 10)
  255. End If
  256. End Sub
  257. Private Sub 月選_年_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_年_cb.SelectedIndexChanged
  258. DTP = (月選_年_cb.Text) & "/" & (月選_起始月_cb.Text) & "/01"
  259. 月選_起始_dtp.Value = DTP
  260. 月選_起始_tb.Text = Strings.Left(Strings.Format(月選_起始_dtp.Value, "yyyy/MM/dd"), 10)
  261. 判斷月差()
  262. End Sub
  263. Private Sub 月選_起始月_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_起始月_cb.SelectedIndexChanged
  264. If 月選_年_cb.Text = "" Then
  265. Exit Sub
  266. Else
  267. DTP = (月選_年_cb.Text) & "/" & (月選_起始月_cb.Text) & "/01"
  268. 月選_起始_dtp.Value = DTP
  269. 月選_起始_tb.Text = Strings.Left(Strings.Format(月選_起始_dtp.Value, "yyyy/MM/dd"), 10)
  270. End If
  271. 判斷月差()
  272. End Sub
  273. Private Sub 月選_結束年_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_結束年_cb.SelectedIndexChanged
  274. DTP = (月選_結束年_cb.Text) & "/" & (月選_結束月_cb.Text) & "/01"
  275. 月選_結束_dtp.Value = DTP
  276. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddMonths(1)
  277. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddDays(-1)
  278. 月選_結束_tb.Text = Strings.Left(Strings.Format(月選_結束_dtp.Value, "yyyy/MM/dd"), 10)
  279. End Sub
  280. Private Sub 月選_結束月_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_結束月_cb.SelectedIndexChanged
  281. If 月選_年_cb.Text = "" Then
  282. Exit Sub
  283. Else
  284. DTP = (月選_結束年_cb.Text) & "/" & (月選_結束月_cb.Text) & "/01"
  285. 月選_結束_dtp.Value = DTP
  286. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddMonths(1)
  287. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddDays(-1)
  288. 月選_結束_tb.Text = Strings.Left(Strings.Format(月選_結束_dtp.Value, "yyyy/MM/dd"), 10)
  289. End If
  290. End Sub
  291. Private Sub 減一個月_bt_Click(sender As Object, e As EventArgs) Handles 減一個月_bt.Click
  292. If 月選_結束月_cb.Text <> "1" Then
  293. 月選_結束月_cb.Text = Val(月選_結束月_cb.Text) - 1
  294. ElseIf 月選_結束月_cb.Text = "1" Then
  295. 月選_結束月_cb.Text = 12
  296. 月選_結束年_cb.Text = Val(月選_結束年_cb.Text) - 1
  297. End If
  298. 判斷月差()
  299. End Sub
  300. Private Sub 加一個月_bt_Click(sender As Object, e As EventArgs) Handles 加一個月_bt.Click
  301. If 月選_結束月_cb.Text <> "12" Then
  302. 月選_結束月_cb.Text = Val(月選_結束月_cb.Text) + 1
  303. ElseIf 月選_結束月_cb.Text = "12" Then
  304. 月選_結束月_cb.Text = 1
  305. 月選_結束年_cb.Text = Val(月選_結束年_cb.Text) + 1
  306. End If
  307. 判斷月差()
  308. End Sub
  309. Private Sub 判斷月差()
  310. If DateDiff(DateInterval.Month, 月選_起始_dtp.Value, 月選_結束_dtp.Value) > 11 Then
  311. 月選_起始月_cb.Text = DateAndTime.Month(Today)
  312. 月選_結束月_cb.Text = DateAndTime.Month(Today)
  313. 月選_年_cb.Text = DateAndTime.Year(Today)
  314. 月選_結束年_cb.Text = DateAndTime.Year(Today)
  315. MsgBox("選擇範圍超過1年", MsgBoxStyle.Information, "提示")
  316. ElseIf DateDiff(DateInterval.Month, 月選_起始_dtp.Value, 月選_結束_dtp.Value) < 0 Then
  317. 月選_起始月_cb.Text = DateAndTime.Month(Today)
  318. 月選_結束月_cb.Text = DateAndTime.Month(Today)
  319. 月選_年_cb.Text = DateAndTime.Year(Today)
  320. 月選_結束年_cb.Text = DateAndTime.Year(Today)
  321. MsgBox("選擇範圍年分順序顛倒", MsgBoxStyle.Information, "提示")
  322. End If
  323. End Sub
  324. Private Sub 彙總表_cb_CheckedChanged(sender As Object, e As EventArgs) Handles 彙總表_cb.CheckedChanged
  325. If 彙總表_cb.Checked = True Then
  326. If CheckBox21.Checked = False Then
  327. MsgBox("列印彙總表需要工廠交期,請勾選 FTY X/F", MsgBoxStyle.Information, "提示")
  328. 彙總表_cb.Checked = False
  329. ElseIf CheckBox7.Checked = False Then
  330. MsgBox("列印彙總表需要PRS,請勾選 PRS", MsgBoxStyle.Information, "提示")
  331. 彙總表_cb.Checked = False
  332. Else
  333. 彙總表_cb.Checked = True : 月份選擇_gb.Enabled = True : 週數選擇_gb.Enabled = True
  334. End If
  335. Else
  336. 月份選擇_gb.Enabled = False : 週數選擇_gb.Enabled = False
  337. Exit Sub
  338. End If
  339. End Sub
  340. Private Function 行指標轉換(ByVal index01 As Integer) As String
  341. Dim index_return As String = ""
  342. Select Case index01
  343. Case 1 : index_return = "A" : Case 2 : index_return = "B" : Case 3 : index_return = "C" : Case 4 : index_return = "D"
  344. Case 5 : index_return = "E" : Case 6 : index_return = "F" : Case 7 : index_return = "G" : Case 8 : index_return = "H"
  345. Case 9 : index_return = "I" : Case 10 : index_return = "J" : Case 11 : index_return = "K" : Case 12 : index_return = "L"
  346. Case 13 : index_return = "M" : Case 14 : index_return = "N" : Case 15 : index_return = "O" : Case 16 : index_return = "P"
  347. Case 17 : index_return = "Q" : Case 18 : index_return = "R" : Case 19 : index_return = "S" : Case 20 : index_return = "T"
  348. Case 21 : index_return = "U" : Case 22 : index_return = "V" : Case 23 : index_return = "W" : Case 24 : index_return = "X"
  349. Case 25 : index_return = "Y" : Case 26 : index_return = "Z" : Case 27 : index_return = "AA" : Case 28 : index_return = "AB"
  350. Case 29 : index_return = "AC" : Case 30 : index_return = "AD" : Case 31 : index_return = "AE" : Case 32 : index_return = "AF"
  351. Case 33 : index_return = "AG" : Case 34 : index_return = "AH" : Case 35 : index_return = "AI" : Case 36 : index_return = "AJ"
  352. Case 37 : index_return = "AK" : Case 38 : index_return = "AL" : Case 39 : index_return = "AM" : Case 40 : index_return = "AN"
  353. End Select
  354. Return index_return
  355. End Function
  356. Private Sub 週選_週數_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 週選_週數_cb.SelectedIndexChanged
  357. 週選_週數_tb.Text = 週選_週數_cb.Text
  358. End Sub
  359. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  360. Dim j As Integer = 1
  361. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  362. xlApp.Visible = True
  363. xlApp.DisplayAlerts = True
  364. xlApp.Application.WindowState = xlMaximized
  365. xlBook = xlApp.Workbooks.Add
  366. '----------------------------------------------------------------------------------------------------------------------
  367. xlSheet = NewMethod(xlBook)
  368. xlApp.Sheets(1).Name = "JH"
  369. xlApp.Sheets("JH").Select
  370. xlBook.Activate()
  371. xlSheet.Activate()
  372. OPEXC(0) = True : OPEXC(1) = False : OPEXC(2) = False
  373. xlSheet.Range("A1").Select()
  374. xlSheet.Cells(2, 2) = "天盾國際有限公司-訂單控制表(玖宏)"
  375. Set_循環列印()
  376. j += 1
  377. '----------------------------------------------------------------------------------------------------------------------
  378. xlSheet = NewMethod(xlBook)
  379. xlApp.Sheets(1).Name = "SK"
  380. xlApp.Sheets("SK").Select
  381. xlBook.Activate()
  382. xlSheet.Activate()
  383. OPEXC(0) = False : OPEXC(1) = True : OPEXC(2) = False
  384. xlSheet.Range("A1").Select()
  385. xlSheet.Cells(2, 2) = "天盾國際有限公司-訂單控制表(森康)"
  386. Set_循環列印()
  387. j += 1
  388. '----------------------------------------------------------------------------------------------------------------------
  389. xlSheet = NewMethod(xlBook)
  390. xlApp.Sheets(1).Name = "NJ"
  391. xlApp.Sheets("NJ").Select
  392. xlBook.Activate()
  393. xlSheet.Activate()
  394. OPEXC(0) = False : OPEXC(1) = False : OPEXC(2) = True
  395. xlSheet.Range("A1").Select()
  396. xlSheet.Cells(2, 2) = "天盾國際有限公司-訂單控制表(楠晉)"
  397. Set_循環列印()
  398. j += 1
  399. '---------------------------------------------------cover--------------------------------------------------------------
  400. If 彙總表_cb.Checked = True Then
  401. xlSheet = NewMethod(xlBook)
  402. xlApp.Sheets(1).Name = "cover"
  403. xlApp.Sheets("cover").Select
  404. xlBook.Activate()
  405. xlSheet.Activate()
  406. xlSheet.Range("A1").Select()
  407. Dim Str_FTY_XF As String = 行指標轉換(Index_FTY_XF)
  408. Dim Str_PRS As String = 行指標轉換(Index_PRS)
  409. 'xlSheet.Cells(2, 2) = "天盾國際有限公司-訂單彙總表"
  410. xlSheet.Cells(3, 2) = "Year " & 月選_年_cb.Text : xlSheet.Cells(3, 9) = "Year " & 週選_年份_CB.Text
  411. xlSheet.Cells(3, 4) = "NJ" : xlSheet.Cells(3, 5) = "SK" : xlSheet.Cells(3, 6) = "JH" : xlSheet.Cells(3, 7) = "total"
  412. xlSheet.Cells(3, 11) = "NJ" : xlSheet.Cells(3, 12) = "SK" : xlSheet.Cells(3, 13) = "JH" : xlSheet.Cells(3, 14) = "total"
  413. xlSheet.Cells(4, 2) = 月選_起始_tb.Text
  414. xlSheet.Cells(4, 3) = "unship" : xlSheet.Cells(4, 9) = "unship"
  415. ' --------- 月次選表 ---------
  416. xlSheet.Cells(4, 4) = "=SUMIF(NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & "<" & """" & "&$B$4,NJ!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  417. xlSheet.Cells(4, 5) = "=SUMIF(SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & "<" & """" & "&$B$4,SK!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  418. xlSheet.Cells(4, 6) = "=SUMIF(JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & "<" & """" & "&$B$4,JH!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  419. xlSheet.Cells(4, 7) = "=SUM(D4:F4)"
  420. Dim count_month, count_year, Br As Integer
  421. Dim DTP2, DTP3 As Date
  422. DTP2 = 月選_起始_dtp.Value
  423. DTP3 = 月選_結束_dtp.Value
  424. Br = DateDiff(DateInterval.Month, DTP2, DTP3)
  425. count_month = 月選_起始_dtp.Value.Month
  426. count_year = 月選_起始_dtp.Value.Year
  427. For k = 1 To (Br + 1)
  428. xlSheet.Cells(k + 4, 3) = count_month
  429. xlSheet.Cells(k + 4, 2) = count_year
  430. xlSheet.Cells(k + 4, 4) = "=SUMPRODUCT((YEAR(NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)=$B" & k + 4 & ")*(MONTH(NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)=$C" & k + 4 & ")*NJ!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  431. xlSheet.Cells(k + 4, 5) = "=SUMPRODUCT((YEAR(SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)=$B" & k + 4 & ")*(MONTH(SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)=$C" & k + 4 & ")*SK!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  432. xlSheet.Cells(k + 4, 6) = "=SUMPRODUCT((YEAR(JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)=$B" & k + 4 & ")*(MONTH(JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)=$C" & k + 4 & ")*JH!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  433. xlSheet.Cells(k + 4, 7) = "=SUM(D" & k + 4 & ":F" & k + 4 & ")"
  434. DTP2 = DTP2.AddMonths(1)
  435. count_month = DTP2.Month
  436. count_year = DTP2.Year
  437. If k = (Br + 1) Then
  438. xlSheet.Cells(k + 5, 2) = Strings.Left(Strings.Format(DTP3, "yyyy/MM/dd"), 10)
  439. xlSheet.Cells(k + 5, 3) = "later"
  440. xlSheet.Cells(k + 5, 4) = "=SUMIF(NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & ">" & """" & "&$B$" & k + 5 & ",NJ!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  441. xlSheet.Cells(k + 5, 5) = "=SUMIF(SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & ">" & """" & "&$B$" & k + 5 & ",SK!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  442. xlSheet.Cells(k + 5, 6) = "=SUMIF(JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & ">" & """" & "&$B$" & k + 5 & ",JH!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  443. xlSheet.Cells(k + 5, 7) = "=SUM(D" & k + 5 & ":F" & k + 5 & ")"
  444. xlSheet.Cells(k + 6, 2) = "total"
  445. xlSheet.Cells(k + 6, 4) = "=SUM(D4:D" & k + 5 & ")"
  446. xlSheet.Cells(k + 6, 5) = "=SUM(E4:E" & k + 5 & ")"
  447. xlSheet.Cells(k + 6, 6) = "=SUM(F4:F" & k + 5 & ")"
  448. xlSheet.Cells(k + 6, 7) = "=SUM(D" & k + 6 & ":F" & k + 6 & ")"
  449. End If
  450. Index_月_total = k + 6
  451. Next
  452. ' --------- 週次選表 ---------
  453. xlSheet.Cells(4, 11) = "=SUMIF(NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & "<" & """" & "&$I$5,NJ!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  454. xlSheet.Cells(4, 12) = "=SUMIF(SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & "<" & """" & "&$I$5,SK!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  455. xlSheet.Cells(4, 13) = "=SUMIF(JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & "<" & """" & "&$I$5,JH!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  456. xlSheet.Cells(4, 14) = "=SUM(K4:M4)"
  457. xlSheet.Cells(5, 9) = 週選_起日_tb.Text
  458. For kk = 1 To CInt(週選_週數_tb.Text)
  459. xlSheet.Cells(kk + 4, 10) = "=I" & (kk + 4) & "+6"
  460. xlSheet.Cells(kk + 4, 11) = "=SUMPRODUCT(((NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)>=$I" & kk + 4 & ")*((NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)<=$J" & kk + 4 & ")*NJ!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  461. xlSheet.Cells(kk + 4, 12) = "=SUMPRODUCT(((SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)>=$I" & kk + 4 & ")*((SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)<=$J" & kk + 4 & ")*SK!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  462. xlSheet.Cells(kk + 4, 13) = "=SUMPRODUCT(((JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)>=$I" & kk + 4 & ")*((JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999)<=$J" & kk + 4 & ")*JH!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  463. xlSheet.Cells(kk + 4, 14) = "=SUM(K" & kk + 4 & ":M" & kk + 4 & ")"
  464. If kk > 1 Then
  465. xlSheet.Cells(kk + 4, 9) = "=J" & (kk + 3) & "+1"
  466. End If
  467. If kk = CInt(週選_週數_tb.Text) Then
  468. xlSheet.Cells(kk + 5, 9) = "later"
  469. xlSheet.Cells(kk + 5, 11) = "=SUMIF(NJ!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & ">" & """" & "&$J$" & kk + 4 & ",NJ!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  470. xlSheet.Cells(kk + 5, 12) = "=SUMIF(SK!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & ">" & """" & "&$J$" & kk + 4 & ",SK!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  471. xlSheet.Cells(kk + 5, 13) = "=SUMIF(JH!$" & Str_FTY_XF & "$4:$" & Str_FTY_XF & "$9999," & """" & ">" & """" & "&$J$" & kk + 4 & ",JH!$" & Str_PRS & "$4:$" & Str_PRS & "$9999)"
  472. xlSheet.Cells(kk + 5, 14) = "=SUM(K" & kk + 5 & ":M" & kk + 5 & ")"
  473. xlSheet.Cells(kk + 6, 9) = "total"
  474. xlSheet.Cells(kk + 6, 11) = "=SUM(K4:K" & kk + 5 & ")"
  475. xlSheet.Cells(kk + 6, 12) = "=SUM(L4:L" & kk + 5 & ")"
  476. xlSheet.Cells(kk + 6, 13) = "=SUM(M4:M" & kk + 5 & ")"
  477. xlSheet.Cells(kk + 6, 14) = "=SUM(K" & kk + 6 & ":M" & kk + 6 & ")"
  478. End If
  479. Next
  480. Excel巨集_C(xlApp, xlSheet)
  481. j += 1
  482. End If
  483. '----------------------------------------------------------------------------------------------------------------------
  484. xlApp.Sheets(j).Delete
  485. xlSheet.PageSetup.PrintArea = ""
  486. xlApp.Cells.Select()
  487. xlApp.Application.WindowState = xlMinimized
  488. MsgBox("列印完成")
  489. Me.Close()
  490. End Sub
  491. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  492. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  493. End Function
  494. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  495. Dim 位置41 As String
  496. If CheckBox7.Checked = True Then
  497. If P = 0 Then
  498. Else
  499. If P = 2 Then : 位置1 = "B" : ElseIf P = 3 Then : 位置1 = "C" : ElseIf P = 4 Then : 位置1 = "D" : ElseIf P = 5 Then : 位置1 = "E" : ElseIf P = 6 Then : 位置1 = "F"
  500. ElseIf P = 7 Then : 位置1 = "G" : ElseIf P = 8 Then : 位置1 = "H" : ElseIf P = 9 Then : 位置1 = "I" : ElseIf P = 10 Then : 位置1 = "J" : ElseIf P = 11 Then : 位置1 = "K"
  501. ElseIf P = 12 Then : 位置1 = "L" : ElseIf P = 13 Then : 位置1 = "M" : ElseIf P = 14 Then : 位置1 = "N" : ElseIf P = 15 Then : 位置1 = "O" : ElseIf P = 16 Then : 位置1 = "P"
  502. ElseIf P = 17 Then : 位置1 = "Q" : ElseIf P = 18 Then : 位置1 = "R" : ElseIf P = 19 Then : 位置1 = "S" : ElseIf P = 20 Then : 位置1 = "T" : ElseIf P = 21 Then : 位置1 = "U"
  503. ElseIf P = 22 Then : 位置1 = "V" : ElseIf P = 23 Then : 位置1 = "W" : ElseIf P = 24 Then : 位置1 = "X" : ElseIf P = 25 Then : 位置1 = "Y" : ElseIf P = 26 Then : 位置1 = "Z"
  504. ElseIf P = 27 Then : 位置1 = "AA" : ElseIf P = 28 Then : 位置1 = "AB" : ElseIf P = 29 Then : 位置1 = "AC" : ElseIf P = 30 Then : 位置1 = "AD" : ElseIf P = 31 Then : 位置1 = "AE"
  505. ElseIf P = 32 Then : 位置1 = "AF" : ElseIf P = 33 Then : 位置1 = "AG" : ElseIf P = 34 Then : 位置1 = "AH" : ElseIf P = 35 Then : 位置1 = "AI" : ElseIf P = 36 Then : 位置1 = "AJ"
  506. ElseIf P = 37 Then : 位置1 = "AK" : ElseIf P = 38 Then : 位置1 = "AL" : ElseIf P = 39 Then : 位置1 = "AM" : ElseIf P = 40 Then : 位置1 = "AN" : ElseIf P = 41 Then : 位置1 = "AO"
  507. ElseIf P = 42 Then : 位置1 = "AP" : ElseIf P = 43 Then : 位置1 = "AQ" : ElseIf P = 44 Then : 位置1 = "AR" : ElseIf P = 45 Then : 位置1 = "AS" : ElseIf P = 46 Then : 位置1 = "AT"
  508. ElseIf P = 47 Then : 位置1 = "AU"
  509. End If
  510. 位置1 = 位置1 & "3" & ":" & 位置1 & "10000"
  511. xlSheet.Range(位置1).Select()
  512. myExcel.Selection.NumberFormatLocal = "#,##0"
  513. End If
  514. End If
  515. If CheckBox9.Checked = True Then
  516. If R = 2 Then : 位置2 = "B" : ElseIf R = 3 Then : 位置2 = "C" : ElseIf R = 4 Then : 位置2 = "D" : ElseIf R = 5 Then : 位置2 = "E" : ElseIf R = 6 Then : 位置2 = "F"
  517. ElseIf R = 7 Then : 位置2 = "G" : ElseIf R = 8 Then : 位置2 = "H" : ElseIf R = 9 Then : 位置2 = "I" : ElseIf R = 10 Then : 位置2 = "J" : ElseIf R = 11 Then : 位置2 = "K"
  518. ElseIf R = 12 Then : 位置2 = "L" : ElseIf R = 13 Then : 位置2 = "M" : ElseIf R = 14 Then : 位置2 = "N" : ElseIf R = 15 Then : 位置2 = "O" : ElseIf R = 16 Then : 位置2 = "P"
  519. ElseIf R = 17 Then : 位置2 = "Q" : ElseIf R = 18 Then : 位置2 = "R" : ElseIf R = 19 Then : 位置2 = "S" : ElseIf R = 20 Then : 位置2 = "T" : ElseIf R = 21 Then : 位置2 = "U"
  520. ElseIf R = 22 Then : 位置2 = "V" : ElseIf R = 23 Then : 位置2 = "W" : ElseIf R = 24 Then : 位置2 = "X" : ElseIf R = 25 Then : 位置2 = "Y" : ElseIf R = 26 Then : 位置2 = "Z"
  521. ElseIf R = 27 Then : 位置2 = "AA" : ElseIf R = 28 Then : 位置2 = "AB" : ElseIf R = 29 Then : 位置2 = "AC" : ElseIf R = 30 Then : 位置2 = "AD" : ElseIf R = 31 Then : 位置2 = "AE"
  522. ElseIf R = 32 Then : 位置2 = "AF" : ElseIf R = 33 Then : 位置2 = "AG" : ElseIf R = 34 Then : 位置2 = "AH" : ElseIf R = 35 Then : 位置2 = "AI" : ElseIf R = 36 Then : 位置2 = "AJ"
  523. ElseIf R = 37 Then : 位置2 = "AK" : ElseIf R = 38 Then : 位置2 = "AL" : ElseIf R = 39 Then : 位置2 = "AM" : ElseIf R = 40 Then : 位置2 = "AN" : ElseIf R = 41 Then : 位置2 = "AO"
  524. ElseIf R = 42 Then : 位置2 = "AP" : ElseIf R = 43 Then : 位置2 = "AQ" : ElseIf R = 44 Then : 位置2 = "AR" : ElseIf R = 45 Then : 位置2 = "AS" : ElseIf R = 46 Then : 位置2 = "AT"
  525. ElseIf R = 47 Then : 位置2 = "AU"
  526. End If
  527. 位置2 = 位置2 & "3" & ":" & 位置2 & "10000"
  528. xlSheet.Range(位置2).Select()
  529. myExcel.Selection.NumberFormatLocal = "#,##0.00"
  530. End If
  531. If CheckBox10.Checked = True Then
  532. If A = 2 Then : 位置3 = "B" : ElseIf A = 3 Then : 位置3 = "C" : ElseIf A = 4 Then : 位置3 = "D" : ElseIf A = 5 Then : 位置3 = "E" : ElseIf A = 6 Then : 位置3 = "F"
  533. ElseIf A = 7 Then : 位置3 = "G" : ElseIf A = 8 Then : 位置3 = "H" : ElseIf A = 9 Then : 位置3 = "I" : ElseIf A = 10 Then : 位置3 = "J" : ElseIf A = 11 Then : 位置3 = "K"
  534. ElseIf A = 12 Then : 位置3 = "L" : ElseIf A = 13 Then : 位置3 = "M" : ElseIf A = 14 Then : 位置3 = "N" : ElseIf A = 15 Then : 位置3 = "O" : ElseIf A = 16 Then : 位置3 = "P"
  535. ElseIf A = 17 Then : 位置3 = "Q" : ElseIf A = 18 Then : 位置3 = "R" : ElseIf A = 19 Then : 位置3 = "S" : ElseIf A = 20 Then : 位置3 = "T" : ElseIf A = 21 Then : 位置3 = "U"
  536. ElseIf A = 22 Then : 位置3 = "V" : ElseIf A = 23 Then : 位置3 = "W" : ElseIf A = 24 Then : 位置3 = "X" : ElseIf A = 25 Then : 位置3 = "Y" : ElseIf A = 26 Then : 位置3 = "Z"
  537. ElseIf A = 27 Then : 位置3 = "AA" : ElseIf A = 28 Then : 位置3 = "AB" : ElseIf A = 29 Then : 位置3 = "AC" : ElseIf A = 30 Then : 位置3 = "AD" : ElseIf A = 31 Then : 位置3 = "AE"
  538. ElseIf A = 32 Then : 位置3 = "AF" : ElseIf A = 33 Then : 位置3 = "AG" : ElseIf A = 34 Then : 位置3 = "AH" : ElseIf A = 35 Then : 位置3 = "AI" : ElseIf A = 36 Then : 位置3 = "AJ"
  539. ElseIf A = 37 Then : 位置3 = "AK" : ElseIf A = 38 Then : 位置3 = "AL" : ElseIf A = 39 Then : 位置3 = "AM" : ElseIf A = 40 Then : 位置3 = "AN" : ElseIf A = 41 Then : 位置3 = "AO"
  540. ElseIf A = 42 Then : 位置3 = "AP" : ElseIf A = 43 Then : 位置3 = "AQ" : ElseIf A = 44 Then : 位置3 = "AR" : ElseIf A = 45 Then : 位置3 = "AS" : ElseIf A = 46 Then : 位置3 = "AT"
  541. ElseIf A = 47 Then : 位置3 = "AU"
  542. End If
  543. 位置3 = 位置3 & "3" & ":" & 位置3 & "10000"
  544. xlSheet.Range(位置3).Select()
  545. myExcel.Selection.NumberFormatLocal = "#,##0.00"
  546. End If
  547. If Q = 2 Then : 位置4 = "B" : ElseIf Q = 3 Then : 位置4 = "C" : ElseIf Q = 4 Then : 位置4 = "D" : ElseIf Q = 5 Then : 位置4 = "E" : ElseIf Q = 6 Then : 位置4 = "F"
  548. ElseIf Q = 7 Then : 位置4 = "G" : ElseIf Q = 8 Then : 位置4 = "H" : ElseIf Q = 9 Then : 位置4 = "I" : ElseIf Q = 10 Then : 位置4 = "J" : ElseIf Q = 11 Then : 位置4 = "K"
  549. ElseIf Q = 12 Then : 位置4 = "L" : ElseIf Q = 13 Then : 位置4 = "M" : ElseIf Q = 14 Then : 位置4 = "N" : ElseIf Q = 15 Then : 位置4 = "O" : ElseIf Q = 16 Then : 位置4 = "P"
  550. ElseIf Q = 17 Then : 位置4 = "Q" : ElseIf Q = 18 Then : 位置4 = "R" : ElseIf Q = 19 Then : 位置4 = "S" : ElseIf Q = 20 Then : 位置4 = "T" : ElseIf Q = 21 Then : 位置4 = "U"
  551. ElseIf Q = 22 Then : 位置4 = "V" : ElseIf Q = 23 Then : 位置4 = "W" : ElseIf Q = 24 Then : 位置4 = "X" : ElseIf Q = 25 Then : 位置4 = "Y" : ElseIf Q = 26 Then : 位置4 = "Z"
  552. ElseIf Q = 27 Then : 位置4 = "AA" : ElseIf Q = 28 Then : 位置4 = "AB" : ElseIf Q = 29 Then : 位置4 = "AC" : ElseIf Q = 30 Then : 位置4 = "AD" : ElseIf Q = 31 Then : 位置4 = "AE"
  553. ElseIf Q = 32 Then : 位置4 = "AF" : ElseIf Q = 33 Then : 位置4 = "AG" : ElseIf Q = 34 Then : 位置4 = "AH" : ElseIf Q = 35 Then : 位置4 = "AI" : ElseIf Q = 36 Then : 位置4 = "AJ"
  554. ElseIf Q = 37 Then : 位置4 = "AK" : ElseIf Q = 38 Then : 位置4 = "AL" : ElseIf Q = 39 Then : 位置4 = "AM" : ElseIf Q = 40 Then : 位置4 = "AN" : ElseIf Q = 41 Then : 位置4 = "AO"
  555. ElseIf Q = 42 Then : 位置4 = "AP" : ElseIf Q = 43 Then : 位置4 = "AQ" : ElseIf Q = 44 Then : 位置4 = "AR" : ElseIf Q = 45 Then : 位置4 = "AS" : ElseIf Q = 46 Then : 位置4 = "AT"
  556. ElseIf Q = 47 Then : 位置4 = "AU"
  557. End If
  558. xlSheet.Columns("A:A").ColumnWidth = 1
  559. xlSheet.Range("B2:E2").Select()
  560. With myExcel.Selection
  561. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  562. .ReadingOrder = xlContext : .MergeCells = False
  563. End With
  564. myExcel.Selection.Merge
  565. xlSheet.Cells(2, 6) = "列印日期 : " : xlSheet.Range("F2:G2").Select()
  566. With myExcel.Selection
  567. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  568. .ReadingOrder = xlContext : .MergeCells = False
  569. End With
  570. myExcel.Selection.Merge
  571. xlSheet.Range("F2:G2").Select()
  572. With myExcel.Selection
  573. .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  574. .ReadingOrder = xlContext : .MergeCells = True
  575. End With
  576. xlSheet.Cells(2, 8) = String.Format("{0:d}", Now) : xlSheet.Range("H2:I2").Select()
  577. With myExcel.Selection
  578. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  579. .ReadingOrder = xlContext : .MergeCells = False
  580. End With
  581. myExcel.Selection.Merge
  582. xlSheet.Range("H2:I2").Select()
  583. xlSheet.Cells.Select()
  584. With myExcel.Selection.Font
  585. .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  586. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  587. End With
  588. xlSheet.Range("B2:I2").Select()
  589. With myExcel.Selection.Font
  590. .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  591. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  592. End With
  593. 位置41 = "B:" & 位置4
  594. xlSheet.Columns(位置41).Select : xlSheet.Columns(位置41).EntireColumn.AutoFit
  595. myExcel.ActiveWindow.ScrollColumn = 4 : myExcel.ActiveWindow.ScrollColumn = 3 : myExcel.ActiveWindow.ScrollColumn = 2 : myExcel.ActiveWindow.ScrollColumn = 1
  596. xlSheet.Rows("4:4").Select
  597. myExcel.ActiveWindow.FreezePanes = True
  598. xlSheet.Rows("3:3").Select
  599. myExcel.Selection.AutoFilter
  600. myExcel.ActiveWindow.ScrollColumn = 3 : myExcel.ActiveWindow.ScrollColumn = 2 : myExcel.ActiveWindow.ScrollColumn = 1
  601. xlSheet.Rows("3:3").Select
  602. With myExcel.Selection
  603. .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  604. .ReadingOrder = xlContext : .MergeCells = False
  605. End With
  606. If 位置4 = "A" Or 位置4 = "B" Or 位置4 = "C" Or 位置4 = "D" Or 位置4 = "E" Or 位置4 = "F" Or 位置4 = "G" Or 位置4 = "H" Or 位置4 = "I" Or 位置4 = "J" Then
  607. Else
  608. 位置41 = "J2:" & 位置4 & "2"
  609. xlSheet.Range(位置41).Select()
  610. With myExcel.Selection
  611. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  612. .ReadingOrder = xlContext : .MergeCells = False
  613. End With
  614. myExcel.Selection.Merge
  615. End If
  616. Dim M As Integer = 4
  617. For M = 4 To DataGridView1.Rows.Count + 2
  618. M += 1
  619. Next M
  620. If 位置4 = "A" Or 位置4 = "B" Or 位置4 = "C" Or 位置4 = "D" Or 位置4 = "E" Or 位置4 = "F" Or 位置4 = "G" Or 位置4 = "H" Or 位置4 = "I" Or 位置4 = "J" Then
  621. 位置4 = "J"
  622. 位置41 = "B2:" & 位置4 & M
  623. Else
  624. 位置41 = "B2:" & 位置4 & M
  625. End If
  626. xlSheet.Range(位置41).Select() : myExcel.Selection.RowHeight = 13.5
  627. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 5
  628. xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 25
  629. xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 30
  630. xlSheet.Range(位置41).Select() : xlSheet.Range("J2").Activate()
  631. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  632. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  633. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  634. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  635. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  636. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  637. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  638. myExcel.ActiveWindow.ScrollRow = 981 : myExcel.ActiveWindow.ScrollRow = 967 : myExcel.ActiveWindow.ScrollRow = 940 : myExcel.ActiveWindow.ScrollRow = 845
  639. myExcel.ActiveWindow.ScrollRow = 804 : myExcel.ActiveWindow.ScrollRow = 791 : myExcel.ActiveWindow.ScrollRow = 587 : myExcel.ActiveWindow.ScrollRow = 546
  640. myExcel.ActiveWindow.ScrollRow = 533 : myExcel.ActiveWindow.ScrollRow = 519 : myExcel.ActiveWindow.ScrollRow = 343 : myExcel.ActiveWindow.ScrollRow = 316
  641. myExcel.ActiveWindow.ScrollRow = 288 : myExcel.ActiveWindow.ScrollRow = 126 : myExcel.ActiveWindow.ScrollRow = 99 : myExcel.ActiveWindow.ScrollRow = 71
  642. myExcel.ActiveWindow.ScrollRow = 4
  643. 位置41 = "B3:" & 位置4 & "3"
  644. xlSheet.Range(位置41).Select()
  645. With myExcel.Selection.Interior
  646. .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent5 : .TintAndShade = 0.599993896298105 : .PatternTintAndShade = 0
  647. End With
  648. xlSheet.Range("M9").Select()
  649. myExcel.ActiveWindow.ScrollColumn = 4 : myExcel.ActiveWindow.ScrollColumn = 3 : myExcel.ActiveWindow.ScrollColumn = 2 : myExcel.ActiveWindow.ScrollColumn = 1
  650. myExcel.ActiveWindow.DisplayGridlines = False
  651. End Sub
  652. Private Sub Excel巨集_C(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  653. '全選改變字體
  654. xlSheet.Cells.Select()
  655. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  656. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  657. End With
  658. ' 改變行寬 Columns("A") & Columns("H")
  659. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 1
  660. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 1
  661. ' 改變行寬
  662. xlSheet.Columns("B:C").Select : myExcel.Selection.ColumnWidth = 10
  663. xlSheet.Columns("I:J").Select : myExcel.Selection.ColumnWidth = 10
  664. xlSheet.Columns("D:G").Select : myExcel.Selection.ColumnWidth = 15
  665. xlSheet.Columns("K:N").Select : myExcel.Selection.ColumnWidth = 15
  666. '全選改變列高
  667. xlSheet.Cells.Select() '全選
  668. myExcel.Selection.RowHeight = 25 '改變列高
  669. xlSheet.Range("A1").Select()
  670. ' 改變列高Rows("1")
  671. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 5
  672. ' 改變列高Rows("2")
  673. xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 35
  674. ' ("B2到N2")跨欄至中
  675. xlSheet.Range("B2:N2").Select()
  676. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  677. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  678. End With : myExcel.Selection.Merge
  679. ' ("B3到C3")跨欄至中
  680. xlSheet.Range("B3:C3").Select()
  681. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  682. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  683. End With : myExcel.Selection.Merge
  684. ' ("I3到J3")跨欄至中
  685. xlSheet.Range("I3:J3").Select()
  686. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  687. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  688. End With : myExcel.Selection.Merge
  689. ' ("I4到J4")跨欄至中
  690. xlSheet.Range("I4:J4").Select()
  691. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  692. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  693. End With : myExcel.Selection.Merge
  694. myExcel.Selection.Merge
  695. '月total 跨欄至中
  696. xlSheet.Range("B" & Index_月_total.ToString & ":C" & Index_月_total.ToString).Select()
  697. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  698. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  699. End With : myExcel.Selection.Merge
  700. '跨欄至中 週 later
  701. xlSheet.Range("I" & (CInt(週選_週數_tb.Text) + 5).ToString & ":J" & (CInt(週選_週數_tb.Text) + 5).ToString).Select()
  702. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  703. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  704. End With : myExcel.Selection.Merge
  705. '跨欄至中 週 total
  706. xlSheet.Range("I" & (CInt(週選_週數_tb.Text) + 6).ToString & ":J" & (CInt(週選_週數_tb.Text) + 6).ToString).Select()
  707. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  708. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  709. End With : myExcel.Selection.Merge
  710. ' 儲存格設置格式 週日期格式
  711. xlSheet.Range("I5:J" & (CInt(週選_週數_tb.Text) + 4).ToString).Select()
  712. myExcel.Selection.NumberFormatLocal = "mm/dd/yy;@" '設置格式
  713. xlSheet.Range("B4").Select()
  714. myExcel.Selection.NumberFormatLocal = "mm/dd/yy;@"
  715. xlSheet.Range("B" & (Index_月_total - 1).ToString).Select()
  716. myExcel.Selection.NumberFormatLocal = "mm/dd/yy;@"
  717. ' 改變字體大小
  718. xlSheet.Range("B2:N2").Select()
  719. myExcel.Selection.Font.Size = 14
  720. ' 儲存格設置格式 (數值 千分位符號)
  721. xlSheet.Range("D4:G1000").Select() : myExcel.Selection.NumberFormatLocal = "#,##0_ "
  722. xlSheet.Range("K4:N1000").Select() : myExcel.Selection.NumberFormatLocal = "#,##0_ "
  723. ' 儲存格顏色設定
  724. xlSheet.Range("B3:G3").Select()
  725. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .Color = 16247773 : .TintAndShade = 0 : .PatternTintAndShade = 0 : End With
  726. ' 儲存格顏色設定
  727. xlSheet.Range("I3:N3").Select()
  728. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .Color = 16247773 : .TintAndShade = 0 : .PatternTintAndShade = 0 : End With
  729. ' 儲存格顏色設定
  730. 'xlSheet.Range("B2:N2").Select()
  731. 'With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.399975585192419 : .PatternTintAndShade = 0 : End With
  732. ' 儲存格顏色設定 月total
  733. xlSheet.Range("G4:G" & Index_月_total.ToString).Select()
  734. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  735. ' 儲存格顏色設定 月total
  736. xlSheet.Range("B" & Index_月_total.ToString & ":G" & Index_月_total.ToString).Select()
  737. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  738. ' 儲存格顏色設定 週total
  739. xlSheet.Range("N4:N" & (CInt(週選_週數_tb.Text) + 6).ToString).Select()
  740. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  741. ' 儲存格顏色設定 週total
  742. xlSheet.Range("I" & (CInt(週選_週數_tb.Text) + 6).ToString & ":N" & (CInt(週選_週數_tb.Text) + 6).ToString).Select()
  743. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  744. ' 儲存格 格線設定 月
  745. xlSheet.Range("B3:G" & Index_月_total.ToString).Select()
  746. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  747. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  748. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  749. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  750. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  751. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  752. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  753. ' 儲存格 格線設定 週
  754. xlSheet.Range("I3:N" & (CInt(週選_週數_tb.Text) + 6).ToString).Select()
  755. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  756. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  757. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  758. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  759. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  760. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  761. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  762. ' 儲存格 格線設定 標頭
  763. 'xlSheet.Range("B2:N2").Select()
  764. 'myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  765. 'myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  766. 'With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  767. 'With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  768. 'With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  769. 'With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  770. 'With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  771. 'With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  772. '全選後資料至中
  773. xlSheet.Cells.Select()
  774. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  775. .ShrinkToFit = False : .ReadingOrder = xlContext
  776. End With
  777. ' 隱藏格線
  778. myExcel.ActiveWindow.DisplayGridlines = False
  779. End Sub
  780. End Class