Bez popisu
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.

匯出EXCEL.vb 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. Imports System.Data.SqlClient
  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. Public Class 匯出EXCEL
  11. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  12. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  13. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  14. Dim misValue As Object = System.Reflection.Missing.Value
  15. Dim 判斷月差結果 As Boolean
  16. Dim Index_Row_Date As Date : Dim str01 As String = ""
  17. ReadOnly ds1 As New DataSet
  18. Private Sub 匯出EXCEL_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  19. 匯出EXCEL_bt.Enabled = True
  20. FormBorderStyle = FormBorderStyle.SizableToolWindow
  21. 月選_起始_dtp.Value = Today() : 月選_結束_dtp.Value = Today()
  22. 月選_起始月_cb.Text = DateAndTime.Month(Today) : 月選_結束月_cb.Text = DateAndTime.Month(Today)
  23. 月選_起始年_cb.Text = DateAndTime.Year(Today) : 月選_結束年_cb.Text = DateAndTime.Year(Today)
  24. End Sub
  25. Private Sub 匯出EXCEL_Close(sender As Object, e As EventArgs) Handles MyBase.Closed
  26. 薪資匯出_dgv.DataSource = Nothing : ds1.Clear() : 顯示選擇月份_lb.Items.Clear()
  27. End Sub
  28. Private Sub 匯出EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.Click
  29. 判斷月差結果 = 判斷月差()
  30. If 判斷月差結果 = True Then
  31. 薪資匯出SQL_to_DGV()
  32. Dim DGV_Row_index1 As Integer = 0
  33. Dim DGV_Row_index2 As Integer = 0
  34. SaveFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv|XLS Files (*.xls)|*xls"
  35. SaveFileDialog1.FilterIndex = 1
  36. SaveFileDialog1.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
  37. SaveFileDialog1.FileName = "薪轉資料" + 薪轉Ex存檔名_tb.Text
  38. If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  39. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  40. xlApp.Visible = True
  41. xlApp.DisplayAlerts = True
  42. xlApp.Application.WindowState = xlMaximized
  43. xlBook = xlApp.Workbooks.Add(misValue)
  44. Dim twC = New System.Globalization.TaiwanCalendar()
  45. Dim DTP3 As Date = 月選_結束_dtp.Value
  46. Index_Row_Date = DTP3
  47. 民國年月_tb.Text = twC.GetYear(DTP3).ToString + DTP3.ToString("MM")
  48. 計算月數_tb.Text = DateDiff(DateInterval.Month, 月選_起始_dtp.Value, 月選_結束_dtp.Value)
  49. For index_Conut As Integer = 0 To 計算月數_tb.Text
  50. 顯示選擇月份_lb.Items.Add(民國年月_tb.Text)
  51. Dim Sheet_Row_index As Integer = 4
  52. xlSheet = NewMethod(xlBook)
  53. xlApp.Sheets(1).Name = 民國年月_tb.Text
  54. xlApp.Sheets(1).Select
  55. xlApp.Cells.NumberFormat = "@" '----------遇到數字,強迫以文字來儲存
  56. xlBook.Activate() : xlSheet.Activate()
  57. xlSheet.Range("A1").Select()
  58. xlSheet.Cells(1, 1) = "雅邸家居國際有限公司" : xlSheet.Cells(2, 1) = twC.GetYear(Index_Row_Date).ToString & " 年 " & Index_Row_Date.ToString("MM") & " 月薪資轉帳"
  59. xlSheet.Cells(3, 1) = "編號" : xlSheet.Cells(3, 2) = "帳號" : xlSheet.Cells(3, 3) = "身份證字號" : xlSheet.Cells(3, 4) = "獎金"
  60. xlSheet.Cells(3, 5) = "薪資" : xlSheet.Cells(3, 6) = "合計" : xlSheet.Cells(3, 7) = "姓名"
  61. xlSheet.Range("D4:F1000").Select() : xlApp.Selection.NumberFormatLocal = "#,##0;[紅色]-#,##0"
  62. Dim DGV_Row_Date As String = 薪資匯出_dgv(9, DGV_Row_index1).Value.ToString()
  63. Dim YY As String = Index_Row_Date.ToString("yyyy") + Index_Row_Date.ToString("/MM") + "/25"
  64. Do While String.Compare(DGV_Row_Date, YY) = 0
  65. If String.Compare(薪資匯出_dgv(10, DGV_Row_index1).Value.ToString, "帳號匯款") = 0 Then
  66. xlSheet.Cells(Sheet_Row_index, 1) = 薪資匯出_dgv(1, DGV_Row_index1).Value.ToString
  67. xlSheet.Cells(Sheet_Row_index, 2) = 薪資匯出_dgv(2, DGV_Row_index1).Value.ToString
  68. xlSheet.Cells(Sheet_Row_index, 3) = 薪資匯出_dgv(3, DGV_Row_index1).Value.ToString
  69. xlSheet.Cells(Sheet_Row_index, 4) = 薪資匯出_dgv(4, DGV_Row_index1).Value.ToString
  70. xlSheet.Cells(Sheet_Row_index, 5) = 薪資匯出_dgv(5, DGV_Row_index1).Value.ToString
  71. xlSheet.Cells(Sheet_Row_index, 6) = "=SUM(D" & Sheet_Row_index & ": E" & Sheet_Row_index & ")"
  72. xlSheet.Cells(Sheet_Row_index, 7) = 薪資匯出_dgv(8, DGV_Row_index1).Value.ToString
  73. If DGV_Row_index1 < 薪資匯出_dgv.Rows.Count - 1 Then
  74. DGV_Row_index1 = DGV_Row_index1 + 1
  75. Sheet_Row_index = Sheet_Row_index + 1
  76. ElseIf DGV_Row_index1 = 薪資匯出_dgv.Rows.Count - 1 Then
  77. Exit Do
  78. End If
  79. Else
  80. If DGV_Row_index1 < 薪資匯出_dgv.Rows.Count - 1 Then
  81. DGV_Row_index1 = DGV_Row_index1 + 1
  82. ElseIf DGV_Row_index1 = 薪資匯出_dgv.Rows.Count - 1 Then
  83. Exit Do
  84. End If
  85. End If
  86. DGV_Row_Date = 薪資匯出_dgv(9, DGV_Row_index1).Value.ToString()
  87. Loop
  88. xlSheet.Cells(Sheet_Row_index, 3) = "合計:" : xlSheet.Cells(Sheet_Row_index + 1, 3) = "領現:"
  89. xlSheet.Cells(Sheet_Row_index, 4) = "=SUM(D4: D" & (Sheet_Row_index - 1) & ")"
  90. xlSheet.Cells(Sheet_Row_index, 5) = "=SUM(E4: E" & (Sheet_Row_index - 1) & ")"
  91. xlSheet.Cells(Sheet_Row_index, 6) = "=SUM(F4: F" & (Sheet_Row_index - 1) & ")"
  92. ' 儲存格 格線設定
  93. xlSheet.Range("A1:G" & (Sheet_Row_index - 1).ToString).Select()
  94. xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  95. With xlApp.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  96. With xlApp.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  97. With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  98. With xlApp.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  99. With xlApp.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  100. With xlApp.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  101. xlSheet.Range("C" & Sheet_Row_index & ":F" & Sheet_Row_index).Select()
  102. xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone : xlApp.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
  103. With xlApp.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  104. With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  105. xlApp.Selection.Borders(xlEdgeRight).LineStyle = xlNone : xlApp.Selection.Borders(xlInsideVertical).LineStyle = xlNone : xlApp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  106. ' -------------------------------------------------------
  107. Dim Sheet_Row_index_暫存 As Integer = Sheet_Row_index
  108. Sheet_Row_index = Sheet_Row_index + 1
  109. Dim 判斷有無領現 As Boolean = False
  110. Dim ww As String = 薪資匯出_dgv(9, DGV_Row_index2).Value.ToString()
  111. Dim zz As String = Index_Row_Date.ToString("yyyy") + Index_Row_Date.ToString("/MM") + "/25"
  112. Do While String.Compare(ww, zz) = 0
  113. If String.Compare(薪資匯出_dgv(10, DGV_Row_index2).Value.ToString, "領現") = 0 Then
  114. 判斷有無領現 = True
  115. xlSheet.Cells(Sheet_Row_index, 6) = 薪資匯出_dgv(6, DGV_Row_index2).Value.ToString
  116. xlSheet.Cells(Sheet_Row_index, 7) = 薪資匯出_dgv(8, DGV_Row_index2).Value.ToString
  117. If DGV_Row_index2 < 薪資匯出_dgv.Rows.Count - 1 Then
  118. DGV_Row_index2 = DGV_Row_index2 + 1
  119. Sheet_Row_index = Sheet_Row_index + 1
  120. ElseIf DGV_Row_index2 = 薪資匯出_dgv.Rows.Count - 1 Then
  121. Sheet_Row_index = Sheet_Row_index + 1
  122. Exit Do
  123. End If
  124. Else
  125. If DGV_Row_index2 < 薪資匯出_dgv.Rows.Count - 1 Then
  126. DGV_Row_index2 = DGV_Row_index2 + 1
  127. ElseIf DGV_Row_index2 = 薪資匯出_dgv.Rows.Count - 1 Then
  128. Exit Do
  129. End If
  130. End If
  131. ww = 薪資匯出_dgv(9, DGV_Row_index2).Value.ToString()
  132. Loop
  133. xlSheet.Cells(Sheet_Row_index, 6) = "=SUM(F" & Sheet_Row_index_暫存 & ": F" & Sheet_Row_index - 1 & ")"
  134. xlSheet.Cells(Sheet_Row_index, 3) = "共計:"
  135. '加底線
  136. xlSheet.Range("F" & Sheet_Row_index - 1 & ":F" & Sheet_Row_index - 1).Select()
  137. xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone : xlApp.Selection.Borders(xlEdgeLeft).LineStyle = xlNone
  138. With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  139. xlApp.Selection.Borders(xlEdgeRight).LineStyle = xlNone : xlApp.Selection.Borders(xlInsideVertical).LineStyle = xlNone : xlApp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  140. Index_Row_Date = DateAdd(DateInterval.Month, (index_Conut + 1) * (-1), DTP3)
  141. 民國年月_tb.Text = twC.GetYear(Index_Row_Date).ToString + Index_Row_Date.ToString("MM")
  142. ' ----------------------------------
  143. '全選改變字體
  144. xlSheet.Cells.Select()
  145. With xlApp.Selection.Font : .Name = "微軟正黑體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  146. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  147. End With
  148. ' 改變行寬 Columns("A") & Columns("H")
  149. xlSheet.Columns("A:A").Select : xlApp.Selection.ColumnWidth = 8.38
  150. xlSheet.Columns("B:B").Select : xlApp.Selection.ColumnWidth = 18
  151. xlSheet.Columns("C:C").Select : xlApp.Selection.ColumnWidth = 16
  152. xlSheet.Columns("D:D").Select : xlApp.Selection.ColumnWidth = 13
  153. xlSheet.Columns("E:E").Select : xlApp.Selection.ColumnWidth = 13
  154. xlSheet.Columns("F:F").Select : xlApp.Selection.ColumnWidth = 13
  155. xlSheet.Columns("G:G").Select : xlApp.Selection.ColumnWidth = 15
  156. ' ("A1到G1") 改變粗體
  157. xlSheet.Range("A1:G3").Select()
  158. xlApp.Selection.Font.Bold = True
  159. '全選改變列高
  160. xlSheet.Cells.Select() '全選
  161. xlApp.Selection.RowHeight = 25 '改變列高
  162. xlSheet.Range("A1").Select()
  163. ' ("A1到G1")跨欄至中
  164. xlSheet.Range("A1:G1").Select()
  165. With xlApp.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  166. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  167. End With : xlApp.Selection.Merge
  168. ' ("A2到G2")跨欄至中
  169. xlSheet.Range("A2:G2").Select()
  170. With xlApp.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  171. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  172. End With : xlApp.Selection.Merge
  173. ' 儲存格顏色設定
  174. xlSheet.Range("A1:G1").Select()
  175. With xlApp.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent6 : .TintAndShade = 0.599993896298105 : .PatternTintAndShade = 0 : End With
  176. ' 儲存格顏色設定
  177. xlSheet.Range("A2:G2").Select()
  178. With xlApp.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .Color = 16247773 : .TintAndShade = 0 : .PatternTintAndShade = 0 : End With
  179. Next
  180. xlApp.Sheets(CInt(計算月數_tb.Text) + 2).Delete
  181. xlApp.Cells.Select()
  182. xlApp.Application.WindowState = xlMinimized
  183. xlSheet.SaveAs(SaveFileDialog1.FileName)
  184. xlBook.Close()
  185. xlApp.Quit()
  186. releaseObject(xlApp)
  187. releaseObject(xlBook)
  188. releaseObject(xlSheet)
  189. MessageBox.Show("存檔成功 !!!" & vbCrLf & "檔案儲存於 : " & SaveFileDialog1.FileName, "存檔資訊", MessageBoxButtons.OK, MessageBoxIcon.Information)
  190. End If
  191. 'Me.Close()
  192. Else
  193. 'MessageBox.Show("年/月 範圍選擇錯誤,請從新選擇", "範圍選擇提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  194. End If
  195. 匯出EXCEL_bt.Enabled = False
  196. End Sub
  197. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  198. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  199. End Function
  200. Private Sub releaseObject(ByVal obj As Object)
  201. Try
  202. System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
  203. obj = Nothing
  204. Catch ex As Exception
  205. obj = Nothing
  206. Finally
  207. GC.Collect()
  208. End Try
  209. End Sub
  210. Private Sub 月選_起始年_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_起始年_cb.SelectedIndexChanged
  211. DTP = (月選_起始年_cb.Text) & "/" & (月選_起始月_cb.Text) & "/01"
  212. 月選_起始_dtp.Value = DTP
  213. 月選_起始_tb.Text = Strings.Left(Strings.Format(月選_起始_dtp.Value, "yyyy/MM/dd"), 10)
  214. End Sub
  215. Private Sub 月選_起始月_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_起始月_cb.SelectedIndexChanged
  216. If 月選_起始年_cb.Text = "" Then
  217. Exit Sub
  218. Else
  219. DTP = (月選_起始年_cb.Text) & "/" & (月選_起始月_cb.Text) & "/01"
  220. 月選_起始_dtp.Value = DTP
  221. 月選_起始_tb.Text = Strings.Left(Strings.Format(月選_起始_dtp.Value, "yyyy/MM/dd"), 10)
  222. End If
  223. End Sub
  224. Private Sub 月選_結束年_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_結束年_cb.SelectedIndexChanged
  225. DTP = (月選_結束年_cb.Text) & "/" & (月選_結束月_cb.Text) & "/01"
  226. 月選_結束_dtp.Value = DTP
  227. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddMonths(1)
  228. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddDays(-1)
  229. 月選_結束_tb.Text = Strings.Left(Strings.Format(月選_結束_dtp.Value, "yyyy/MM/dd"), 10)
  230. End Sub
  231. Private Sub 月選_結束月_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 月選_結束月_cb.SelectedIndexChanged
  232. If 月選_起始年_cb.Text = "" Then
  233. Exit Sub
  234. Else
  235. DTP = (月選_結束年_cb.Text) & "/" & (月選_結束月_cb.Text) & "/01"
  236. 月選_結束_dtp.Value = DTP
  237. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddMonths(1)
  238. 月選_結束_dtp.Value = 月選_結束_dtp.Value.AddDays(-1)
  239. 月選_結束_tb.Text = Strings.Left(Strings.Format(月選_結束_dtp.Value, "yyyy/MM/dd"), 10)
  240. End If
  241. End Sub
  242. Private Sub 結束減一個月_bt_Click(sender As Object, e As EventArgs) Handles 結束減一個月_bt.Click
  243. If 月選_結束月_cb.Text <> "1" Then
  244. 月選_結束月_cb.Text = Val(月選_結束月_cb.Text) - 1
  245. ElseIf 月選_結束月_cb.Text = "1" Then
  246. 月選_結束月_cb.Text = 12
  247. 月選_結束年_cb.Text = Val(月選_結束年_cb.Text) - 1
  248. End If
  249. End Sub
  250. Private Sub 結束加一個月_bt_Click(sender As Object, e As EventArgs) Handles 結束加一個月_bt.Click
  251. If 月選_結束月_cb.Text <> "12" Then
  252. 月選_結束月_cb.Text = Val(月選_結束月_cb.Text) + 1
  253. ElseIf 月選_結束月_cb.Text = "12" Then
  254. 月選_結束月_cb.Text = 1
  255. 月選_結束年_cb.Text = Val(月選_結束年_cb.Text) + 1
  256. End If
  257. End Sub
  258. Private Sub 起始減一個月_bt_Click(sender As Object, e As EventArgs) Handles 起始減一個月_bt.Click
  259. If 月選_起始月_cb.Text <> "1" Then
  260. 月選_起始月_cb.Text = Val(月選_起始月_cb.Text) - 1
  261. ElseIf 月選_起始月_cb.Text = "1" Then
  262. 月選_起始月_cb.Text = 12
  263. 月選_起始年_cb.Text = Val(月選_起始年_cb.Text) - 1
  264. End If
  265. End Sub
  266. Private Sub 起始加一個月_bt_Click(sender As Object, e As EventArgs) Handles 起始加一個月_bt.Click
  267. If 月選_起始月_cb.Text <> "12" Then
  268. 月選_起始月_cb.Text = Val(月選_起始月_cb.Text) + 1
  269. ElseIf 月選_起始月_cb.Text = "12" Then
  270. 月選_起始月_cb.Text = 1
  271. 月選_起始年_cb.Text = Val(月選_起始年_cb.Text) + 1
  272. End If
  273. End Sub
  274. Private Function 判斷月差() As Boolean
  275. Dim 判斷結果 As Boolean
  276. If DateDiff(DateInterval.Month, 月選_起始_dtp.Value, 月選_結束_dtp.Value) > 119 Then
  277. 月選_起始月_cb.Text = DateAndTime.Month(Today) : 月選_結束月_cb.Text = DateAndTime.Month(Today)
  278. 月選_起始年_cb.Text = DateAndTime.Year(Today) : 月選_結束年_cb.Text = DateAndTime.Year(Today)
  279. 判斷結果 = False
  280. MsgBox("選擇範圍超過10年,請從新選擇", MsgBoxStyle.Information, "提示")
  281. ElseIf DateDiff(DateInterval.Month, 月選_起始_dtp.Value, 月選_結束_dtp.Value) < 0 Then
  282. 月選_起始月_cb.Text = DateAndTime.Month(Today) : 月選_結束月_cb.Text = DateAndTime.Month(Today)
  283. 月選_起始年_cb.Text = DateAndTime.Year(Today) : 月選_結束年_cb.Text = DateAndTime.Year(Today)
  284. 判斷結果 = False
  285. MsgBox("選擇範圍年分順序顛倒,請從新選擇", MsgBoxStyle.Information, "提示")
  286. Else
  287. 判斷結果 = True
  288. End If
  289. Return 判斷結果
  290. End Function
  291. Private Sub 薪資匯出SQL_to_DGV()
  292. 薪資匯出_dgv.DataSource = Nothing : ds1.Clear()
  293. 薪資匯出_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  294. 薪資匯出_dgv.ColumnHeadersHeight = 40 : 薪資匯出_dgv.AllowUserToAddRows = False
  295. str01 = "" : Dim DTP3 As Date = 月選_結束_dtp.Value
  296. 計算月數_tb.Text = DateDiff(DateInterval.Month, 月選_起始_dtp.Value, 月選_結束_dtp.Value)
  297. str01 = Strings.Left(Strings.Format(月選_結束_dtp.Value, "yyyy/MM/dd"), 7) + "/25"
  298. 薪資轉帳表_匯出EXCEL_月份清單(str01)
  299. da.Fill(ds1) : 薪資匯出_dgv.DataSource = ds1.Tables(0) : conn.Close()
  300. 薪資匯出_dgv.Columns("獎金").DefaultCellStyle.Format = "#,##0.0"
  301. 薪資匯出_dgv.Columns("薪資").DefaultCellStyle.Format = "#,##0.0"
  302. 薪資匯出_dgv.Columns("薪資合計").DefaultCellStyle.Format = "#,##0.0"
  303. 薪資匯出_dgv.Columns("領現").DefaultCellStyle.Format = "#,##0.0"
  304. For index_Conut As Integer = 0 To 計算月數_tb.Text
  305. 'ListBox1.Items.Add(str01)
  306. Index_Row_Date = DateAdd(DateInterval.Month, (index_Conut + 1) * (-1), DTP3)
  307. str01 = Strings.Left(Strings.Format(Index_Row_Date, "yyyy/MM/dd"), 7) + "/25"
  308. 薪資轉帳表_匯出EXCEL_月份清單(str01)
  309. da.Fill(ds1) : 薪資匯出_dgv.DataSource = ds1.Tables(0) : conn.Close()
  310. Next
  311. 薪資匯出_dgv.Columns(0).Visible = False : 薪資匯出_dgv.Columns(10).Visible = True : 薪資匯出_dgv.Columns(11).Visible = False
  312. 薪資匯出_dgv.Columns(0).ReadOnly = True : 薪資匯出_dgv.Columns(1).ReadOnly = True : 薪資匯出_dgv.Columns(2).ReadOnly = True : 薪資匯出_dgv.Columns(3).ReadOnly = True
  313. 薪資匯出_dgv.Columns(4).ReadOnly = True : 薪資匯出_dgv.Columns(5).ReadOnly = True : 薪資匯出_dgv.Columns(6).ReadOnly = True : 薪資匯出_dgv.Columns(7).ReadOnly = True
  314. 薪資匯出_dgv.Columns(8).ReadOnly = True : 薪資匯出_dgv.Columns(9).ReadOnly = True
  315. End Sub
  316. End Class