Currently, my VB.NET 2019 application has a form to select a workbook, then the sheet, and then load the worksheet to a datagrid and then add to a database table (Access). This works great for a couple of workbooks.
On a monthly basis, I have 102 worksheets to import. The worksheets are all created from a PDF to worksheet application, so the sheet name is always the same.
My search results only come up with VBA suggestions.
Thanks for any assistance.
Code to process sheet:
Code:Private Sub BtnSheet_Click(sender As Object, e As EventArgs) Handles btnSheet.Click ExcelFile = txtFileName.Text Dim extension As String = Path.GetExtension(ExcelFile) Dim filePath As String = ExcelFile Dim header As String = "YES" fileName = Path.GetFileNameWithoutExtension(ExcelFile) ClearDGV() prbStatus.Refresh() sheetname = cboSheet.SelectedValue.ToString conStr = String.Empty Select Case extension Case ".xls" 'Excel 97-03 conStr = String.Format(Excel03ConString, filePath, header) Exit Select Case ".xlsx" 'Excel 07 conStr = String.Format(Excel07ConString, filePath, header) Exit Select End Select Using con As New OleDb.OleDbConnection(conStr) Using cmd As New OleDbCommand() Using oda As New OleDbDataAdapter() cmd.CommandText = (Convert.ToString("SELECT * From [") & sheetname) + "]" cmd.Connection = con con.Open() oda.SelectCommand = cmd oda.Fill(dtable) con.Close() dgvRatesAll.DataSource = dtable btnImport.Enabled = True End Using End Using End Using End Sub




Reply With Quote
