Question:
I want to set multi values from Excel named range. I tested and got the failure: "Array was not a one-dimensional array."
GoExcel.Open("C:\Temp\Book1.xlsx", "Sheet1")
MultiValue.List("myP") = GoExcel.NamedRangeValue("MyRange")
Is there anything missed?
Solution:
In Excel, the named range is a X*Y dimensions. X is the rows, Y is the column. While the parameter of multi-values in Inventor is one dimension. Even you defined the named range with only one column, it is not a correct usage to set it to the multi-values directly. You need to extract the values of the column we are interested in. e.g. the code below gets the values of the first column.
GoExcel.Open("C:\Temp\Book1.xlsx", "Sheet1")
' this is an array X*Y dimension
rangeArray = GoExcel.NamedRangeValue("MyRange")
'create a list to get the values of the columns
Dim oList As ArrayList
oList = New ArrayList
'rangeArray.GetLength(0) means how many rows
'rangeArray.GetLength(1) means how many colmuns
Dim oRowsCount
oRowsCount = rangeArray.GetLength(0)
Dim oColCount
oColCount = rangeArray.GetLength(1)
Dim oRowIndex As Integer
Dim oColIndex As Integer
For oRowIndex = 1 To oRowsCount
' add value of each row one by one
For oColIndex = 1 To oColCount
oList.Add(rangeArray(oRowIndex,oColIndex))
Next
Next
'set it to the list parameter
MultiValue.List("MyP") = oList
GoExcel.Close