问题
I'm retrieving data from Excel and would like to keep my arrays 0 based but Excel returns 1 base. Is there a fairly simple way to return change the array from 1 to 0 base? Or do I just need to create a loop?
Here's an example code right here:
dim oData(,) as object
dim rng as range
dim wks as worksheet = xlApp.Activeworkbook.sheets(Sheet1)
rng=wks.Range("A1:B2")
oData=rng.Value2
回答1:
A loop is the simplest option.
Dim target as string(0 to oData.Length - 1)
For index = 1 to oData.Length
target(index - 1) = oData(index)
Next
Thats from memory and not tested but it's obvious enough.
来源:https://stackoverflow.com/questions/9086229/change-base-1-array-to-base-0-array