Hola buenas con todos, queria ayuda sobre este codigo que tengo lo que pasa que quisiera que los datos de listview se copien o transfieran al excel pero a un rango de celda especifico
aqui el codigo
desde ya muchas gracias
Public Class Form1
Dim cn As New OleDb.OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim da As New OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim dataset As DataSet
Sub llenarListview()
End Sub
Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'cuando el formulario carga crear la conexion , notese que el string de conexion se edita de forma manual.
llenarListview()
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\SISTEMAS-MONITOREO\Desktop\visual\BDACC\datos.xlsx;Extended Properties=Excel 12.0"
Dim sql = "select * from [Hoja1$]"
da = New OleDb.OleDbDataAdapter(sql, cn)
da.Fill(dt)
'llenar el listwiev
For i = 0 To dt.Rows.Count - 1
ListView1.Items.Add(dt.Rows(i).Item(0))
ListView1.Items(i).SubItems.Add(dt.Rows(i).Item(1))
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'agrega en la BD
cn.Open()
cm.Connection = cn
cm.CommandText = "insert into [Hoja1$]values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
cm.ExecuteNonQuery()
'Agrega en el list view
Dim indice As Integer = ListView1.Items.Count
ListView1.Items.Add(TextBox1.Text) 'agrega una fila nueva
ListView1.Items(indice).SubItems.Add(TextBox2.Text)
ListView1.Items(indice).SubItems.Add(TextBox3.Text) ' agrega una columna nueva en la fila creada
cn.Close()
End Sub
End Class
aqui el codigo
desde ya muchas gracias
Public Class Form1
Dim cn As New OleDb.OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim da As New OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim dataset As DataSet
Sub llenarListview()
End Sub
Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'cuando el formulario carga crear la conexion , notese que el string de conexion se edita de forma manual.
llenarListview()
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\SISTEMAS-MONITOREO\Desktop\visual\BDACC\datos.xlsx;Extended Properties=Excel 12.0"
Dim sql = "select * from [Hoja1$]"
da = New OleDb.OleDbDataAdapter(sql, cn)
da.Fill(dt)
'llenar el listwiev
For i = 0 To dt.Rows.Count - 1
ListView1.Items.Add(dt.Rows(i).Item(0))
ListView1.Items(i).SubItems.Add(dt.Rows(i).Item(1))
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'agrega en la BD
cn.Open()
cm.Connection = cn
cm.CommandText = "insert into [Hoja1$]values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
cm.ExecuteNonQuery()
'Agrega en el list view
Dim indice As Integer = ListView1.Items.Count
ListView1.Items.Add(TextBox1.Text) 'agrega una fila nueva
ListView1.Items(indice).SubItems.Add(TextBox2.Text)
ListView1.Items(indice).SubItems.Add(TextBox3.Text) ' agrega una columna nueva en la fila creada
cn.Close()
End Sub
End Class