Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

倉儲對帳表.vb 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Imports Microsoft.Office.Interop.Excel.XlPrintLocation
  11. Imports Microsoft.Office.Interop.Excel.XlPageOrientation
  12. Imports Microsoft.Office.Interop.Excel.XlPaperSize
  13. Imports Microsoft.Office.Interop.Excel.XlOrder
  14. Imports Microsoft.Office.Interop.Excel.XlPrintErrors
  15. Imports Microsoft.Office.Interop.Excel
  16. Imports System.IO
  17. Public Class 倉儲對帳表
  18. ReadOnly ds1 As New DataSet
  19. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  20. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  21. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  22. Dim 位置1 As String
  23. Dim N2 As Integer
  24. Private Sub 倉儲對帳表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  25. Me.MdiParent = ICS_ASMS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  26. SQL_物料資料庫_類別_下拉清單() : 類別清單_cb.Items.Clear()
  27. While (dr.Read()) : 類別清單_cb.Items.Add(dr("類別")) : End While : conn.Close()
  28. 選擇供應商_cb.Items.Add("")
  29. SQL_物料資料庫_供應商_下拉清單()
  30. While (dr.Read()) : 選擇供應商_cb.Items.Add(dr("公司名")) : End While : conn.Close()
  31. Set_清單2()
  32. SQL_讀取公司名稱()
  33. If dr.Read() Then
  34. 公司名稱.Text = dr("公司名稱")
  35. End If
  36. End Sub
  37. Private Sub Set_清單2()
  38. 明細表_dgv.DataSource = Nothing : ds1.Clear()
  39. 明細表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  40. 明細表_dgv.ColumnHeadersHeight = 25
  41. 明細表_dgv.AllowUserToAddRows = False
  42. 明細表_dgv.RowTemplate.Height = 35
  43. 明細表_dgv.EditMode = DataGridViewEditMode.EditOnEnter
  44. SQL_倉儲對帳表_明細表清單() : da.Fill(ds1) : 明細表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  45. 明細表_dgv.Columns(3).ReadOnly = True : 明細表_dgv.Columns(4).ReadOnly = True : 明細表_dgv.Columns(5).ReadOnly = True
  46. 明細表_dgv.Columns(8).ReadOnly = True
  47. 明細表_dgv.Columns(0).FillWeight = 60 : 明細表_dgv.Columns(1).FillWeight = 60 : 明細表_dgv.Columns(2).Visible = False : 明細表_dgv.Columns(3).FillWeight = 150
  48. 明細表_dgv.Columns(4).FillWeight = 150 : 明細表_dgv.Columns(5).FillWeight = 40 : 明細表_dgv.Columns(6).FillWeight = 40
  49. 明細表_dgv.Columns(7).FillWeight = 40 : 明細表_dgv.Columns(8).FillWeight = 40 : 明細表_dgv.Columns(9).FillWeight = 150
  50. 明細表_dgv.Columns(10).Visible = False : 明細表_dgv.Columns(11).Visible = False
  51. 明細表_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 明細表_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
  52. Dim NUM1, NUM2, NUM3, NUM4 As Integer
  53. For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
  54. 明細表_dgv.Rows(i).Cells("總額").Value = 明細表_dgv.Rows(i).Cells("單價").Value * 明細表_dgv.Rows(i).Cells("數量").Value
  55. If 明細表_dgv.Rows(i).Cells("數量").Value < 0 Then
  56. NUM1 += 明細表_dgv.Rows(i).Cells("總額").Value
  57. Else
  58. NUM2 += 明細表_dgv.Rows(i).Cells("總額").Value
  59. End If
  60. Next
  61. 本期銷貨金額_tb.Text = Strings.Format(Val(NUM2), "#,##0")
  62. 本期銷退金額_tb.Text = Strings.Format(Val(-NUM1), "#,##0")
  63. NUM3 = NUM2 + NUM1
  64. 合計金額_tb.Text = Strings.Format(Val(NUM3), "#,##0")
  65. NUM4 = NUM3 * 0.05
  66. If 含稅_ch.Checked = True Then
  67. 稅額_tb.Text = Strings.Format(Val(NUM4), "#,##0")
  68. 金額總計_tb.Text = Strings.Format(Val(NUM3 + NUM4), "#,##0")
  69. Else
  70. 稅額_tb.Text = "0"
  71. 金額總計_tb.Text = Strings.Format(Val(NUM3), "#,##0")
  72. End If
  73. End Sub
  74. Private Sub 含稅_CheckedChanged(sender As Object, e As EventArgs) Handles 含稅_ch.Click
  75. 含稅_ch.Checked = True : 不含稅_ch.Checked = False
  76. Dim NUM1, NUM2 As Integer
  77. NUM1 = 合計金額_tb.Text
  78. NUM2 = NUM1 * 0.05
  79. If 含稅_ch.Checked = True Then
  80. 稅額_tb.Text = Strings.Format(Val(NUM2), "#,##0")
  81. 金額總計_tb.Text = Strings.Format(Val(NUM1 + NUM2), "#,##0")
  82. Else
  83. 稅額_tb.Text = "0"
  84. 金額總計_tb.Text = Strings.Format(Val(NUM1), "#,##0")
  85. End If
  86. End Sub
  87. Private Sub 不含稅_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 不含稅_ch.Click
  88. 含稅_ch.Checked = False : 不含稅_ch.Checked = True
  89. Dim NUM1, NUM2 As Integer
  90. NUM1 = 合計金額_tb.Text
  91. NUM2 = NUM1 * 0.05
  92. If 含稅_ch.Checked = True Then
  93. 稅額_tb.Text = Strings.Format(Val(NUM2), "#,##0")
  94. 金額總計_tb.Text = Strings.Format(Val(NUM1 + NUM2), "#,##0")
  95. Else
  96. 稅額_tb.Text = "0"
  97. 金額總計_tb.Text = Strings.Format(Val(NUM1), "#,##0")
  98. End If
  99. End Sub
  100. Private Sub 選擇供應商_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 選擇供應商_cb.SelectedIndexChanged
  101. Set_清單2()
  102. If 選擇供應商_cb.Text = "" Then
  103. 供應商編號.Text = "" : 供應商名稱.Text = "" : 地址.Text = "" : 電話.Text = "" : 傳真.Text = ""
  104. Else
  105. SQL_倉儲對帳表_供應商資料()
  106. While (dr.Read())
  107. 供應商編號.Text = dr("編號") : 供應商名稱.Text = dr("名稱") : 地址.Text = dr("地址") : 電話.Text = dr("電話") : 傳真.Text = dr("傳真")
  108. End While : conn.Close()
  109. End If
  110. End Sub
  111. Private Sub 開始日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 開始日期_dtp.ValueChanged
  112. Set_清單2() : 開始日期_dtp.CustomFormat = "yyyy/MM/dd"
  113. 開始日期_dtp.Format = DateTimePickerFormat.Custom
  114. End Sub
  115. Private Sub 結束日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 結束日期_dtp.ValueChanged
  116. Set_清單2() : 結束日期_dtp.CustomFormat = "yyyy/MM/dd"
  117. 結束日期_dtp.Format = DateTimePickerFormat.Custom
  118. End Sub
  119. Private Sub 當日_bt_Click(sender As Object, e As EventArgs) Handles 當日_bt.Click
  120. 中間日期_dtp.Value = Today
  121. DTP = Strings.Format(Today(), "yyyy/MM/dd")
  122. 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = DTP
  123. Set_清單2()
  124. End Sub
  125. Private Sub 當月_bt_Click(sender As Object, e As EventArgs) Handles 當月_bt.Click
  126. 中間日期_dtp.Value = Today
  127. DTP = Strings.Left(Strings.Format(Today(), "yyyy/MM/dd"), 8) & "01"
  128. 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = Today()
  129. Set_清單2()
  130. End Sub
  131. Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月_ch.Click
  132. 會計月_ch.Checked = True : 一般月_ch.Checked = False : 日期格式() : Set_清單2()
  133. End Sub
  134. Private Sub 一般月_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月_ch.Click
  135. 會計月_ch.Checked = False : 一般月_ch.Checked = True : 日期格式() : Set_清單2()
  136. End Sub
  137. Private Sub 上個月_bt_Click(sender As Object, e As EventArgs) Handles 上個月_bt.Click
  138. If 會計月_ch.Checked = True Then
  139. 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
  140. 開始日期_dtp.Value = 中間日期_dtp.Value
  141. 結束日期_dtp.Value = 中間日期_dtp.Value
  142. Else
  143. 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1)
  144. 開始日期_dtp.Value = 中間日期_dtp.Value
  145. 結束日期_dtp.Value = 中間日期_dtp.Value
  146. End If : 日期格式() : Set_清單2()
  147. End Sub
  148. Private Sub 下個月_bt_Click(sender As Object, e As EventArgs) Handles 下個月_bt.Click
  149. If 會計月_ch.Checked = True Then
  150. 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
  151. 開始日期_dtp.Value = 中間日期_dtp.Value
  152. 結束日期_dtp.Value = 中間日期_dtp.Value
  153. Else
  154. 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1)
  155. 開始日期_dtp.Value = 中間日期_dtp.Value
  156. 結束日期_dtp.Value = 中間日期_dtp.Value
  157. End If : 日期格式() : Set_清單2()
  158. End Sub
  159. Private Sub 日期格式()
  160. If 會計月_ch.Checked = True Then
  161. '-------------日期一----------------------------------------------------------------------------------------
  162. DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
  163. 開始日期_dtp.Value = 結束日期_dtp.Value.AddMonths(-1)
  164. DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "26" : 開始日期_dtp.Value = DTP
  165. '-------------日期二----------------------------------------------------------------------------------------
  166. DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "25" : 結束日期_dtp.Value = DTP
  167. Else
  168. 開始日期_dtp.Value = 結束日期_dtp.Value
  169. '-------------日期一----------------------------------------------------------------------------------------
  170. DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP
  171. '-------------日期二----------------------------------------------------------------------------------------
  172. DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 結束日期_dtp.Value = DTP
  173. 結束日期_dtp.Value = 結束日期_dtp.Value.AddMonths(1) : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(-1)
  174. End If
  175. End Sub
  176. Private Sub 匯出EXCEL_bt_MouseEnter(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.MouseEnter
  177. ToolTip1.SetToolTip(Me.匯出EXCEL_bt, "匯出PDF")
  178. End Sub
  179. Private Sub 匯出EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.Click
  180. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  181. xlApp.Visible = True
  182. xlApp.DisplayAlerts = True
  183. xlApp.Application.WindowState = xlMaximized
  184. xlBook = xlApp.Workbooks.Add
  185. xlSheet = NewMethod(xlBook)
  186. xlBook.Activate()
  187. xlSheet.Activate()
  188. Dim m As String
  189. Dim selectedDate As DateTime = 中間日期_dtp.Value
  190. Dim y As String = selectedDate.Year.ToString()
  191. If selectedDate.Month < 10 Then : m = "0" & selectedDate.Month.ToString()
  192. Else : m = selectedDate.Month.ToString()
  193. End If
  194. xlSheet.Cells(1, 1) = 公司名稱.Text & y & "年" & m & "月銷貨明細表"
  195. xlSheet.Cells(2, 1) = "供應商名稱: " & 供應商名稱.Text
  196. xlSheet.Cells(2, 4) = "供應商編號: " & 供應商編號.Text
  197. xlSheet.Cells(3, 1) = "地址: " & 地址.Text
  198. xlSheet.Cells(4, 1) = "電話: " & 電話.Text
  199. xlSheet.Cells(4, 4) = "傳真: " & 傳真.Text
  200. xlSheet.Cells(5, 1) = "項次" : xlSheet.Cells(5, 2) = "車種年份" : xlSheet.Cells(5, 3) = "品名"
  201. xlSheet.Cells(5, 4) = "廠牌" : xlSheet.Cells(5, 5) = "數量" : xlSheet.Cells(5, 6) = "單價" : xlSheet.Cells(5, 7) = "總額"
  202. xlSheet.Cells(5, 8) = "備註"
  203. For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
  204. xlSheet.Cells(i + 6, 1) = i + 1
  205. Dim str As String
  206. Dim cellValue As Object = 明細表_dgv.Rows(i).Cells("車種年份").Value
  207. If cellValue IsNot Nothing AndAlso IsNumeric(cellValue.ToString()) Then
  208. ' 如果是數字,則加上 '
  209. str = "'" & cellValue.ToString()
  210. Else
  211. str = 明細表_dgv.Rows(i).Cells("車種年份").Value
  212. End If
  213. xlSheet.Cells(i + 6, 2) = str : xlSheet.Cells(i + 6, 3) = 明細表_dgv.Rows(i).Cells("品名").Value
  214. xlSheet.Cells(i + 6, 4) = 明細表_dgv.Rows(i).Cells("廠牌").Value : xlSheet.Cells(i + 6, 5) = 明細表_dgv.Rows(i).Cells("數量").Value
  215. Dim value As Double = Convert.ToDouble(明細表_dgv.Rows(i).Cells("單價").Value)
  216. Dim formattedValue As String = value.ToString("#,##0") : xlSheet.Cells(i + 6, 6) = formattedValue
  217. Dim value1 As Double = Convert.ToDouble(明細表_dgv.Rows(i).Cells("總額").Value)
  218. Dim formattedValue1 As String = value1.ToString("#,##0") : xlSheet.Cells(i + 6, 7) = formattedValue1
  219. xlSheet.Cells(i + 6, 8) = 明細表_dgv.Rows(i).Cells("備註").Value
  220. N2 = i
  221. Next i
  222. xlSheet.Cells(N2 + 7, 4) = "金額合計:" : xlSheet.Cells(N2 + 7, 6) = 合計金額_tb.Text
  223. xlSheet.Cells(N2 + 8, 4) = "稅 額:" : xlSheet.Cells(N2 + 8, 6) = 稅額_tb.Text
  224. xlSheet.Cells(N2 + 9, 4) = "金額總計:" : xlSheet.Cells(N2 + 9, 6) = 金額總計_tb.Text
  225. BB(xlApp, xlSheet)
  226. xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
  227. '----轉成PDF-----
  228. Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
  229. If Not Directory.Exists(pdfFolderPath) Then
  230. Directory.CreateDirectory(pdfFolderPath)
  231. End If
  232. Dim pdfFilePath As String = Path.Combine(pdfFolderPath, 供應商名稱.Text & y & "年" & m & "月-對帳單.pdf")
  233. xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
  234. '--------
  235. xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
  236. Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
  237. Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  238. Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  239. xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
  240. Try
  241. Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
  242. If System.IO.File.Exists(chromePath) Then
  243. Dim process As New Process()
  244. process.StartInfo.FileName = "chrome"
  245. process.StartInfo.Arguments = """" & pdfFilePath & """"
  246. process.Start()
  247. Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  248. If System.IO.File.Exists(edgePath) Then
  249. Dim process As New Process()
  250. process.StartInfo.FileName = "msedge"
  251. process.StartInfo.Arguments = """" & pdfFilePath & """"
  252. process.Start()
  253. Else
  254. Process.Start(pdfFilePath)
  255. End If
  256. End If
  257. Catch ex As Exception
  258. MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & 供應商名稱.Text & y & "年" & m & "月-對帳單.pdf")
  259. End Try
  260. End Sub
  261. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  262. xlSheet.Cells.Select()
  263. With myExcel.Selection.Font
  264. .Name = "微軟正黑體"
  265. .Size = 10
  266. .Strikethrough = False
  267. .Superscript = False
  268. .Subscript = False
  269. .OutlineFont = False
  270. .Shadow = False
  271. .Underline = xlUnderlineStyleNone
  272. .ThemeColor = xlThemeColorLight1
  273. .TintAndShade = 0
  274. .ThemeFont = xlThemeFontNone
  275. End With
  276. xlSheet.Range("A1:H1").Select()
  277. With myExcel.Selection.Font
  278. .Name = "微軟正黑體"
  279. .Size = 14
  280. .Strikethrough = False
  281. .Superscript = False
  282. .Subscript = False
  283. .OutlineFont = False
  284. .Shadow = False
  285. .Underline = xlUnderlineStyleNone
  286. .ThemeColor = xlThemeColorLight1
  287. .TintAndShade = 0
  288. .ThemeFont = xlThemeFontNone
  289. End With
  290. xlSheet.Range("A2:H4").Select()
  291. With myExcel.Selection.Font
  292. .Name = "微軟正黑體"
  293. .Size = 12
  294. .Strikethrough = False
  295. .Superscript = False
  296. .Subscript = False
  297. .OutlineFont = False
  298. .Shadow = False
  299. .Underline = xlUnderlineStyleNone
  300. .ThemeColor = xlThemeColorLight1
  301. .TintAndShade = 0
  302. .ThemeFont = xlThemeFontNone
  303. End With
  304. xlSheet.Columns("A:A").ColumnWidth = 4.5
  305. xlSheet.Columns("B:B").ColumnWidth = 22
  306. xlSheet.Columns("C:C").ColumnWidth = 28
  307. xlSheet.Columns("D:D").ColumnWidth = 6
  308. xlSheet.Columns("E:E").ColumnWidth = 4
  309. xlSheet.Columns("F:F").ColumnWidth = 7
  310. xlSheet.Columns("G:G").ColumnWidth = 8
  311. xlSheet.Columns("H:H").ColumnWidth = 14
  312. xlSheet.Range("A5:H5").Select()
  313. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  314. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  315. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
  316. With myExcel.Selection.Borders(xlEdgeTop)
  317. .LineStyle = xlContinuous
  318. .ColorIndex = 0
  319. .TintAndShade = 0
  320. .Weight = xlThin
  321. End With
  322. With myExcel.Selection.Borders(xlEdgeBottom)
  323. .LineStyle = xlContinuous
  324. .ColorIndex = 0
  325. .TintAndShade = 0
  326. .Weight = xlThin
  327. End With
  328. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone
  329. myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
  330. myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  331. xlSheet.Range("A" & N2 + 7 & ":H" & N2 + 7).Select()
  332. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  333. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  334. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
  335. With myExcel.Selection.Borders(xlEdgeTop)
  336. .LineStyle = xlContinuous
  337. .ColorIndex = 0
  338. .TintAndShade = 0
  339. .Weight = xlThin
  340. End With
  341. myExcel.Selection.Borders(xlEdgeBottom).LineStyle = xlNone
  342. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone
  343. myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
  344. myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  345. xlSheet.Columns("A:A").Select
  346. With myExcel.Selection
  347. .HorizontalAlignment = xlCenter
  348. .VerticalAlignment = xlCenter
  349. .WrapText = False
  350. .Orientation = 0
  351. .AddIndent = False
  352. .IndentLevel = 0
  353. .ShrinkToFit = False
  354. .ReadingOrder = xlContext
  355. .MergeCells = False
  356. End With
  357. xlSheet.Range("E5:G5").Select()
  358. With myExcel.Selection
  359. .HorizontalAlignment = xlRight
  360. .VerticalAlignment = xlCenter
  361. .WrapText = False
  362. .Orientation = 0
  363. .AddIndent = False
  364. .IndentLevel = 0
  365. .ShrinkToFit = False
  366. .ReadingOrder = xlContext
  367. .MergeCells = False
  368. End With
  369. xlSheet.Range("A1:H1").Select()
  370. With myExcel.Selection
  371. .HorizontalAlignment = xlCenter
  372. .VerticalAlignment = xlCenter
  373. .WrapText = False
  374. .Orientation = 0
  375. .AddIndent = False
  376. .IndentLevel = 0
  377. .ShrinkToFit = False
  378. .ReadingOrder = xlContext
  379. .MergeCells = False
  380. End With
  381. myExcel.Selection.Merge
  382. xlSheet.Range("A2:C2").Select()
  383. With myExcel.Selection
  384. .HorizontalAlignment = xlLeft
  385. .VerticalAlignment = xlCenter
  386. .WrapText = False
  387. .Orientation = 0
  388. .AddIndent = False
  389. .IndentLevel = 0
  390. .ShrinkToFit = False
  391. .ReadingOrder = xlContext
  392. .MergeCells = False
  393. End With
  394. myExcel.Selection.Merge
  395. xlSheet.Range("D2:H2").Select()
  396. With myExcel.Selection
  397. .HorizontalAlignment = xlLeft
  398. .VerticalAlignment = xlCenter
  399. .WrapText = False
  400. .Orientation = 0
  401. .AddIndent = False
  402. .IndentLevel = 0
  403. .ShrinkToFit = False
  404. .ReadingOrder = xlContext
  405. .MergeCells = False
  406. End With
  407. myExcel.Selection.Merge
  408. xlSheet.Range("A3:H3").Select()
  409. With myExcel.Selection
  410. .HorizontalAlignment = xlLeft
  411. .VerticalAlignment = xlCenter
  412. .WrapText = False
  413. .Orientation = 0
  414. .AddIndent = False
  415. .IndentLevel = 0
  416. .ShrinkToFit = False
  417. .ReadingOrder = xlContext
  418. .MergeCells = False
  419. End With
  420. myExcel.Selection.Merge
  421. xlSheet.Range("A4:C4").Select()
  422. With myExcel.Selection
  423. .HorizontalAlignment = xlLeft
  424. .VerticalAlignment = xlCenter
  425. .WrapText = False
  426. .Orientation = 0
  427. .AddIndent = False
  428. .IndentLevel = 0
  429. .ShrinkToFit = False
  430. .ReadingOrder = xlContext
  431. .MergeCells = False
  432. End With
  433. myExcel.Selection.Merge
  434. xlSheet.Range("D4:H4").Select()
  435. With myExcel.Selection
  436. .HorizontalAlignment = xlLeft
  437. .VerticalAlignment = xlCenter
  438. .WrapText = False
  439. .Orientation = 0
  440. .AddIndent = False
  441. .IndentLevel = 0
  442. .ShrinkToFit = False
  443. .ReadingOrder = xlContext
  444. .MergeCells = False
  445. End With
  446. myExcel.Selection.Merge
  447. xlSheet.Range("D" & N2 + 7 & ":E" & N2 + 7).Select()
  448. With myExcel.Selection
  449. .HorizontalAlignment = xlRight
  450. .VerticalAlignment = xlCenter
  451. .WrapText = False
  452. .Orientation = 0
  453. .AddIndent = False
  454. .IndentLevel = 0
  455. .ShrinkToFit = False
  456. .ReadingOrder = xlContext
  457. .MergeCells = False
  458. End With
  459. myExcel.Selection.Merge
  460. xlSheet.Range("F" & N2 + 7 & ":G" & N2 + 7).Select()
  461. With myExcel.Selection
  462. .HorizontalAlignment = xlRight
  463. .VerticalAlignment = xlCenter
  464. .WrapText = False
  465. .Orientation = 0
  466. .AddIndent = False
  467. .IndentLevel = 0
  468. .ShrinkToFit = False
  469. .ReadingOrder = xlContext
  470. .MergeCells = False
  471. End With
  472. myExcel.Selection.Merge
  473. xlSheet.Range("D" & N2 + 8 & ":E" & N2 + 8).Select()
  474. With myExcel.Selection
  475. .HorizontalAlignment = xlRight
  476. .VerticalAlignment = xlCenter
  477. .WrapText = False
  478. .Orientation = 0
  479. .AddIndent = False
  480. .IndentLevel = 0
  481. .ShrinkToFit = False
  482. .ReadingOrder = xlContext
  483. .MergeCells = False
  484. End With
  485. myExcel.Selection.Merge
  486. xlSheet.Range("F" & N2 + 8 & ":G" & N2 + 8).Select()
  487. With myExcel.Selection
  488. .HorizontalAlignment = xlRight
  489. .VerticalAlignment = xlCenter
  490. .WrapText = False
  491. .Orientation = 0
  492. .AddIndent = False
  493. .IndentLevel = 0
  494. .ShrinkToFit = False
  495. .ReadingOrder = xlContext
  496. .MergeCells = False
  497. End With
  498. myExcel.Selection.Merge
  499. xlSheet.Range("D" & N2 + 9 & ":E" & N2 + 9).Select()
  500. With myExcel.Selection
  501. .HorizontalAlignment = xlRight
  502. .VerticalAlignment = xlCenter
  503. .WrapText = False
  504. .Orientation = 0
  505. .AddIndent = False
  506. .IndentLevel = 0
  507. .ShrinkToFit = False
  508. .ReadingOrder = xlContext
  509. .MergeCells = False
  510. End With
  511. myExcel.Selection.Merge
  512. xlSheet.Range("F" & N2 + 9 & ":G" & N2 + 9).Select()
  513. With myExcel.Selection
  514. .HorizontalAlignment = xlRight
  515. .VerticalAlignment = xlCenter
  516. .WrapText = False
  517. .Orientation = 0
  518. .AddIndent = False
  519. .IndentLevel = 0
  520. .ShrinkToFit = False
  521. .ReadingOrder = xlContext
  522. .MergeCells = False
  523. End With
  524. myExcel.Selection.Merge
  525. myExcel.Application.PrintCommunication = False
  526. With myExcel.ActiveSheet.PageSetup
  527. .PrintTitleRows = "$1:$5"
  528. .PrintTitleColumns = "$A:$H"
  529. End With
  530. myExcel.Application.PrintCommunication = True
  531. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  532. myExcel.Application.PrintCommunication = False
  533. With myExcel.ActiveSheet.PageSetup
  534. .LeftHeader = ""
  535. .CenterHeader = ""
  536. .RightHeader = "&D"
  537. .LeftFooter = ""
  538. .CenterFooter = "第 &P 頁,共 &N 頁"
  539. .RightFooter = ""
  540. .LeftMargin = myExcel.Application.InchesToPoints(0.25)
  541. .RightMargin = myExcel.Application.InchesToPoints(0.25)
  542. .TopMargin = myExcel.Application.InchesToPoints(0.75)
  543. .BottomMargin = myExcel.Application.InchesToPoints(0.75)
  544. .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
  545. .FooterMargin = myExcel.Application.InchesToPoints(0.3)
  546. .PrintHeadings = False
  547. .PrintGridlines = False
  548. .CenterHorizontally = False
  549. .CenterVertically = False
  550. .Draft = False
  551. .FirstPageNumber = xlAutomatic
  552. .BlackAndWhite = False
  553. .Zoom = 100
  554. .OddAndEvenPagesHeaderFooter = False
  555. .DifferentFirstPageHeaderFooter = False
  556. .ScaleWithDocHeaderFooter = True
  557. .AlignMarginsHeaderFooter = True
  558. .EvenPage.LeftHeader.Text = ""
  559. .EvenPage.CenterHeader.Text = ""
  560. .EvenPage.RightHeader.Text = ""
  561. .EvenPage.LeftFooter.Text = ""
  562. .EvenPage.CenterFooter.Text = ""
  563. .EvenPage.RightFooter.Text = ""
  564. .FirstPage.LeftHeader.Text = ""
  565. .FirstPage.CenterHeader.Text = ""
  566. .FirstPage.RightHeader.Text = ""
  567. .FirstPage.LeftFooter.Text = ""
  568. .FirstPage.CenterFooter.Text = ""
  569. .FirstPage.RightFooter.Text = ""
  570. End With
  571. myExcel.Application.PrintCommunication = True
  572. End Sub
  573. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  574. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  575. End Function
  576. End Class