No Description
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 28KB

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