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 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. Option Strict Off
  2. Imports System.IO
  3. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  4. Imports Microsoft.Office.Interop.Excel.Constants
  5. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  6. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  7. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  8. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  9. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  10. Imports Microsoft.Office.Interop.Excel.XlWindowState
  11. Imports Microsoft.Office.Interop.Excel
  12. Public Class 財務收支單一覽表
  13. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  14. Dim N1 As Integer : Dim N2 As Integer
  15. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  16. Private Sub Set_清單1()
  17. DataGridView4.DataSource = Nothing : ds1.Clear()
  18. DataGridView4.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  19. DataGridView4.ColumnHeadersHeight = 25
  20. DataGridView4.AllowUserToAddRows = False
  21. SQL_營運成本收支單一覽表清單()
  22. da.Fill(ds1) : DataGridView4.DataSource = ds1.Tables(0) : conn.Close()
  23. DataGridView4.Columns(0).FillWeight = 160 : DataGridView4.Columns(1).Visible = False : DataGridView4.Columns(2).FillWeight = 100 : DataGridView4.Columns(3).Visible = False
  24. DataGridView4.Columns(4).FillWeight = 100 : DataGridView4.Columns(5).Visible = False : DataGridView4.Columns(6).Visible = False
  25. End Sub
  26. Private Sub Set_清單2()
  27. DataGridView2.DataSource = Nothing : ds2.Clear()
  28. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  29. DataGridView2.ColumnHeadersHeight = 25
  30. DataGridView2.AllowUserToAddRows = False
  31. SQL_營運成本收支單一覽表彙總()
  32. da.Fill(ds2) : DataGridView2.DataSource = ds2.Tables(0) : conn.Close()
  33. DataGridView2.Columns(0).FillWeight = 100 : DataGridView2.Columns(1).FillWeight = 140 : DataGridView2.Columns(2).FillWeight = 140 : DataGridView2.Columns(3).FillWeight = 140
  34. DataGridView2.Columns(4).FillWeight = 100 : DataGridView2.Columns(5).FillWeight = 100 : DataGridView2.Columns(6).FillWeight = 100 : DataGridView2.Columns(7).FillWeight = 100
  35. DataGridView2.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView2.Columns(7).DefaultCellStyle.Format = "#,##0" : DataGridView2.Columns(4).DefaultCellStyle.Format = "#,##0"
  36. DataGridView2.Columns(5).DefaultCellStyle.Format = "#,##0"
  37. DataGridView2.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView2.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  38. DataGridView2.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView2.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  39. DataGridView2.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView2.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  40. DataGridView2.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView2.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  41. DataGridView2.Columns(0).ReadOnly = True : DataGridView2.Columns(1).ReadOnly = True : DataGridView2.Columns(2).ReadOnly = True : DataGridView2.Columns(3).ReadOnly = True
  42. DataGridView2.Columns(4).ReadOnly = True : DataGridView2.Columns(5).ReadOnly = True : DataGridView2.Columns(6).ReadOnly = True : DataGridView2.Columns(7).ReadOnly = True
  43. End Sub
  44. Private Sub Set_費用清單()
  45. DataGridView1.DataSource = Nothing : ds.Clear()
  46. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  47. DataGridView1.ColumnHeadersHeight = 25
  48. DataGridView1.AllowUserToAddRows = False
  49. DataGridView1.RowTemplate.Height = 35
  50. SQL_營運成本收支單一覽表費用清單()
  51. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  52. DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).FillWeight = 80 : DataGridView1.Columns(2).FillWeight = 300 : DataGridView1.Columns(3).FillWeight = 500
  53. DataGridView1.Columns(4).FillWeight = 140 : DataGridView1.Columns(5).FillWeight = 140 : DataGridView1.Columns(6).FillWeight = 140 : DataGridView1.Columns(7).FillWeight = 140
  54. DataGridView1.Columns(8).FillWeight = 140
  55. DataGridView1.Columns(1).ReadOnly = True : DataGridView1.Columns(2).ReadOnly = True : DataGridView1.Columns(3).ReadOnly = True : DataGridView1.Columns(4).ReadOnly = True
  56. DataGridView1.Columns(5).ReadOnly = True : DataGridView1.Columns(6).ReadOnly = True
  57. DataGridView1.Columns(4).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(5).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(6).DefaultCellStyle.Format = "#,##0"
  58. DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0"
  59. DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  60. DataGridView1.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  61. DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  62. DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  63. DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
  64. TextBox5.Text = "0" : TextBox7.Text = "0" : TextBox6.Text = "0" : TextBox10.Text = "0" : TextBox11.Text = "0"
  65. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  66. TextBox5.Text = Val(TextBox5.Text) + DataGridView1.Rows(i).Cells("現金").Value : TextBox7.Text = Val(TextBox7.Text) + DataGridView1.Rows(i).Cells("支出").Value
  67. TextBox10.Text = Val(TextBox10.Text) + DataGridView1.Rows(i).Cells("開票").Value : TextBox11.Text = Val(TextBox11.Text) + DataGridView1.Rows(i).Cells("收票").Value
  68. Next i
  69. TextBox6.Text = Val(TextBox10.Text) + Val(TextBox5.Text) - Val(TextBox7.Text)
  70. If Val(TextBox6.Text) > 0 Then : TextBox6.ForeColor = Color.Blue : Else : TextBox6.ForeColor = Color.Red : End If
  71. TextBox5.Text = Strings.Format(Val(TextBox5.Text), "#,##0") : TextBox7.Text = Strings.Format(Val(TextBox7.Text), "#,##0") : TextBox6.Text = Strings.Format(Val(TextBox6.Text), "#,##0")
  72. TextBox10.Text = Strings.Format(Val(TextBox10.Text), "#,##0") : TextBox11.Text = Strings.Format(Val(TextBox11.Text), "#,##0")
  73. End Sub
  74. Private Sub 日期格式()
  75. If 會計月.Checked = True Then
  76. '-------------日期一----------------------------------------------------------------------------------------
  77. DTP = Strings.Left(Strings.Format(DateTimePicker4.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker4.Value = DTP
  78. DateTimePicker4.Value = DateTimePicker4.Value.AddMonths(-1)
  79. DTP = Strings.Left(Strings.Format(DateTimePicker4.Value, "yyyy/MM/dd"), 8) & "26" : DateTimePicker4.Value = DTP
  80. '-------------日期二----------------------------------------------------------------------------------------
  81. DTP = Strings.Left(Strings.Format(DateTimePicker3.Value, "yyyy/MM/dd"), 8) & "25" : DateTimePicker3.Value = DTP
  82. Else
  83. '-------------日期一----------------------------------------------------------------------------------------
  84. DateTimePicker4.Value = DateTimePicker4.Value.AddMonths(1)
  85. DTP = Strings.Left(Strings.Format(DateTimePicker4.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker4.Value = DTP
  86. '-------------日期二----------------------------------------------------------------------------------------
  87. DTP = Strings.Left(Strings.Format(DateTimePicker3.Value, "yyyy/MM/dd"), 8) & "01" : DateTimePicker3.Value = DTP
  88. DateTimePicker3.Value = DateTimePicker3.Value.AddMonths(1) : DateTimePicker3.Value = DateTimePicker3.Value.AddDays(-1)
  89. End If
  90. End Sub
  91. Private Sub 營運費用支付單一覽表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  92. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  93. 日期格式() : DataGridView2.Visible = False : RadioButton1.Checked = True : DateTimePicker5.Visible = False
  94. End Sub
  95. Private Sub DataGridView4_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView4.CellClick
  96. If e.RowIndex = -1 Then : Else
  97. TextBox1.Text = DataGridView4(0, e.RowIndex).Value.ToString : TextBox13.Text = DataGridView4(6, e.RowIndex).Value.ToString
  98. TextBox3.Text = DataGridView4(1, e.RowIndex).Value.ToString : DateTimePicker1.Value = DataGridView4(2, e.RowIndex).Value.ToString
  99. TextBox4.Text = DataGridView4(3, e.RowIndex).Value.ToString : DateTimePicker2.Value = DataGridView4(4, e.RowIndex).Value.ToString
  100. TextBox14.Text = DataGridView4(5, e.RowIndex).Value.ToString
  101. Set_費用清單()
  102. End If
  103. End Sub
  104. Private Sub DataGridView2_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView2.RowPostPaint
  105. Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
  106. If e.RowIndex = DataGridView2.Rows.Count - 1 Then
  107. Exit Sub
  108. Else
  109. If DataGridView2(0, e.RowIndex).Value.ToString <> DataGridView2(0, e.RowIndex + 1).Value.ToString Then
  110. Dim startX As Integer = IIf(DataGridView2.RowHeadersVisible, DataGridView2.RowHeadersWidth, 0)
  111. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  112. Dim endX As Integer = startX + DataGridView2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView2.HorizontalScrollingOffset
  113. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  114. Exit Sub
  115. End If
  116. If DataGridView2(1, e.RowIndex).Value.ToString <> DataGridView2(1, e.RowIndex + 1).Value.ToString Then
  117. Dim startX As Integer = IIf(DataGridView2.RowHeadersVisible, DataGridView2.RowHeadersWidth, 0)
  118. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  119. Dim endX As Integer = startX + DataGridView2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView2.HorizontalScrollingOffset
  120. e.Graphics.DrawLine(linePen1, startX, startY, endX, startY)
  121. Exit Sub
  122. End If
  123. End If
  124. End Sub
  125. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  126. If 會計月.Checked = True Then
  127. DateTimePicker5.Value = DateTimePicker5.Value.AddMonths(-1)
  128. DateTimePicker4.Value = DateTimePicker5.Value
  129. DateTimePicker3.Value = DateTimePicker5.Value
  130. Else
  131. DateTimePicker5.Value = DateTimePicker5.Value.AddMonths(-1)
  132. DateTimePicker4.Value = DateTimePicker5.Value.AddMonths(-1)
  133. DateTimePicker3.Value = DateTimePicker5.Value
  134. End If
  135. 日期格式()
  136. End Sub
  137. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  138. If 會計月.Checked = True Then
  139. DateTimePicker5.Value = DateTimePicker5.Value.AddMonths(1)
  140. DateTimePicker4.Value = DateTimePicker5.Value
  141. DateTimePicker3.Value = DateTimePicker5.Value
  142. Else
  143. DateTimePicker5.Value = DateTimePicker5.Value.AddMonths(1)
  144. DateTimePicker4.Value = DateTimePicker5.Value.AddMonths(-1)
  145. DateTimePicker3.Value = DateTimePicker5.Value
  146. End If
  147. 日期格式()
  148. End Sub
  149. Private Sub 彙總計算()
  150. If RadioButton1.Checked = False And RadioButton2.Checked = True Then
  151. TextBox5.Text = "0" : TextBox7.Text = "0" : TextBox6.Text = "0" : TextBox10.Text = "0" : TextBox11.Text = "0"
  152. For i As Integer = 0 To DataGridView2.Rows.Count - 1
  153. TextBox5.Text = Val(TextBox5.Text) + DataGridView2.Rows(i).Cells("現金").Value : TextBox7.Text = Val(TextBox7.Text) + DataGridView2.Rows(i).Cells("支出").Value
  154. TextBox10.Text = Val(TextBox10.Text) + DataGridView2.Rows(i).Cells("開票").Value : TextBox11.Text = Val(TextBox11.Text) + DataGridView2.Rows(i).Cells("收票").Value
  155. Next i
  156. TextBox6.Text = Val(TextBox10.Text) + Val(TextBox5.Text) - Val(TextBox7.Text)
  157. If Val(TextBox6.Text) > 0 Then : TextBox6.ForeColor = Color.Blue : Else : TextBox6.ForeColor = Color.Red : End If
  158. TextBox5.Text = Strings.Format(Val(TextBox5.Text), "#,##0") : TextBox7.Text = Strings.Format(Val(TextBox7.Text), "#,##0") : TextBox6.Text = Strings.Format(Val(TextBox6.Text), "#,##0")
  159. TextBox10.Text = Strings.Format(Val(TextBox10.Text), "#,##0") : TextBox11.Text = Strings.Format(Val(TextBox11.Text), "#,##0")
  160. End If
  161. End Sub
  162. Private Sub DateTimePicker4_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker4.ValueChanged
  163. Set_清單1() : Set_清單2() : 彙總計算()
  164. End Sub
  165. Private Sub DateTimePicker3_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker3.ValueChanged
  166. Set_清單1() : Set_清單2() : 彙總計算()
  167. End Sub
  168. Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
  169. DataGridView1.Visible = True : DataGridView2.Visible = False : RadioButton1.Checked = True : RadioButton2.Checked = False
  170. TextBox5.Text = "0" : TextBox7.Text = "0" : TextBox6.Text = "0" : TextBox10.Text = "0" : TextBox11.Text = "0" : DataGridView4.Enabled = True
  171. End Sub
  172. Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click
  173. DataGridView1.Visible = False : DataGridView2.Visible = True : RadioButton1.Checked = False : RadioButton2.Checked = True
  174. TextBox1.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" : DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView4.Enabled = False
  175. 彙總計算()
  176. End Sub
  177. Private Sub TextBox14_TextChanged(sender As Object, e As EventArgs) Handles TextBox14.TextChanged
  178. PA = TextBox14.Text : SQL_使用者權限圖片顯示()
  179. While dr.Read() = True
  180. Dim unused As Byte() = New Byte(-1) {}
  181. Dim bytes As Byte() = DirectCast(dr.Item("簽名檔圖片"), Byte())
  182. Dim oStream As New MemoryStream(bytes)
  183. PictureBox1.Image = Bitmap.FromStream(oStream)
  184. End While
  185. conn.Close() : PictureBox1.SizeMode = 4
  186. End Sub
  187. Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月.Click
  188. 會計月.Checked = True : 一般月.Checked = False : 日期格式()
  189. End Sub
  190. Private Sub 一般月_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月.Click
  191. 會計月.Checked = False : 一般月.Checked = True : 日期格式()
  192. End Sub
  193. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  194. xlApp = CType(CreateObject("Excel.Application"), Application)
  195. xlBook = xlApp.Workbooks.Add
  196. xlApp.DisplayAlerts = True
  197. xlBook.Activate()
  198. xlSheet = NewMethod(xlBook)
  199. xlSheet.Activate()
  200. xlApp.Visible = True
  201. xlApp.Application.WindowState = xlMaximized
  202. xlSheet.Cells(1, 1) = "年度" : xlSheet.Cells(1, 2) = Year(Today) - 1911
  203. If RadioButton1.Checked = True And RadioButton2.Checked = False Then
  204. xlSheet.Cells(1, 3) = MAOJI_ERP_SYS.ComboBox2.Text & "-營運費用收支明細表"
  205. xlSheet.Cells(2, 1) = "收款日期" : xlSheet.Cells(2, 2) = "會計科目" : xlSheet.Cells(2, 3) = "客戶或用途"
  206. xlSheet.Cells(2, 4) = "開票" : xlSheet.Cells(2, 5) = "收票" : xlSheet.Cells(2, 6) = "現金" : xlSheet.Cells(2, 7) = "支出" : xlSheet.Cells(2, 8) = "現金餘額" : xlSheet.Cells(2, 9) = "票期"
  207. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  208. xlSheet.Cells(i + 3, 1) = DateTimePicker1.Value : xlSheet.Cells(i + 3, 2) = DataGridView1.Rows(i).Cells("會計科目").Value
  209. xlSheet.Cells(i + 3, 3) = DataGridView1.Rows(i).Cells("用途").Value : xlSheet.Cells(i + 3, 4) = DataGridView1.Rows(i).Cells("開票").Value
  210. xlSheet.Cells(i + 3, 5) = DataGridView1.Rows(i).Cells("收票").Value : xlSheet.Cells(i + 3, 6) = DataGridView1.Rows(i).Cells("現金").Value
  211. xlSheet.Cells(i + 3, 7) = DataGridView1.Rows(i).Cells("支出").Value : xlSheet.Cells(i + 3, 9) = DataGridView1.Rows(i).Cells("票期").Value
  212. If i = 0 Then
  213. xlSheet.Cells(i + 3, 8) = "=D3+F3-G3"
  214. Else
  215. xlSheet.Cells(i + 3, 8) = "=H" & i + 2 & "+D" & i + 3 & "+F" & i + 3 & "-G" & i + 3 & ""
  216. End If
  217. With xlApp.Selection
  218. .Font.Bold = True
  219. End With
  220. N1 = i + 3 : N2 = i + 3
  221. Next i
  222. xlSheet.Cells(N1 + 1, 3) = "以下空白" : xlSheet.Cells(N1 + 3, 1) = "簽核(點交)" : xlSheet.Cells(N1 + 3, 7) = "製表 : " & TextBox3.Text & " - " & DateTimePicker1.Value
  223. xlSheet.Cells(N1 + 2, 4) = "=SUM(D3:D" & N1 + 1 & ")" : xlSheet.Cells(N1 + 2, 5) = "=SUM(E3:E" & N1 + 1 & ")" : xlSheet.Cells(N1 + 2, 6) = "=SUM(F3:F" & N1 + 1 & ")"
  224. xlSheet.Cells(N1 + 2, 7) = "=SUM(G3:G" & N1 + 1 & ")" : xlSheet.Cells(N1 + 2, 8) = "=H" & N1 : xlSheet.Cells(N1 + 2, 1) = "合計"
  225. AA(xlApp, xlSheet) : BB(xlApp, xlSheet)
  226. ElseIf RadioButton1.Checked = False And RadioButton2.Checked = True Then
  227. xlSheet.Cells(1, 3) = MAOJI_ERP_SYS.ComboBox2.Text & "-營運費用收支彙總簡表"
  228. xlSheet.Cells(2, 1) = "日期" : xlSheet.Cells(2, 2) = "主項" : xlSheet.Cells(2, 3) = "子項" : xlSheet.Cells(2, 4) = "子細項" : xlSheet.Cells(2, 5) = "開票"
  229. xlSheet.Cells(2, 6) = "收票" : xlSheet.Cells(2, 7) = "現金" : xlSheet.Cells(2, 8) = "支出" : xlSheet.Cells(2, 9) = "現金餘額"
  230. For i As Integer = 0 To DataGridView2.Rows.Count - 1
  231. xlSheet.Cells(i + 3, 1) = DataGridView2.Rows(i).Cells("日期").Value
  232. xlSheet.Cells(i + 3, 2) = DataGridView2.Rows(i).Cells("主項").Value
  233. xlSheet.Cells(i + 3, 3) = DataGridView2.Rows(i).Cells("子項").Value
  234. xlSheet.Cells(i + 3, 4) = DataGridView2.Rows(i).Cells("子細項").Value
  235. xlSheet.Cells(i + 3, 5) = DataGridView2.Rows(i).Cells("開票").Value
  236. xlSheet.Cells(i + 3, 6) = DataGridView2.Rows(i).Cells("收票").Value
  237. xlSheet.Cells(i + 3, 7) = DataGridView2.Rows(i).Cells("現金").Value
  238. xlSheet.Cells(i + 3, 8) = DataGridView2.Rows(i).Cells("支出").Value
  239. If i = 0 Then
  240. xlSheet.Cells(i + 3, 9) = "=E3+G3-H3"
  241. Else
  242. xlSheet.Cells(i + 3, 9) = "=I" & i + 2 & "+E" & i + 3 & "+G" & i + 3 & "-H" & i + 3 & ""
  243. End If
  244. With xlApp.Selection
  245. .Font.Bold = True
  246. End With
  247. N1 = i + 3 : N2 = i + 3
  248. Next i
  249. xlSheet.Cells(N1 + 1, 2) = "以下空白" : xlSheet.Cells(N1 + 3, 1) = "簽核" : xlSheet.Cells(N1 + 3, 5) = "製表 : " & gUserName & " - " & Today()
  250. xlSheet.Cells(N1 + 2, 5) = "=SUM(E3:E" & N1 + 1 & ")" : xlSheet.Cells(N1 + 2, 6) = "=SUM(F3:F" & N1 + 1 & ")" : xlSheet.Cells(N1 + 2, 7) = "=SUM(G3:G" & N1 + 1 & ")"
  251. xlSheet.Cells(N1 + 2, 8) = "=SUM(H3:H" & N1 + 1 & ")" : xlSheet.Cells(N1 + 2, 9) = "=I" & N1 : xlSheet.Cells(N1 + 2, 1) = "合計"
  252. CC(xlApp, xlSheet)
  253. End If
  254. xlSheet.PageSetup.PrintArea = ""
  255. xlApp.Cells.Select()
  256. xlSheet.Range("B1").Select()
  257. xlApp.Application.WindowState = xlMinimized
  258. xlSheet.Cells.Select()
  259. xlApp.ActiveSheet.Protect(DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="0911274990")
  260. xlApp.ActiveSheet.EnableSelection = 1
  261. MsgBox("列印完成。")
  262. End Sub
  263. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  264. Return CType(xlBook.Worksheets.Add, Worksheet)
  265. End Function
  266. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  267. xlSheet.Cells.Select()
  268. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  269. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  270. End With
  271. xlSheet.Columns("A:A").Select : myExcel.Selection.NumberFormatLocal = "m/d;@"
  272. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  273. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  274. End With
  275. xlSheet.Range("B1").Select()
  276. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  277. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  278. End With
  279. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 25
  280. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 30
  281. xlSheet.Columns("D:H").Select : myExcel.Selection.ColumnWidth = 10 : myExcel.Selection.NumberFormatLocal = "#,##0;[紅色]-#,##0"
  282. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 10 : myExcel.Selection.NumberFormatLocal = "[$-zh-TW]e/m/d;@"
  283. xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 25
  284. xlSheet.Range("A2:I2").Select()
  285. With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  286. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  287. End With
  288. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  289. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  290. End With
  291. xlSheet.Range("A2:I" & N1 + 2).Select() : myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  292. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  293. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  294. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  295. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  296. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  297. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  298. myExcel.ActiveWindow.DisplayGridlines = False
  299. xlSheet.Rows("3:" & N1 + 2).Select : myExcel.Selection.RowHeight = 20
  300. xlSheet.Rows(N1 + 3 & ":" & N1 + 3).Select : myExcel.Selection.RowHeight = 40
  301. xlSheet.Columns("I:I").Select
  302. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  303. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  304. End With
  305. xlSheet.Range("A" & N1 + 2 & ":C" & N1 + 2).Select() : myExcel.Selection.Merge
  306. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  307. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True
  308. End With
  309. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 25
  310. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  311. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  312. End With
  313. End Sub
  314. Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  315. Clipboard.SetDataObject(PictureBox1.Image)
  316. xlSheet.Range("B" & N2 + 3).Select()
  317. myExcel.ActiveSheet.Pictures.Paste.Select
  318. myExcel.Selection.ShapeRange.Height = 43
  319. myExcel.Selection.ShapeRange.IncrementTop(3)
  320. End Sub
  321. Private Sub CC(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  322. xlSheet.Cells.Select()
  323. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  324. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  325. End With
  326. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 8
  327. xlSheet.Columns("B:C").Select : myExcel.Selection.ColumnWidth = 15
  328. xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 20
  329. xlSheet.Columns("E:I").Select : myExcel.Selection.ColumnWidth = 10 : myExcel.Selection.NumberFormatLocal = "#,##0;[紅色]-#,##0"
  330. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 25
  331. xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 25
  332. xlSheet.Rows("3:" & N1 + 2).Select : myExcel.Selection.RowHeight = 20
  333. xlSheet.Rows(N1 + 3 & ":" & N1 + 3).Select : myExcel.Selection.RowHeight = 40
  334. xlSheet.Rows("2:2").Select
  335. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  336. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  337. End With
  338. xlSheet.Range("A1").Select()
  339. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  340. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  341. End With
  342. xlSheet.Range("B1").Select()
  343. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  344. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  345. End With
  346. xlSheet.Rows("1:1").Select
  347. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  348. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  349. End With
  350. xlSheet.Range("A2:I" & N1 + 2).Select() : myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  351. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  352. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  353. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  354. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  355. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  356. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  357. xlSheet.Range("A" & N1 + 2 & ":D" & N1 + 2).Select() : myExcel.Selection.Merge
  358. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  359. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True
  360. End With
  361. xlSheet.Columns("E:I").Select : myExcel.Selection.NumberFormatLocal = "#,##0;[紅色]-#,##0"
  362. myExcel.ActiveWindow.DisplayGridlines = False
  363. End Sub
  364. '----------------------滑鼠右鍵--------------------------------------------------------------------------------------------------------------------------------------------------------------------
  365. Private Sub 重新讀取ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新讀取ToolStripMenuItem.Click
  366. Set_清單1() : Set_清單2() : 彙總計算()
  367. End Sub
  368. End Class