Home » excel » arrays – VB.Net – Excel application get showing values of an range

arrays – VB.Net – Excel application get showing values of an range

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying get an Excel Range and copy into an array of objects with Vb.Net.

This is not a problem. I use the following code:

Dim vValues(,) As Object = ExcelApp.Range(vRange).Value

And works fine; but I have a the following case:

Excel

In the column “C”; the value has a specific format and internally has another value.

My question is:

Somebody know the way to get the information exact as the user see?

I’m trying to get the information without use a For ... Each or some kind of cycle.

I’m also tried to avoid use “text to columns” function.

Both seems right solutions, but would impact the performance with a lot of data.

FYI: Also I can get the information through the ODBC connection; but I’m searching the solution using a Range

How to&Answers:

Exactly what the user sees is the Text property. But you cannot have an array of that, you will have to query each cell individually.

You are getting a Double value in your array instead of a DateTime value because you have “Time” formatting applied in Excel. If you had a format from the “Date” category, Excel would instead send a proper Variant/Date, not a Double that represents it.

Another option would be constructing the DateTime objects on the .NET side, provided you know in which columns they should be.