Moikka,
Voisko joku antaa pienen koodi vinkin miten saan vietyä formin texti kentistä tiedot excelin määrättyihin soluihin?
esim käyttämällä Microsoft.Office.Interop.Excel
tarttis saada niinku vietyä tietoa esim. worksheet2 A sarakkeen 15 riville tieto textbox1.text kentästä ja jostain toisesta text boxista sit taas vaikka B19 ja näin eteenpäin.
Kiitos jo etukäteen.
T.mika
Moikka Huh-hellettä!
tässä pieni esimerkki...
'väännetty SharpDevelop 4.0 Beta 2:lla
Imports System.Diagnostics
Imports Excel = Microsoft.Office.Interop.Excel
Public Partial Class MainForm
Private xlapp As Excel.Application = Nothing
Private xlbook As Excel.Workbook = Nothing
Private xlsheet As Excel.Worksheet = Nothing
Public Sub New()
Me.InitializeComponent()
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
KillExcelProcesses
Dim basePath As String = Environment.GetFolderPath( _
Environment.SpecialFolder.Desktop)
Dim fileName As String = "testi.xls"
Dim fullPath As String = basePath + "\" + fileName
If Dir(fullPath) <> "" Then
xlapp = New Excel.Application
xlbook = CType(xlapp.Workbooks.Open( _
fullPath), Excel.Workbook)
xlsheet = CType(xlBook.Worksheets(2), _
Excel.Worksheet)
xlsheet.Application.Visible = False
Else
If MessageBox.Show("Tiedostoa " + _
fullPath + " ei löydy!" + _
Environment.NewLine + _
"Luodaanko uusi työkirja " + fileName, _
Me.Text, MessageBoxButtons.YesNo, _
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly) _
= MsgBoxResult.Yes Then
xlapp = New Excel.Application
xlbook = CType(xlapp.Workbooks.Add( _
Type.Missing), Excel.Workbook)
xlbook.SaveAs(fullPath)
xlsheet = CType(xlBook.Worksheets(2), _
Excel.Worksheet)
xlsheet.Application.Visible = False
End If
End If
End Sub
Sub Button1Click(sender As Object, e As EventArgs)
If xlsheet IsNot Nothing Then
xlsheet.Range("A15").Value = textBox1.Text
xlsheet.Range("B19").Value = textBox2.Text
xlapp.DisplayAlerts = False
xlbook.Save
End If
End Sub
Sub KillExcelProcesses()
Dim xlProcess As Process() _
= Process.GetProcessesByName("Excel")
If Not xlProcess Is Nothing Then
For i As Integer = 0 To xlProcess.GetUpperBound(0)
Try
xlProcess(i).Kill()
Catch ex As Exception
End try
Next
End If
xlProcess = Nothing
End Sub
Sub MainFormFormClosing(sender As Object, e As FormClosingEventArgs)
KillExcelProcesses
xlsheet = Nothing
xlbook = Nothing
xlapp = Nothing
End Sub
End ClassKiitos tuhannesti, pitää testata ja muokata sopivaksi
T:Mika
Aihe on jo aika vanha, joten et voi enää vastata siihen.