Enum
This guide demonstrates different features of excel enum type.
Use predefined enum type
The basic enum guide, please go to read Enum →
For example, enum type FruitType
in common.proto
is defined as:
enum FruitType {
FRUIT_TYPE_UNKNOWN = 0 [(tableau.evalue).name = "Unknown"];
FRUIT_TYPE_APPLE = 1 [(tableau.evalue).name = "Apple"];
FRUIT_TYPE_ORANGE = 2 [(tableau.evalue).name = "Orange"];
FRUIT_TYPE_BANANA = 4 [(tableau.evalue).name = "Banana"];
}
A worksheet ItemConf
in HelloWorld.xlsx:
ID | Type |
---|---|
map<uint32, Item> | enum<.FruitType> |
Item’s ID | Fruit’s type |
1 | 1 |
2 | Orange |
3 | FRUIT_TYPE_BANANA |
Generated:
hello_world.proto
// --snip--
import "common.proto";
option (tableau.workbook) = {name:"HelloWorld.xlsx"};
message ItemConf {
option (tableau.worksheet) = {name:"ItemConf" namerow:1 typerow:2 noterow:3 datarow:4};
map<uint32, Item> item_map = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}];
message Item {
uint32 id = 1 [(tableau.field) = {name:"ID"}];
FruitType type = 2 [(tableau.field) = {name:"Type"}];
}
}
ItemConf.json
{
"itemMap": {
"1": {
"id": 1,
"type": "FRUIT_TYPE_APPLE"
},
"2": {
"id": 3,
"type": "FRUIT_TYPE_ORANGE"
}
"3": {
"id": 2,
"type": "FRUIT_TYPE_BANANA"
},
}
}
Define enum type in sheet
In order to generate enum type definition, you should specify Mode
option to MODE_ENUM_TYPE
in metasheet @TABLEAU
.
Simple enum type in sheet
For example, a worksheet ItemType
in HelloWorld.xlsx:
Name | Alias |
---|---|
ITEM_TYPE_FRUIT | Fruit |
ITEM_TYPE_EQUIP | Equip |
ITEM_TYPE_BOX | Box |
Sheet | Mode |
---|---|
ItemType | MODE_ENUM_TYPE |
Generated:
hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx"};
// Generated from sheet: ItemType.
enum ItemType {
ITEM_TYPE_INVALID = 0;
ITEM_TYPE_FRUIT = 1 [(tableau.evalue).name = "Fruit"];
ITEM_TYPE_EQUIP = 2 [(tableau.evalue).name = "Equip"];
ITEM_TYPE_BOX = 3 [(tableau.evalue).name = "Box"];
}
Specify Number column
In Number
column, you can specify custom unique enum value number.
If you not specify default enum value "0", it will be auto generated. And the default enum value name pattern is: "{ENUM_TYPE}_INVALID".
For example, a worksheet ItemType
in HelloWorld.xlsx:
Number | Name | Alias |
---|---|---|
0 | ITEM_TYPE_UNKNOWN | Unknown |
10 | ITEM_TYPE_FRUIT | Fruit |
20 | ITEM_TYPE_EQUIP | Equip |
30 | ITEM_TYPE_BOX | Box |
Sheet | Mode |
---|---|
ItemType | MODE_ENUM_TYPE |
Generated:
hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx"};
// Generated from sheet: ItemType.
enum ItemType {
ITEM_TYPE_UNKNOWN = 0 [(tableau.evalue).name = "Unknown"];
ITEM_TYPE_FRUIT = 10 [(tableau.evalue).name = "Fruit"];
ITEM_TYPE_EQUIP = 20 [(tableau.evalue).name = "Equip"];
ITEM_TYPE_BOX = 30 [(tableau.evalue).name = "Box"];
}
Define and use enum type in sheet
For example, two worksheets ItemType
and ItemConf
in HelloWorld.xlsx:
Number | Name | Alias |
---|---|---|
1 | ITEM_TYPE_FRUIT | Fruit |
2 | ITEM_TYPE_EQUIP | Equip |
3 | ITEM_TYPE_BOX | Box |
ID | Type | Name | Price |
---|---|---|---|
map<int32, Item> | enum<.ItemType> | string | int32 |
Item’s ID | Item’s type | Item’s name | Item’s price |
1 | Fruit | Apple | 40 |
2 | Fruit | Orange | 20 |
3 | Equip | Sword | 10 |
Sheet | Mode |
---|---|
ItemType | MODE_ENUM_TYPE |
ItemConf |
Generated:
hello_world.proto
// --snip--
import "common.proto";
option (tableau.workbook) = {name:"HelloWorld.xlsx"};
// Generated from sheet: ItemType.
enum ItemType {
ITEM_TYPE_INVALID = 0;
ITEM_TYPE_FRUIT = 1 [(tableau.evalue).name = "Fruit"];
ITEM_TYPE_EQUIP = 2 [(tableau.evalue).name = "Equip"];
ITEM_TYPE_BOX = 3 [(tableau.evalue).name = "Box"];
}
message ItemConf {
option (tableau.worksheet) = {name:"ItemConf" namerow:1 typerow:2 noterow:3 datarow:4};
map<int32, Item> item_map = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}];
message Item {
int32 id = 1 [(tableau.field) = {name:"ID"}];
protoconf.ItemType type = 2 [(tableau.field) = {name:"Type"}];
string name = 3 [(tableau.field) = {name:"Name"}];
int32 price = 4 [(tableau.field) = {name:"Price"}];
}
}
ItemConf.json
{
"itemMap": {
"1": {
"id": 1,
"type": "ITEM_TYPE_FRUIT",
"name": "Apple",
"price": 40
},
"2": {
"id": 2,
"type": "ITEM_TYPE_FRUIT",
"name": "Orange",
"price": 20
},
"3": {
"id": 3,
"type": "ITEM_TYPE_EQUIP",
"name": "Sword",
"price": 10
}
}
}