Tuesday, October 24, 2017 :: Login  

Excel file into Array

 

Imports Excel

Dim oExcel As Excel.Application
Dim oWorkBook As Excel.Workbook
Dim oWorkSheet As Excel.Worksheet

Dim arrreturn As String(,) = Nothing
Dim Arrtmp As String(,) = Nothing

oExcel = New Excel.Application() 
oWorkBook = oExcel.Workbooks.Open(varExcelFileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, _ 
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, _ 
Missing.Value, Missing.Value, Missing.Value)

oWorkSheet = DirectCast(oWorkBook.Worksheets(1), Excel.Worksheet)

Dim r As Integer
Dim c As Integer
Dim intRows As Integer
Dim intCols As Integer
Dim excelCell As Excel.Range = oWorkSheet.UsedRange
Dim values As Object(,) = DirectCast(excelCell.Value2, Object(,))

intRows = values.GetLength(0)

If intRows <> 0 Then

intCols = values.GetLength(1)

If intCols <> 0 Then

Arrtmp = New String(values.GetLength(0) - 1, values.GetLength(1) - 1) {}

For r = 1 To intRows

For c = 1 To intCols

Arrtmp(r - 1, c - 1) = DirectCast(DirectCast(values(r, c), Excel.Range).Text, String)

Next

Next

End If

End If

arrreturn = Arrtmp

Arrtmp = Nothing

oWorkSheet = Nothing

oWorkBook.Close(Missing.Value, Missing.Value, Missing.Value)

oWorkBook = Nothing

oExcel.Quit()

oExcel = Nothing

 

 

Privacy Policy www.made4dotnet.com 2006

Map IP Address
Powered byIP2Location.com

   Terms Of Use   ::   Privacy Statement   ::   Copyright (c) 2017 www.made4dotnet.com - .NET Development