Getting data from a spreadsheet with 2 dimension array

Getting data from a spreadsheet with 2 dimension array

steveh3
Advisor Advisor
341 Views
3 Replies
Message 1 of 4

Getting data from a spreadsheet with 2 dimension array

steveh3
Advisor
Advisor

Hello Gang...

I have a spreadsheet which has two dimensions OD and BC.

steveh_1-1663779670855.png

For the DimC, I would like to gather all the rows where OD is greater than or equal to the DimC value chosen in the form (grey hi-lited cells).

 

Then also do the same for the BC. Select all rows where BC is greater than or equal to MaxBC (yellow hi-lited cells).

 

Then the result for AvailableDiscs would be the intersection of the two sets (green hi-lited). This would then show up in the form as what would be available to chose. 

 

I have the form and spreadsheet set up, but I can't figure out how to dynamically update the Listing of AvailableDiscs.

 

steveh_2-1663779995871.png

I'm assuming this is possible?

I have included the .ipt and spreadsheet as attachments.

 

Thanks in advance,

Steve H.

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (2)
342 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @steveh3.  I didn't have time to create a complete solution for you today, but I did create something to get you further along in your project.  It is difficult to get data from Excel in a 2-dimensional array using iLogic's built-in GoExcel functions, so I opted for digging into Excel's API for this one.  This will get the Excel data to a 2D array for you.  Then just to show you that it worked, I included a message at the end that shows you the values across the last line of data.  The comparisons and filtering can be added later.

This is the code I have for you right now.

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Sub Main
	Dim oFile As String = "C:\Temp\Wheel_database.xlsx"
	Dim oSheet As String = "FormedPlates"
	'start a new instance of Excel
	Dim oExcel As New Excel.Application
	oExcel.DisplayAlerts = False
	oExcel.Visible = True
	Dim oWB As Workbook = oExcel.Workbooks.Open(oFile)
	Dim oWS As Worksheet = oWB.Sheets.Item(oSheet)
	'specify the range of cells in that sheet you want to read into memory
	Dim oRange As Range = oWS.Range("A1:D32")
	'create 2-dimensional array of Object, and set the range's values into it
	Dim oArray(, ) As Object = oRange.Value
	'read from an array by specifying row, then column, both starting with 1
	Dim oLastRowData As String
	oLastRowData = oArray(32, 1).ToString
	oLastRowData = oLastRowData & " <> " & oArray(32, 2).ToString
	oLastRowData = oLastRowData & " <> " & oArray(32, 3).ToString
	oLastRowData = oLastRowData & " <> " & oArray(32, 4).ToString
	MsgBox("oLastRowData = " & oLastRowData,,"")
	
	oWS = Nothing
	oWB.Close
	oWB = Nothing
	'oExcel.Quit
	oExcel = Nothing
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

tyler.warner
Advocate
Advocate
Accepted solution

@steveh3 I made some adjustments to the Excel sheet to do some of the calculations for you. The form in the part file now updates to the available options, by selecting your two parameter inputs at the top of the form & then clicking the update button. The only thing that you will need to change to test this out is:

 

DiscSelector.ipt --> ParametersChosen Rule --> oExcelFileName (the correct path to your excel file)

 

See if this is what you're looking for.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 4 of 4

steveh3
Advisor
Advisor

Thanks Gentlemen....

I was able to take your logic and it worked.

 

Appreciate the help!

 

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes