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:

IDType
map<uint32, Item>enum<.FruitType>
Item’s IDFruit’s type
11
2Orange
3FRUIT_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:

NameAlias
ITEM_TYPE_FRUITFruit
ITEM_TYPE_EQUIPEquip
ITEM_TYPE_BOXBox
SheetMode
ItemTypeMODE_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.

For example, a worksheet ItemType in HelloWorld.xlsx:

NumberNameAlias
0ITEM_TYPE_UNKNOWNUnknown
10ITEM_TYPE_FRUITFruit
20ITEM_TYPE_EQUIPEquip
30ITEM_TYPE_BOXBox
SheetMode
ItemTypeMODE_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:

NumberNameAlias
1ITEM_TYPE_FRUITFruit
2ITEM_TYPE_EQUIPEquip
3ITEM_TYPE_BOXBox
IDTypeNamePrice
map<int32, Item>enum<.ItemType>stringint32
Item’s IDItem’s typeItem’s nameItem’s price
1FruitApple40
2FruitOrange20
3EquipSword10
SheetMode
ItemTypeMODE_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
        }
    }
}