Advertisement
Guest User

Excel.Style yg Berhasil di VB .NET 2010 & Excel 2010

a guest
Feb 11th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.55 KB | None | 0 0
  1. Imports Excel = Microsoft.Office.Interop.Excel
  2.  
  3. Imports Microsoft.Office
  4.  
  5. Public Class Form1
  6.  
  7.     Dim appXL As Excel.Application = Nothing
  8.  
  9.     Dim wbXL As Excel.Workbook = Nothing
  10.  
  11.     Dim shXL As Excel.Worksheet = Nothing
  12.  
  13.     Dim raXL As Excel.Range = Nothing
  14.  
  15.     Dim style As Microsoft.Office.Interop.Excel.Style
  16.  
  17.  
  18.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  19.  
  20.         'Membuat workbook
  21.         appXL = CreateObject("Excel.Application")
  22.  
  23.         appXL.Visible = True
  24.  
  25.         wbXL = appXL.Workbooks.Add
  26.  
  27.         shXL = wbXL.Sheets("Sheet2")
  28.  
  29.         shXL.Activate()
  30.  
  31.         Exit Sub
  32.  
  33.  
  34.  
  35.  
  36. Err_Handler:
  37.  
  38.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
  39.  
  40.  
  41.     End Sub
  42.  
  43.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
  44.  
  45.         'Menutup WorkBook
  46.  
  47.         raXL = Nothing
  48.  
  49.         shXL = Nothing
  50.  
  51.         wbXL = Nothing
  52.  
  53.         appXL.Quit()
  54.  
  55.         appXL = Nothing
  56.     End Sub
  57.  
  58.     Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  59.  
  60.         'Menerapkan style
  61.  
  62.         style = wbXL.Styles.Add("Style1")
  63.  
  64.         style.NumberFormat = "Text"
  65.  
  66.         style.Font.Name = "Arial"
  67.  
  68.         style.Font.Bold = True
  69.  
  70.         style.Font.Size = 5
  71.  
  72.         style.Interior.Pattern = Microsoft.Office.Interop.Excel.XlPattern.xlPatternSolid
  73.  
  74.  
  75.         shXL.Cells(1, 1) = "repairing car"
  76.  
  77.         shXL.Cells(1, 1).Style = "Style1"
  78.  
  79.  
  80.  
  81.     End Sub
  82. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement