Excel Tables
Excel Tables specify a range of cells from an Excel Spreadsheet (XLSX
/XLS
) to translate into a ModuleScript.
The resulting table can be formatted in multiple ways.
Syntax
File Name
*.Excel.JSON
Keys
spreadsheet
: string- A relative path to the associated Excel Spreadsheet.
ref
: string- The 2D range with which to pull data from. Formatted as
sheetName!rowColumn:rowColumn
, e.g.Sheet1!A1:C3
. It can also be a named range, which allows the range to be modified from inside the Excel worksheet.
- The 2D range with which to pull data from. Formatted as
hasHeader
: boolean- Whether or not the first row should be used as keys for nesting elements in the translated Excel Table.
numColumnKeys
: number- Defines by how many columns each entry should be nested.
lastColumnKeyUsesIndices
: boolean- Whether or not the last nesting defined by
numColumnKeys
should be treated as an array.
- Whether or not the last nesting defined by
Examples
Example 1
Given an Excel Spreadsheet named Economy.xlsx
containing the following cells in a sheet named Pets
;
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
1 | PetID | Name | Area | Deluxe | Rarity | Power |
2 | Starter_Cat | Cat | 1 | 0 | 0 | 5 |
3 | Starter_Dog | Dog | 1 | 0 | 0 | 5 |
4 | Starter_Bunn | Bunny | 1 | 0 | 0 | 5 |
... and an Excel Table file named Pets.Excel.JSON
containing the following;
{
"spreadsheet": "Economy.xlsx",
"ref": "Pets!A1:F4",
"hasHeader": true,
"numColumnKeys": 1,
"lastColumnKeyUsesIndices": false
}
... the following table will appear in Roblox as a ModuleScript named Pets
:
return {
Starter_Cat = {
Name = "Cat",
Area = 1,
Deluxe = 0,
Rarity = 0,
Power = 5,
},
Starter_Dog = {
Name = "Dog",
Area = 1,
Deluxe = 0,
Rarity = 0,
Power = 5,
},
Starter_Bunn = {
Name = "Bunny",
Area = 1,
Deluxe = 0,
Rarity = 0,
Power = 5,
}
}
TIP
It's important to format tables in ways that are easy for you to use. When tables are organized with keys instead of indices, you will be able to access these entries directly (e.g., Pets[uniquePetId]
.)
Example 2
Given an Excel Spreadsheet named Players.xlsx
containing the following cells in a sheet named Sheet1
;
C | D | E | F | |
---|---|---|---|---|
4 | Name | Foo | Bar | Baz |
5 | Alfa | 512 | 64 | 8 |
6 | Bravo | 256 | 4 | |
7 | Charlie | 128 | 16 | 2 |
... and an Excel Table file named Leaderboard.Excel.JSON
containing the following;
{
"spreadsheet": "Players.xlsx",
"ref": "Sheet1!C4:F7",
"hasHeader": true,
"numColumnKeys": 0,
"lastColumnKeyUsesIndices": false
}
... the following table will appear in Roblox as a ModuleScript named Leaderboard
:
return {
{
Name = "Alfa",
Foo = 512,
Bar = 64,
Baz = 8,
},
{
Name = "Bravo",
Foo = 256,
Bar = nil,
Baz = 4,
},
{
Name = "Charlie",
Foo = 128,
Bar = 16,
Baz = 2,
},
}