Skip to content

How to pull data from Excel

Albin Bergh edited this page Sep 6, 2023 · 4 revisions

When pulling data from an Excel sheet the following process can be applied: image

From left to right:

A component called “BH.oM.Adapter.FileSettings.FileSettings() {String FileName, String Directory, String Name}” when searching with ctrl + shift + b. To this component you connect a panel with the name of the excel file and a panel with the directory to where said file is saved.

Next step is creating an Excel adapter. Do this by using the "CreateAdapter" component found in the BHoM tab. Right click on the adapter and in the search box type “excel” and choose the alternative that comes up.

Then create a component called “BH.oM.Adapters.Excel.CellContentsRequest() {String worksheet, String range}” with ctrl + shift + b. To this panel connect a panel with the name of the worksheet from Excel that you want to use. Then connect a panel with the desired range in the form of expression1:expression2. Note that if you wish to only pull one cell you would still need to type in the same way e.g. A3:A3.

Then create a Pull component from the BHoM tab and connect the "CellContentsRequest" component to the request and the ExcelAdapter to the adapter. Then create a "BooleanToggle" and connect it to active. This toggle is used to activate the pulling process, switching it to false and then back to true also updates the script with any changes done in the excel sheet.

To control the pulled objects you can use two Explode components found in the BHoM tab connected to a panel as shown on the picture.

Notes:

The data is pulled from Excel row by row.

When doing changes in the Excel sheet, save the file and toggle the BooleanToggle to update in Grasshopper.

Clone this wiki locally