Skip to content

Script Examples

Reading data from File

Download ZIP File

In this example, we created a UI that can read data from a CSV file.

To do this, we first read the file, split it's contents per row. then Add the row's content to an Array so we can easily access and assign it to the respective textbox where we want to display the data.

Locator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
const file = await File.read("PlayerInfo.csv");
const [header, ...rows] = file.split('\r\n');
const val = [];
for (const row of rows) {
  dropdown1.addItem(row.split(',').at(0));
  val.push(row.split(','));
}


dropdown1.onChange = () =>{
  FirstName_TI.value = val[dropdown1.selectedIndex][0];
  Age_TI.value = val[dropdown1.selectedIndex][1];
  Position_TI.value = val[dropdown1.selectedIndex][2];
  Height_TI.value = val[dropdown1.selectedIndex][3];
  PlayerImage_Media.value = val[dropdown1.selectedIndex][4];
};