Imports Microsoft.Office.Interop Public Class Form1 Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Protected Overrides Sub Finalize() MyBase.Finalize() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Dim xlRange As Excel.Range Dim xlRow As Integer Dim strFilename As String Dim V As String 'Dim data(0 To 100) As String With OpenFileDialog1 .Filter = "Excel Office| *.xls;* .xlsx" .ShowDialog() strFilename = .FileName End With If strFilename <> String.Empty Then xlApp = New Excel.Application xlWorkBook = xlApp.Workbooks.Open(strFilename) xlWorkSheet = xlWorkBook.Worksheets("sheet1") xlRange = xlWorkSheet.UsedRange For xlRow = 2 To xlRange.Rows.Count V = DataGridView1.Rows.Add(xlRange.Cells(xlRow, 1), xlRange.Cells(xlRow, 2), xlRange.Cells(xlRow, 3), xlRange.Cells(xlRow, 4)) Next xlWorkBook.Close() xlApp.Quit() End If End Sub End Class
Hi, I'm trying to import data from Excel to Visual Studio VB. But when I'm importing the data I got {System.__ComObject} instead of Values!!!
COM
Value
Cells
System.__ComObject
xlRange.Cells(xlRow, 1).Value
xlRange.Value2(xlRow, 1))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)