暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

應付賬款.vb 26KB

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