IMPORT EXCEL TO LISTVIEW
Alguem tem algum exemplo de como importar somente 2 colunas de um arquivo excel que tem 3 colunas? Ja pesquisei e nada....
KURTGU,
é +/- isso que você quer?
=====================================================================
[Resolvido] Importar Dados do Excel para DataGridView
http://forum.imasters.com.br/topic/387377-resolvidoimportar-dados-do-excel-para-datagridview/
=====================================================================
[][ô]s,
Tunusat.
é +/- isso que você quer?
=====================================================================
[Resolvido] Importar Dados do Excel para DataGridView
http://forum.imasters.com.br/topic/387377-resolvidoimportar-dados-do-excel-para-datagridview/
=====================================================================
[][ô]s,
Tunusat.
Tunusat tentei utilizar este exemplo mais não consegui...
Você já tentou abrir o excel como fonte de dados? http://www.connectionstrings.com/excel/
KerpLunk da pra fazer select usando Excel?
Sim, você abre o excel como se fosse um banco de dados qualquer, faz select, insert, update... até joins se quiser. Use a connectionstring do site que passei, você vai abrir o excel como se fosse um banco de dados qualquer.
Vou ver se consigo fazer algo....
Pessoal da um help ai....Consegui fazer ler seguindo um tutorial, mais nao consigo mudar a sequencia das colunas....
Imports Microsoft.Office.Interop
Public Class Form1
Private Structure ExcelRows
Dim C1 As String
Dim C2 As String
Dim C3 As String
Dim C4 As String
End Structure
Private ExcelRowsList As List(Of ExcelRows) = New List(Of ExcelRows)
Public Property Sorting As SortOrder
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.OpenFileDialog1.FileName = Nothing
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.TextBox1.Text = Me.OpenFileDialog1.FileName
End If
If GetInfo() = True Then
For Each Xitem In ExcelRowsList
Dim lvitem As ListViewItem
lvitem = Me.ListView1.Items.Add(Xitem.C1)
lvitem.SubItems.AddRange(New String() {Xitem.C2, Xitem.C3})
Label1.Text = ListView1.Items.Count
ListView1.Sorting = SortOrder.Ascending
Next
End If
End Sub
Private Function GetInfo() As Boolean
Dim completed As Boolean = False
[ô]OPEN
Dim myExcel As New Excel.Application
myExcel.Workbooks.Open(Me.TextBox1.Text)
[ô]EXTRACT
myExcel.Sheets([Ô]Acolhimento - CG SUL PN CONSULT[Ô]).Activate()
myExcel.Range([Ô]A2[Ô]).Activate()
Dim ThisRow As New ExcelRows
Do
If myExcel.ActiveCell.Value > Nothing Or myExcel.ActiveCell.Text > Nothing Then
ThisRow.C1 = myExcel.ActiveCell.Value
myExcel.ActiveCell.Offset(0, 1).Activate()
ThisRow.C2 = myExcel.ActiveCell.Value
myExcel.ActiveCell.Offset(0, 1).Activate()
ThisRow.C3 = myExcel.ActiveCell.Value
myExcel.ActiveCell.Offset(0, 1).Activate()
ExcelRowsList.Add(ThisRow)
myExcel.ActiveCell.Offset(1, -14).Activate()
Else
completed = True
Exit Do
End If
Loop
[ô]CLOSE
myExcel.Workbooks.Close()
myExcel = Nothing
Return completed
End Function
End Class
Imports Microsoft.Office.Interop
Public Class Form1
Private Structure ExcelRows
Dim C1 As String
Dim C2 As String
Dim C3 As String
Dim C4 As String
End Structure
Private ExcelRowsList As List(Of ExcelRows) = New List(Of ExcelRows)
Public Property Sorting As SortOrder
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.OpenFileDialog1.FileName = Nothing
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.TextBox1.Text = Me.OpenFileDialog1.FileName
End If
If GetInfo() = True Then
For Each Xitem In ExcelRowsList
Dim lvitem As ListViewItem
lvitem = Me.ListView1.Items.Add(Xitem.C1)
lvitem.SubItems.AddRange(New String() {Xitem.C2, Xitem.C3})
Label1.Text = ListView1.Items.Count
ListView1.Sorting = SortOrder.Ascending
Next
End If
End Sub
Private Function GetInfo() As Boolean
Dim completed As Boolean = False
[ô]OPEN
Dim myExcel As New Excel.Application
myExcel.Workbooks.Open(Me.TextBox1.Text)
[ô]EXTRACT
myExcel.Sheets([Ô]Acolhimento - CG SUL PN CONSULT[Ô]).Activate()
myExcel.Range([Ô]A2[Ô]).Activate()
Dim ThisRow As New ExcelRows
Do
If myExcel.ActiveCell.Value > Nothing Or myExcel.ActiveCell.Text > Nothing Then
ThisRow.C1 = myExcel.ActiveCell.Value
myExcel.ActiveCell.Offset(0, 1).Activate()
ThisRow.C2 = myExcel.ActiveCell.Value
myExcel.ActiveCell.Offset(0, 1).Activate()
ThisRow.C3 = myExcel.ActiveCell.Value
myExcel.ActiveCell.Offset(0, 1).Activate()
ExcelRowsList.Add(ThisRow)
myExcel.ActiveCell.Offset(1, -14).Activate()
Else
completed = True
Exit Do
End If
Loop
[ô]CLOSE
myExcel.Workbooks.Close()
myExcel = Nothing
Return completed
End Function
End Class
Tópico encerrado , respostas não são mais permitidas