Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 532

Setting Multi-Value Parameter from Excel Named Range Values

$
0
0

By Xiaodong Liang

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 dimensionrangeArray=GoExcel.NamedRangeValue("MyRange")'create a list to get the values of the first columnDimoListAsArrayListoList=NewArrayListDimoIndexAsInteger'rangeArray.GetLength(0)  means how many rowsForoIndex=1TorangeArray.GetLength(0)' add value of each row one by oneoList.Add(rangeArray(oIndex,1))Next'set it to the list parameterMultiValue.List("myP")=oList
GoExcel.Close

Viewing all articles
Browse latest Browse all 532

Trending Articles