Pa ja sam nesto radila... medjutim nesto je tu zbrkano..
Naravno prvo sam dodala referencu na excel.
Evo koda:
Code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlapp As Excel.Application
Dim xlwrk As Excel.Workbook
Dim xlsht As Excel.Worksheet
xlapp = New Excel.Application
xlwrk = xlapp.Workbooks.Open("E:\Documents and Settings\Administrator\Desktop\Za formu.xls")
xlsht = xlwrk.Worksheets(1)
xlsht.Cells(2, 1) = TextBox1.Text
xlwrk.SaveAs()
xlwrk.Close()
End Sub
End Class
Ali, radi on to, samo sto mi tu gde je smesten projekat napravi excel file pod istim, ali potpuno istim nazivom "Za formu", znaci, ne puni ovaj na desctop-u, vec kreira novi. Probaj.. E, sad, to je jedan problem, a drugi je: kako da napracim da kada kliknem na to dugme: Button1, on smesti to iz TextBox12 u prvu praznu celiju u A redu a iz Text Box2 u prvu praznu u B redu i da mi po kliku na dugme ocisti textBox-ove za novi unos?
Probala sam ovako:
Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlapp As Excel.Application
Dim Dest As Excel.Range
Dim rwA As Object 'mada probala sam da stavim i Excel.Range i Integer, jer to je red i ne znam bas kako ga pravilno deklarisati
Dim rwB As Object 'mada probala sam da stavim i Excel.Range i Integer, jer to je red i ne znam bas kako ga pravilno deklarisati
Dim xlUp As Excel.Range
Dim xlwrk As Excel.Workbook
Dim xlsht As Excel.Worksheet
xlapp = New Excel.Application
xlwrk = xlapp.Workbooks.Open("E:\Documents and Settings\Administrator\Desktop\Za formu.xls")
xlsht = xlwrk.Worksheets(1)
rwA = xlwrk.Sheets(1).Range("A65536").End(xlUp).Row + 1
Dest = xlwrk.Sheets(1).Cells(rwA, 1)
Dest.Value = TextBox1.Text
rwB = xlwrk.Sheets(1).Range("B65536").End(xlUp).Row + 1
Dest = xlwrk.Sheets(1).Cells(rwB, 1)
Dest.Value = TextBox2.Text
xlwrk.SaveAs()
xlwrk.Close()
End Sub
End Class
Izbacuje ovu gresku:
"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in system.windows.forms.dll
Additional information: Exception from HRESULT: 0x800A03EC."
Jednom recju.... Pomagaj!
[Ovu poruku je menjao tasman_76_82 dana 04.11.2006. u 02:37 GMT+1]
[Ovu poruku je menjao krckoorascic dana 04.11.2006. u 17:14 GMT+1]
[Ovu poruku je menjao Shadowed dana 05.11.2006. u 12:28 GMT+1]