Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.41 KB | None | 0 0
  1. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  2.         On Error Resume Next
  3.         Dim oExcel As Object
  4.         Dim oBook As Object
  5.         Dim oSheet As Object
  6.         On Error Resume Next
  7.         oExcel = CreateObject("Excel.Application")
  8.         oBook = oExcel.Workbooks.Add
  9.  
  10.         Dim DataArray(DataGridView1.Rows.Count, DataGridView1.Columns.Count - 1) As Object
  11.         Dim head(DataGridView1.Columns.Count) As Object
  12.         For x As Integer = 0 To DataGridView1.Columns.Count - 1
  13.             head(x) = DataGridView1.Columns(x).Name
  14.         Next
  15.  
  16.         For y As Integer = 0 To DataGridView1.Rows.Count
  17.             For x As Integer = 0 To DataGridView1.Columns.Count - 1
  18.                 DataArray(y + 1, x) = DataGridView1.Rows(y).Cells(x).Value
  19.             Next
  20.         Next
  21.  
  22.         oSheet = oBook.Worksheets(1)
  23.         oSheet.Range("E1").value = "Palawan State University"
  24.         oSheet.Range("E2").value = "College of Nursing and Health Sciences"
  25.         oSheet.Range("E3").value = "Stock Room Inventory Report - Apparatuses"
  26.         oSheet.Range("E4").value = "For the Month of " & MonthName(Date.Now.Month) & " " & Date.Now.Year
  27.  
  28.         For x As Integer = 0 To DataGridView1.Columns.Count - 1
  29.             oSheet.Range(Chr(65 + x).ToString & (6).ToString).value = head(x)
  30.         Next
  31.         For y As Integer = 0 To DataGridView1.Rows.Count
  32.             For x As Integer = 0 To DataGridView1.Columns.Count - 1
  33.                 oSheet.Range(Chr(65 + x).ToString & (y + 7).ToString).value = DataArray(y, x)
  34.                 namengtanga = (y + 7)
  35.             Next
  36.         Next
  37.         oSheet.range("F" & namengtanga + 1).value = "Total Cost = " & totalnglahat.Text & ""
  38.         oSheet.range("E" & namengtanga + 3).value = "Prepared by:"
  39.         oSheet.range("E" & namengtanga + 5).value = "Ms. Cristine Mae Panganiban"
  40.         oSheet.range("E" & namengtanga + 6).value = "Laboratory Aid"
  41.  
  42.         oBook.SaveAs("C:\Users\user\Desktop\CNHS-ApparatusInventory.xls")
  43.         oSheet = Nothing
  44.         oBook = Nothing
  45.         oExcel.Quit()
  46.         oExcel = Nothing
  47.         GC.Collect()
  48.         Dim myProcess As New Process()
  49.         myProcess.StartInfo.FileName = "C:\Users\user\Desktop\CNHS-ApparatusInventory.xls"
  50.         'myProcess.StartInfo.Verb = "Print"
  51.         'myProcess.StartInfo.CreateNoWindow = True
  52.         myProcess.Start()
  53.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement