Imports Microsoft.Office.Interop
Public Class Form2
Private Property newinfo As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim lastRow As Long
Dim FILE_NAME As String = "C:\Users\Galamba\Documents\Visual Studio 2010\"
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(FILE_NAME)
xlWorksheet = xlWorkBook.Sheets.Item(1)
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(TextBox1.Text)
objWriter.Close()
MsgBox("Completo")
Else
MsgBox("Efectuado com sucesso")
End If
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("C:\Users\Galamba\Documents\Visual Studio 2010\Livro")
xlWorksheet = xlWorkBook.Worksheets(1)
xlApp.Visible = False
lastRow = xlWorksheet.Range("A" & xlApp.Rows.CountLarge).End(Excel.XlDirection.xlUp).Row + 1
With xlWorksheet
.Range("A1").Value = "Nº Processo Auto"
.Range("A1").ColumnWidth = 20
.Range("B1").Value = "Data de inserção"
.Range("B1").ColumnWidth = 20
.Range("C1").Value = "Número do oficio"
.Range("C1").ColumnWidth = 20
.Range("D1").Value = "Matricula"
.Range("D1").ColumnWidth = 20
.Range("E1").Value = "Hora"
.Range("E1").ColumnWidth = 20
.Range("F1").Value = "Data Multa"
.Range("F1").ColumnWidth = 20
.Range("G1").Value = "Montante"
.Range("G1").ColumnWidth = 20
.Range("H1").Value = "Data notificação"
.Range("H1").ColumnWidth = 20
.Range("A" & lastRow).Value = Me.TextBox1.Text
.Range("B" & lastRow).Value = Me.TextBox2.Text
.Range("C" & lastRow).Value = Me.TextBox3.Text
.Range("D" & lastRow).Value = Me.TextBox4.Text
.Range("E" & lastRow).Value = Me.TextBox5.Text
.Range("F" & lastRow).Value = Me.TextBox6.Text
.Range("G" & lastRow).Value = Me.TextBox7.Text
.Range("H" & lastRow).Value = Me.TextBox8.Text
End With
xlWorkBook.SaveAs("Processo")
xlWorkBook.Close()
releaseObject(xlWorkBook)
releaseObject(xlWorksheet)
xlApp.Quit()
releaseObject(xlApp)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Public Class Form2
Private Property newinfo As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim lastRow As Long
Dim FILE_NAME As String = "C:\Users\Galamba\Documents\Visual Studio 2010\"
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(FILE_NAME)
xlWorksheet = xlWorkBook.Sheets.Item(1)
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(TextBox1.Text)
objWriter.Close()
MsgBox("Completo")
Else
MsgBox("Efectuado com sucesso")
End If
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("C:\Users\Galamba\Documents\Visual Studio 2010\Livro")
xlWorksheet = xlWorkBook.Worksheets(1)
xlApp.Visible = False
lastRow = xlWorksheet.Range("A" & xlApp.Rows.CountLarge).End(Excel.XlDirection.xlUp).Row + 1
With xlWorksheet
.Range("A1").Value = "Nº Processo Auto"
.Range("A1").ColumnWidth = 20
.Range("B1").Value = "Data de inserção"
.Range("B1").ColumnWidth = 20
.Range("C1").Value = "Número do oficio"
.Range("C1").ColumnWidth = 20
.Range("D1").Value = "Matricula"
.Range("D1").ColumnWidth = 20
.Range("E1").Value = "Hora"
.Range("E1").ColumnWidth = 20
.Range("F1").Value = "Data Multa"
.Range("F1").ColumnWidth = 20
.Range("G1").Value = "Montante"
.Range("G1").ColumnWidth = 20
.Range("H1").Value = "Data notificação"
.Range("H1").ColumnWidth = 20
.Range("A" & lastRow).Value = Me.TextBox1.Text
.Range("B" & lastRow).Value = Me.TextBox2.Text
.Range("C" & lastRow).Value = Me.TextBox3.Text
.Range("D" & lastRow).Value = Me.TextBox4.Text
.Range("E" & lastRow).Value = Me.TextBox5.Text
.Range("F" & lastRow).Value = Me.TextBox6.Text
.Range("G" & lastRow).Value = Me.TextBox7.Text
.Range("H" & lastRow).Value = Me.TextBox8.Text
End With
xlWorkBook.SaveAs("Processo")
xlWorkBook.Close()
releaseObject(xlWorkBook)
releaseObject(xlWorksheet)
xlApp.Quit()
releaseObject(xlApp)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class