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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. Public Class 列印_供應商資料表
  11. Private ReadOnly ds As New DataSet
  12. Dim N2 As Integer
  13. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  14. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  15. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  16. Private Sub Set_清單()
  17. DataGridView1.DataSource = Nothing : ds.Clear()
  18. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  19. DataGridView1.ColumnHeadersHeight = 25
  20. DataGridView1.AllowUserToAddRows = False
  21. ConnOpen()
  22. SQL1 = 列印用SQL
  23. CmdSet_For_DGV()
  24. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  25. End Sub
  26. Private Sub Set_格式設定()
  27. DataGridView1.Visible = False
  28. End Sub
  29. Private Sub 列印_供應商資料表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  30. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  31. Set_清單() : Set_格式設定()
  32. End Sub
  33. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  34. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  35. xlBook = xlApp.Workbooks.Add
  36. xlApp.DisplayAlerts = True
  37. xlBook.Activate()
  38. xlSheet = NewMethod(xlBook)
  39. xlSheet.Activate()
  40. xlApp.Visible = True
  41. xlApp.Application.WindowState = xlMaximized
  42. xlSheet.Cells(1, 1) = "巨益貿易-供應商資料表" : xlSheet.Cells(2, 1) = "供應商編碼" : xlSheet.Cells(2, 2) = "供應商簡稱" : xlSheet.Cells(2, 3) = "公司名" : xlSheet.Cells(2, 4) = "公司地址"
  43. xlSheet.Cells(2, 5) = "公司電話1" : xlSheet.Cells(2, 6) = "公司電話2" : xlSheet.Cells(2, 7) = "公司電話3" : xlSheet.Cells(2, 8) = "公司傳真1" : xlSheet.Cells(2, 9) = "公司傳真2"
  44. xlSheet.Cells(2, 10) = "廠商類別" : xlSheet.Cells(2, 11) = "聯繫人1" : xlSheet.Cells(2, 12) = "聯繫人2" : xlSheet.Cells(2, 13) = "聯繫人3" : xlSheet.Cells(2, 14) = "聯繫人1職稱"
  45. xlSheet.Cells(2, 15) = "聯繫人2職稱" : xlSheet.Cells(2, 16) = "聯繫人3職稱" : xlSheet.Cells(2, 17) = "聯繫人1電話" : xlSheet.Cells(2, 18) = "聯繫人2電話" : xlSheet.Cells(2, 19) = "聯繫人3電話"
  46. xlSheet.Cells(2, 20) = "聯繫人1郵箱" : xlSheet.Cells(2, 21) = "聯繫人2郵箱" : xlSheet.Cells(2, 22) = "聯繫人3郵箱"
  47. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  48. xlSheet.Cells(i + 3, 1) = DataGridView1.Rows(i).Cells("供應商編碼").Value : xlSheet.Cells(i + 3, 2) = DataGridView1.Rows(i).Cells("廠商").Value
  49. xlSheet.Cells(i + 3, 3) = DataGridView1.Rows(i).Cells("公司名").Value : xlSheet.Cells(i + 3, 4) = DataGridView1.Rows(i).Cells("公司地址").Value
  50. xlSheet.Cells(i + 3, 5) = DataGridView1.Rows(i).Cells("公司電話1").Value : xlSheet.Cells(i + 3, 6) = DataGridView1.Rows(i).Cells("公司電話2").Value
  51. xlSheet.Cells(i + 3, 7) = DataGridView1.Rows(i).Cells("公司電話3").Value : xlSheet.Cells(i + 3, 8) = DataGridView1.Rows(i).Cells("公司傳真1").Value
  52. xlSheet.Cells(i + 3, 9) = DataGridView1.Rows(i).Cells("公司傳真2").Value : xlSheet.Cells(i + 3, 10) = DataGridView1.Rows(i).Cells("公司傳真3").Value
  53. xlSheet.Cells(i + 3, 11) = DataGridView1.Rows(i).Cells("聯繫人1").Value : xlSheet.Cells(i + 3, 12) = DataGridView1.Rows(i).Cells("聯繫人2").Value
  54. xlSheet.Cells(i + 3, 13) = DataGridView1.Rows(i).Cells("聯繫人3").Value : xlSheet.Cells(i + 3, 14) = DataGridView1.Rows(i).Cells("聯繫人1職稱").Value
  55. xlSheet.Cells(i + 3, 15) = DataGridView1.Rows(i).Cells("聯繫人2職稱").Value : xlSheet.Cells(i + 3, 16) = DataGridView1.Rows(i).Cells("聯繫人3職稱").Value
  56. xlSheet.Cells(i + 3, 17) = DataGridView1.Rows(i).Cells("聯繫人1電話").Value : xlSheet.Cells(i + 3, 18) = DataGridView1.Rows(i).Cells("聯繫人2電話").Value
  57. xlSheet.Cells(i + 3, 19) = DataGridView1.Rows(i).Cells("聯繫人3電話").Value : xlSheet.Cells(i + 3, 20) = DataGridView1.Rows(i).Cells("聯繫人1郵箱").Value
  58. xlSheet.Cells(i + 3, 21) = DataGridView1.Rows(i).Cells("聯繫人2郵箱").Value : xlSheet.Cells(i + 3, 22) = DataGridView1.Rows(i).Cells("聯繫人3郵箱").Value
  59. With xlApp.Selection
  60. .Font.Bold = True
  61. End With
  62. N2 = i + 3
  63. Next i
  64. BB(xlApp, xlSheet)
  65. xlSheet.PageSetup.PrintArea = ""
  66. xlApp.Cells.Select()
  67. xlSheet.Range("B1").Select()
  68. xlApp.Application.WindowState = xlMinimized
  69. MsgBox("列印完成")
  70. Me.Close()
  71. End Sub
  72. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  73. 列印用SQL = "" : Me.Close()
  74. End Sub
  75. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  76. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  77. End Function
  78. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  79. Dim 位置1 As String
  80. xlSheet.Cells.Select()
  81. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  82. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  83. xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 30 : xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 20
  84. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 10 : xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 17
  85. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 30 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 60
  86. xlSheet.Columns("E:S").Select : myExcel.Selection.ColumnWidth = 12 : xlSheet.Columns("T:V").Select : myExcel.Selection.ColumnWidth = 30
  87. xlSheet.Range("D3").Select() : myExcel.ActiveWindow.FreezePanes = True
  88. xlSheet.Range("A1:C1").Select()
  89. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  90. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  91. xlSheet.Range("A1:C1").Select()
  92. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  93. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  94. 位置1 = "A2:V" & N2 : xlSheet.Range(位置1).Select()
  95. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  96. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  97. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  98. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  99. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  100. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  101. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  102. xlSheet.Range("A2:V2").Select()
  103. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2 : .TintAndShade = 0.799981688894314
  104. .PatternTintAndShade = 0 : End With
  105. xlSheet.Range("P12").Select()
  106. myExcel.ActiveWindow.DisplayGridlines = False
  107. End Sub
  108. End Class