Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

應付賬款控制表.vb 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Imports Microsoft.Office.Interop.Excel
  11. Public Class 應付賬款控制表
  12. ReadOnly ds As New DataSet
  13. Dim N1 As Integer : Dim 新項次 As String
  14. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  15. Private Sub Set_賬款清單()
  16. DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView1.ColumnHeadersHeight = 40
  17. DataGridView1.AllowUserToAddRows = False : DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView1.MultiSelect = True
  18. SQL_應付賬款清單()
  19. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  20. DataGridView1.Columns(0).FillWeight = 150 : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).FillWeight = 100 : DataGridView1.Columns(3).Visible = False
  21. DataGridView1.Columns(4).FillWeight = 80 : DataGridView1.Columns(5).FillWeight = 300 : DataGridView1.Columns(6).FillWeight = 80 : DataGridView1.Columns(7).FillWeight = 80
  22. DataGridView1.Columns(8).FillWeight = 80 : DataGridView1.Columns(9).FillWeight = 80 : DataGridView1.Columns(10).FillWeight = 100 : DataGridView1.Columns(11).FillWeight = 100
  23. DataGridView1.Columns(12).FillWeight = 150 : DataGridView1.Columns(13).FillWeight = 60 : DataGridView1.Columns(14).FillWeight = 50 : DataGridView1.Columns(15).Visible = False
  24. DataGridView1.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0.000"
  25. DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(9).DefaultCellStyle.Format = "#,##0"
  26. DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  27. DataGridView1.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  28. DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  29. DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  30. DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  31. DataGridView1.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  32. DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  33. DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  34. DataGridView1.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  35. For I As Integer = 0 To 12 : DataGridView1.Columns(I).ReadOnly = True : Next : DataGridView1.Columns(14).ReadOnly = True
  36. For I As Integer = 0 To DataGridView1.Rows.Count - 1
  37. If DataGridView1.Rows(I).Cells("應付立帳").Value.ToString = "" Then : DataGridView1.Rows(I).Cells("應付立帳").Value = False : End If
  38. DataGridView1.Rows(I).Cells("選擇").Value = False
  39. Next
  40. End Sub
  41. Private Sub ComboBox1下拉表單資料載入()
  42. SQL_會計科目_第一階_只含流動票務()
  43. ComboBox5.Items.Clear() : ComboBox1.Items.Clear() : While (dr.Read()) : ComboBox5.Items.Add(dr("第一階")) : ComboBox1.Items.Add(dr("編號")) : End While : conn.Close()
  44. End Sub
  45. Private Sub ComboBox3下拉表單資料載入()
  46. PA = ComboBox1.Text : SQL_會計科目_第二階_只含流動票務()
  47. ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : While (dr.Read()) : ComboBox3.Items.Add(dr("第二階")) : ComboBox4.Items.Add(dr("編號")) : End While : conn.Close() : PA = ""
  48. End Sub
  49. Private Sub ComboBox6下拉表單資料載入()
  50. PA = ComboBox4.Text : SQL_會計科目_第三階_只含流動票務()
  51. ComboBox7.Items.Clear() : ComboBox6.Items.Clear() : While (dr.Read()) : ComboBox7.Items.Add(dr("會計科目")) : ComboBox6.Items.Add(dr("編號")) : End While : conn.Close()
  52. If ComboBox7.Items.Count <> 0 Then : ComboBox7.SelectedIndex = 0 : End If
  53. End Sub
  54. Private Sub 日期格式()
  55. If 會計月.Checked = True Then
  56. '-------------日期一----------------------------------------------------------------------------------------
  57. DTP = Strings.Left(Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker1.Value = DTP
  58. DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(-1)
  59. DTP = Strings.Left(Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd"), 8) & "26" : DateTimePicker1.Value = DTP
  60. '-------------日期二----------------------------------------------------------------------------------------
  61. DTP = Strings.Left(Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd"), 8) & "25" : DateTimePicker2.Value = DTP
  62. Else
  63. '-------------日期一----------------------------------------------------------------------------------------
  64. DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(1)
  65. DTP = Strings.Left(Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker1.Value = DTP
  66. '-------------日期二----------------------------------------------------------------------------------------
  67. Dim iDays As Integer = DateTime.DaysInMonth(Strings.Left(Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd"), 4), Strings.Mid(Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd"), 6, 2))
  68. DTP = Strings.Left(Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd"), 8) & iDays : DateTimePicker2.Value = DTP
  69. End If
  70. End Sub
  71. Private Sub 預設關鍵字()
  72. 關鍵字編號 = "DV002" : SQL_通用預設值管理查詢() : If dr.Read() Then : TextBox9.Text = dr("預設值") : End If
  73. End Sub
  74. Private Sub 應付賬款_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  75. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  76. ComboBox6.Visible = False : TextBox1.Visible = False : TextBox4.Visible = False : TextBox5.Visible = False
  77. TextBox1.Text = "0" : TextBox2.Text = "0"
  78. ComboBox1下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox6下拉表單資料載入() : 日期格式() : Set_賬款清單()
  79. 預設關鍵字()
  80. End Sub
  81. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  82. DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(-1) : DateTimePicker2.Value = DateTimePicker2.Value.AddMonths(-1) : Set_賬款清單()
  83. End Sub
  84. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  85. DateTimePicker1.Value = DateTimePicker1.Value.AddMonths(1) : DateTimePicker2.Value = DateTimePicker2.Value.AddMonths(1) : Set_賬款清單()
  86. End Sub
  87. Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月.Click
  88. 會計月.Checked = True : 一般月.Checked = False : 日期格式() : Set_賬款清單()
  89. End Sub
  90. Private Sub 一般月_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月.Click
  91. 會計月.Checked = False : 一般月.Checked = True : 日期格式() : Set_賬款清單()
  92. End Sub
  93. Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.TextChanged
  94. ComboBox1.SelectedIndex = ComboBox5.SelectedIndex : TextBox9.Text = "" : ComboBox3下拉表單資料載入() : ComboBox6下拉表單資料載入()
  95. End Sub
  96. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
  97. ComboBox5.SelectedIndex = ComboBox1.SelectedIndex : ComboBox3下拉表單資料載入() : ComboBox6下拉表單資料載入()
  98. End Sub
  99. Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.TextChanged
  100. ComboBox4.SelectedIndex = ComboBox3.SelectedIndex : ComboBox6下拉表單資料載入()
  101. End Sub
  102. Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.TextChanged
  103. ComboBox3.SelectedIndex = ComboBox4.SelectedIndex : ComboBox6下拉表單資料載入()
  104. End Sub
  105. Private Sub ComboBox7_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox7.SelectedIndexChanged
  106. ComboBox6.SelectedIndex = ComboBox7.SelectedIndex
  107. End Sub
  108. Private Sub ComboBox6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox6.SelectedIndexChanged
  109. ComboBox7.SelectedIndex = ComboBox6.SelectedIndex
  110. End Sub
  111. Private Sub TextBox9_TextChanged(sender As Object, e As EventArgs) Handles TextBox9.TextChanged
  112. PA = TextBox9.Text : SQL_會計科目_關鍵字_只含流動票務()
  113. ComboBox7.Items.Clear() : ComboBox6.Items.Clear() : While (dr.Read()) : ComboBox7.Items.Add(dr("會計科目")) : ComboBox6.Items.Add(dr("編號")) : End While : conn.Close()
  114. If ComboBox7.Items.Count <> 0 Then : ComboBox7.SelectedIndex = 0 : End If : PA = ""
  115. End Sub
  116. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  117. If e.RowIndex = -1 Then : Else
  118. TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells("單據編號").Value : TextBox5.Text = DataGridView1.Rows(e.RowIndex).Cells("供應商").Value
  119. TextBox2.Text = "0" : TextBox1.Text = "0"
  120. For I As Integer = 0 To DataGridView1.Rows.Count - 1
  121. If CheckBox2.Checked = False Then
  122. DataGridView1.Rows(I).Cells("選擇").Value = False
  123. End If
  124. If TextBox3.Text = DataGridView1.Rows(I).Cells("單據編號").Value Then
  125. DataGridView1.Rows(I).Cells("選擇").Value = True
  126. TextBox1.Text = Val(TextBox1.Text) + DataGridView1.Rows(I).Cells("金額").Value
  127. TextBox2.Text = Val(TextBox2.Text) + DataGridView1.Rows(I).Cells("金額").Value
  128. End If
  129. Next
  130. TextBox2.Text = Strings.Format(Val(TextBox2.Text), "#,##0")
  131. End If
  132. End Sub
  133. Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  134. Dim linePen As New Pen(Color.Blue, 2)
  135. If e.RowIndex = DataGridView1.Rows.Count - 1 Then : Exit Sub
  136. Else
  137. If DataGridView1(0, e.RowIndex).Value.ToString <> DataGridView1(0, e.RowIndex + 1).Value.ToString Then
  138. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  139. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  140. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  141. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  142. End If
  143. End If
  144. End Sub
  145. Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
  146. For i As Integer = 0 To DataGridView1.Rows.Count - 1 : DataGridView1.Rows(i).Cells("選擇").Value = True : Next i
  147. End Sub
  148. Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
  149. For i As Integer = 0 To DataGridView1.Rows.Count - 1 : DataGridView1.Rows(i).Cells("選擇").Value = False : Next i
  150. End Sub
  151. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  152. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  153. If TextBox3.Text = DataGridView1.Rows(i).Cells("單據編號").Value.ToString Then
  154. DataGridView1.Rows(i).Cells("應付立帳").Value = False
  155. End If
  156. Next i
  157. End Sub
  158. Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  159. NumericUpDown2.Value = Val(TextBox1.Text) - NumericUpDown1.Value
  160. End Sub
  161. Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
  162. NumericUpDown2.Value = Val(TextBox1.Text) - NumericUpDown1.Value
  163. End Sub
  164. Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.CheckedChanged
  165. Set_賬款清單()
  166. End Sub
  167. Private Sub Set_日期格式轉換()
  168. If CheckBox1.Checked = False Then : DTP = Strings.Format(Today(), "yyyy/MM/dd") : DTP1 = Strings.Format(Today(), "yyyyMMdd")
  169. Else : DTP1 = Strings.Format(DateTimePicker3.Value, "yyyyMMdd") : DTP = Strings.Format(DateTimePicker3.Value, "yyyy/MM/dd") : End If
  170. End Sub
  171. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  172. If CheckBox2.Checked = True Then
  173. MsgBox("開立支付單(傳票)需要一張一張來,請重新選擇。")
  174. CheckBox2.Checked = False
  175. For I As Integer = 0 To DataGridView1.Rows.Count - 1
  176. DataGridView1.Rows(I).Cells("選擇").Value = False
  177. Next
  178. Else
  179. If NumericUpDown1.Value = 0 Then
  180. MsgBox("實付金額不可為零。") : Exit Sub
  181. Else
  182. If NumericUpDown2.Value = 0 Then : Else
  183. If ComboBox6.Text = "" Then
  184. MsgBox("未付款金額擇讓需要會計科目。") : Exit Sub
  185. Else
  186. End If
  187. End If
  188. Dim 確認 As Boolean = False
  189. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  190. If DataGridView1.Rows(i).Cells("選擇").Value = True Then
  191. MsgBox("該採購單已經開立過傳票,如是之前開立有誤需要從新開立,請先點擊--依據單號取消立帳選擇--按鈕。如是因採購退貨需要開立收支單(傳票)請先勾選--已立帳資料隱藏--再行操作。")
  192. Exit Sub
  193. End If
  194. Next
  195. If 確認 = False Then : MsgBox("沒有選擇任何一筆要轉收支帳(傳票)的採購單號。")
  196. Else
  197. Dim NUM1 As Integer : Set_日期格式轉換()
  198. For ii As Integer = 1 To 999
  199. NUM1 = 0 + ii
  200. If NUM1 < 10 Then : TextBox4.Text = "OE-" & DTP1 & "-00" & NUM1
  201. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox4.Text = "OE-" & DTP1 & "-0" & NUM1
  202. ElseIf NUM1 > 99 Then : TextBox4.Text = "OE-" & DTP1 & "-" & NUM1 : End If : PA = TextBox4.Text
  203. SQL_營運成本收支單申請_支付單號流水號()
  204. If dr.Read() Then : Else : ii = 999 : End If
  205. Next
  206. SQL_營運成本控制表新增()
  207. SQL_營運成本明細表項次新增查詢()
  208. If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close() : NUM1 = Double.Parse(新項次) + 1
  209. If NUM1 < 10 Then : 新項次 = "0" & NUM1
  210. ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1 : End If
  211. 關鍵字編號 = "DV001" : SQL_通用預設值管理查詢() : If dr.Read() Then : PA3 = dr("預設值") : End If
  212. PA1 = TextBox4.Text : PA2 = 新項次 : PA4 = TextBox5.Text & " - " & DateTimePicker1.Value & " 到 " & DateTimePicker2.Value & " 應付帳款"
  213. NU1 = NumericUpDown1.Value : PA5 = "" : NU2 = 0 : NU3 = 0 : NU4 = 0 : PA6 = "付現" : PA7 = gUserName
  214. SQL_營運成本明細表新增()
  215. If NumericUpDown2.Value = 0 Then : Else
  216. SQL_營運成本明細表項次新增查詢()
  217. If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close() : NUM1 = Double.Parse(新項次) + 1
  218. If NUM1 < 10 Then : 新項次 = "0" & NUM1
  219. ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1 : End If
  220. PA1 = TextBox4.Text : PA2 = 新項次 : PA3 = ComboBox6.Text : PA4 = TextBox5.Text & " - " & DateTimePicker1.Value & " 到 " & DateTimePicker2.Value & " 貨款折讓"
  221. NU1 = NumericUpDown2.Value * -1 : PA5 = "" : NU2 = 0 : NU3 = 0 : NU4 = 0 : PA6 = "付現" : PA7 = gUserName
  222. SQL_營運成本明細表新增()
  223. End If
  224. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  225. 資料數 = DataGridView1.Rows.Count : MyModule1.進度條()
  226. If DataGridView1.Rows(i).Cells("選擇").Value = True Then
  227. PA6 = DataGridView1.Rows(i).Cells("資料流水號").Value
  228. SQL_應付賬款_倉儲明細應付立帳修改()
  229. End If
  230. Next i : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("財務收支單(傳票)申請完成,請通知主管審核。") : Set_賬款清單()
  231. End If
  232. End If
  233. End If
  234. End Sub
  235. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  236. xlApp = CType(CreateObject("Excel.Application"), Application)
  237. xlBook = xlApp.Workbooks.Add
  238. xlApp.DisplayAlerts = True
  239. xlApp.Visible = True
  240. xlApp.Application.WindowState = xlMaximized
  241. N1 = 0
  242. If DataGridView1.Rows.Count = 0 Then : Else
  243. xlSheet = NewMethod(xlBook)
  244. xlSheet.Cells(1, 1) = MAOJI_ERP_SYS.ComboBox2.Text : xlSheet.Cells(2, 1) = DateTimePicker1.Value & " 到 " & DateTimePicker2.Value & " 應付帳款清單"
  245. xlSheet.Cells(3, 1) = "單據編號" : xlSheet.Cells(3, 2) = "供應商" : xlSheet.Cells(3, 3) = "頁碼" : xlSheet.Cells(3, 4) = "品名" : xlSheet.Cells(3, 5) = "單價" : xlSheet.Cells(3, 6) = "匯率"
  246. xlSheet.Cells(3, 7) = "入庫" : xlSheet.Cells(3, 8) = "金額" : xlSheet.Cells(3, 9) = "採購下單" : xlSheet.Cells(3, 10) = "入庫日期" : xlSheet.Cells(3, 11) = "是否立帳"
  247. xlSheet.Cells(2, 7) = "合計" : xlSheet.Cells(2, 8) = "=SUBTOTAL(9,H4:H9999)"
  248. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  249. If DataGridView1.Rows(i).Cells("選擇").Value = True Then
  250. xlSheet.Cells(N1 + 4, 1) = DataGridView1.Rows(i).Cells("單據編號").Value : xlSheet.Cells(N1 + 4, 2) = DataGridView1.Rows(i).Cells("供應商").Value
  251. xlSheet.Cells(N1 + 4, 3) = DataGridView1.Rows(i).Cells("頁碼").Value : xlSheet.Cells(N1 + 4, 4) = DataGridView1.Rows(i).Cells("品名").Value
  252. xlSheet.Cells(N1 + 4, 5) = DataGridView1.Rows(i).Cells("單價").Value : xlSheet.Cells(N1 + 4, 6) = DataGridView1.Rows(i).Cells("匯率").Value
  253. xlSheet.Cells(N1 + 4, 7) = DataGridView1.Rows(i).Cells("入庫").Value : xlSheet.Cells(N1 + 4, 8) = DataGridView1.Rows(i).Cells("金額").Value
  254. xlSheet.Cells(N1 + 4, 9) = DataGridView1.Rows(i).Cells("採購下單").Value : xlSheet.Cells(N1 + 4, 10) = DataGridView1.Rows(i).Cells("入庫日期").Value
  255. If DataGridView1.Rows(i).Cells("應付立帳").Value = True Then : PA1 = "YES" : Else : PA1 = "NO" : End If
  256. xlSheet.Cells(N1 + 4, 11) = PA1
  257. N1 += 1
  258. End If
  259. Next i
  260. N1 += 4
  261. AA(xlApp, xlSheet)
  262. End If
  263. xlSheet.PageSetup.PrintArea = ""
  264. xlApp.Cells.Select()
  265. xlSheet.Range("B1").Select()
  266. xlApp.Application.WindowState = xlMinimized
  267. xlSheet.Cells.Select()
  268. MsgBox("列印完成。")
  269. End Sub
  270. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  271. Return CType(xlBook.Worksheets.Add, Worksheet)
  272. End Function
  273. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  274. xlSheet.Cells.Select()
  275. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  276. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  277. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 18 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10
  278. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 9 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 30
  279. xlSheet.Columns("E:H").Select : myExcel.Selection.NumberFormatLocal = "#,##0;[紅色]-#,##0"
  280. xlSheet.Columns("F:F").Select : myExcel.Selection.NumberFormatLocal = "#,##0.000;[紅色]-#,##0.000"
  281. xlSheet.Columns("E:H").Select : myExcel.Selection.ColumnWidth = 7 : xlSheet.Columns("I:J").Select : myExcel.Selection.ColumnWidth = 10
  282. xlSheet.Columns("K:K").Select : myExcel.Selection.ColumnWidth = 8
  283. xlSheet.Rows("1:1").Select
  284. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 22 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  285. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  286. xlSheet.Rows("2:2").Select
  287. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 18 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  288. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  289. xlSheet.Rows("3:3").Select
  290. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  291. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  292. xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = True : xlSheet.Rows("3:3").Select : myExcel.Selection.AutoFilter
  293. xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 25
  294. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlTop : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  295. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  296. xlSheet.Range("H2:I2").Select()
  297. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  298. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  299. xlSheet.Range("G2:I2").Select()
  300. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  301. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  302. xlSheet.Range("A1:K1").Select()
  303. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  304. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  305. xlSheet.Range("A2:F2").Select()
  306. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  307. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  308. xlSheet.Range("L10").Select() : myExcel.ActiveWindow.DisplayGridlines = False
  309. xlSheet.Range("G2").Select()
  310. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  311. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  312. xlSheet.Range("A3:K" & N1).Select()
  313. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  314. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  315. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  316. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  317. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  318. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  319. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  320. End Sub
  321. End Class