Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
- On Error Resume Next
- Dim oExcel As Object
- Dim oBook As Object
- Dim oSheet As Object
- On Error Resume Next
- oExcel = CreateObject("Excel.Application")
- oBook = oExcel.Workbooks.Add
- Dim DataArray(DataGridView1.Rows.Count, DataGridView1.Columns.Count - 1) As Object
- Dim head(DataGridView1.Columns.Count) As Object
- For x As Integer = 0 To DataGridView1.Columns.Count - 1
- head(x) = DataGridView1.Columns(x).Name
- Next
- For y As Integer = 0 To DataGridView1.Rows.Count
- For x As Integer = 0 To DataGridView1.Columns.Count - 1
- DataArray(y + 1, x) = DataGridView1.Rows(y).Cells(x).Value
- Next
- Next
- oSheet = oBook.Worksheets(1)
- oSheet.Range("E1").value = "Palawan State University"
- oSheet.Range("E2").value = "College of Nursing and Health Sciences"
- oSheet.Range("E3").value = "Stock Room Inventory Report - Apparatuses"
- oSheet.Range("E4").value = "For the Month of " & MonthName(Date.Now.Month) & " " & Date.Now.Year
- For x As Integer = 0 To DataGridView1.Columns.Count - 1
- oSheet.Range(Chr(65 + x).ToString & (6).ToString).value = head(x)
- Next
- For y As Integer = 0 To DataGridView1.Rows.Count
- For x As Integer = 0 To DataGridView1.Columns.Count - 1
- oSheet.Range(Chr(65 + x).ToString & (y + 7).ToString).value = DataArray(y, x)
- namengtanga = (y + 7)
- Next
- Next
- oSheet.range("F" & namengtanga + 1).value = "Total Cost = " & totalnglahat.Text & ""
- oSheet.range("E" & namengtanga + 3).value = "Prepared by:"
- oSheet.range("E" & namengtanga + 5).value = "Ms. Cristine Mae Panganiban"
- oSheet.range("E" & namengtanga + 6).value = "Laboratory Aid"
- oBook.SaveAs("C:\Users\user\Desktop\CNHS-ApparatusInventory.xls")
- oSheet = Nothing
- oBook = Nothing
- oExcel.Quit()
- oExcel = Nothing
- GC.Collect()
- Dim myProcess As New Process()
- myProcess.StartInfo.FileName = "C:\Users\user\Desktop\CNHS-ApparatusInventory.xls"
- 'myProcess.StartInfo.Verb = "Print"
- 'myProcess.StartInfo.CreateNoWindow = True
- myProcess.Start()
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement