Skip to main content

AccessTr.neT


Excelden Datagride Veri Aktarımı

Excelden Datagride Veri Aktarımı

#4
Boşu boşuna hiç kasmadan olayı bir videodan gördüğüm gibi yaptım. Gayet hızlı ve performanslı bi aktarım oldu

NuGet Package Manager den

"ExcelDataReader"
"ExcelDataReader.DataSet" bunları ekliyoruz

Forma
1 adet DataGridView
1 adet textbox
1 adet button
1 adet combobox ekliyoruz

Kodlar şu

Kod:
Imports System.Globalization
Imports System.IO
Imports ClosedXML.Excel
Imports ExcelDataReader

Dim tables As DataTableCollection

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using ofd As OpenFileDialog = New OpenFileDialog() With {.Filter = "Excel File|*.xlsx;*.xls"}
            If ofd.ShowDialog() = DialogResult.OK Then
                TextBox1.Text = ofd.FileName

                Using stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read)
                    Using reader As IExcelDataReader = ExcelReaderFactory.CreateReader(stream)
                        Dim result As DataSet = reader.AsDataSet(New ExcelDataSetConfiguration() With {
                                                                 .ConfigureDataTable = Function(__) New ExcelDataTableConfiguration() With {
                                                                 .UseHeaderRow = True}})
                        tables = result.Tables
                        ComboBox1.Items.Clear()

                        For Each table As DataTable In tables
                            ComboBox1.Items.Add(table.TableName)
                            ComboBox1.Enabled = True
                        Next



                    End Using

                End Using

            End If

        End Using
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Try
            Dim dt As DataTable = tables(ComboBox1.SelectedItem.ToString())

            DataGridView1.DataSource = dt
            

        Catch ex As Exception

        End Try


    End Sub

Bu kadar
drummers, 11-05-2009 tarihinden beri AccessTr.neT üyesidir.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da

Bu Konudaki Yorumlar
Excelden Datagride Veri Aktarımı - Yazar: drummers - 28/06/2021, 09:45
RE: Excelden Datagride Veri Aktarımı - Yazar: feraz - 28/06/2021, 16:52
RE: Excelden Datagride Veri Aktarımı - Yazar: drummers - 29/06/2021, 14:37
RE: Excelden Datagride Veri Aktarımı - Yazar: feraz - 29/06/2021, 14:48
RE: Excelden Datagride Veri Aktarımı - Yazar: feraz - 29/06/2021, 14:54
RE: Excelden Datagride Veri Aktarımı - Yazar: feraz - 30/06/2021, 01:41
Task