I am trying to import data from Excel to textbox.
I want import data from Excel saved on my C: disk and i get error with System.NotImplementedException I use library for Excel and Office.
Dim ExcelApp As New Excel.Application
Dim ReteilerWorkbook As New WindowsApp1.ExcelApp.Workbooks.Open("C:\Users\TR\1.xlsx")
Dim retailerWorksheet As New RetailerWorkbook.Sheets(1)
Private Sub ZPlikuToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ZPlikuToolStripMenuItem.Click
Me.TextBox1.Text = ""
TextBox1.Text = retailerWorksheet.cells(1, 1).text
End Sub
I want fill textbox1 with data from cell A1
Here's what I do on VB.NET
to import data from Excel
:
First, I import Interop
on the head of my VB
module:
Imports Excel = Microsoft.Office.Interop.Excel
Then I declare the following INSIDE the routine:
Private Sub ...
Dim ExcelApp As Excel.Application = New Excel.Application
Dim ReteilerWorkbook As Excel.Workbook = ExcelApp.Workbooks.Open("C:\Users\TR\1.xlsx")
...
Could you try it this way?
To retrieve the cells(1,1)
content you don't need to declare the Worksheet
. It doesn't compensate the effort. So you could do this simply with:
TextBox1.Text = ReteilerWorkbook.Sheets(1).Cells(1,1).Text
And, as always, don't forget to close the workbook at the end:
ReteilerWorkbook.Close()