键控列表(KeyedList)

本文说明 Excel 键控列表类型的各种特性。

语法

键控列表与普通列表相同,区别在于 ColumnType(第一个字段类型)被尖括号 <> 包围,并作为键处理。

语法[ElemType]<ColumnType>

水平键控列表(Horizontal KeyedList)

TODO…

垂直键控列表(Vertical KeyedList)

垂直标量键控列表(Vertical scalar KeyedList)

[!NOTE] 定义方式与 单元格内标量键控列表 相同,但如果提供了多行数据,会进行聚合。

HelloWorld.xlsx 中的工作表 ItemConf

ID
[]<uint32>
ID
1,2,3
4,5
6

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated uint32 id_list = 1 [(tableau.field) = {name:"ID" key:"ID" layout:LAYOUT_INCELL}];
}
ItemConf.json
{
    "idList": [1, 2, 3, 4, 5, 6]
}

垂直枚举键控列表(Vertical enum KeyedList)

[!NOTE] 定义方式与 单元格内枚举键控列表 相同,但如果提供了多行数据,会进行聚合。

common.proto 中预定义的枚举类型 FruitType

enum FruitType {
  FRUIT_TYPE_UNKNOWN = 0 [(tableau.evalue).name = "Unknown"];
  FRUIT_TYPE_APPLE   = 1 [(tableau.evalue).name = "Apple"];
  FRUIT_TYPE_ORANGE  = 3 [(tableau.evalue).name = "Orange"];
  FRUIT_TYPE_BANANA  = 4 [(tableau.evalue).name = "Banana"];
}

HelloWorld.xlsx 中的工作表 ItemConf

Type
[]<enum<.FruitType>>
Type
Apple,Orange
FRUIT_TYPE_BANANA
0

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated protoconf.FruitType type_list = 1 [(tableau.field) = {name:"Type" key:"Type" layout:LAYOUT_INCELL}];
}
ItemConf.json
{
    "typeList": [
        "FRUIT_TYPE_APPLE",
        "FRUIT_TYPE_ORANGE",
        "FRUIT_TYPE_BANANA",
        "FRUIT_TYPE_UNKNOWN"
    ]
}

垂直结构体键控列表(Vertical struct KeyedList)

HelloWorld.xlsx 中的工作表 ItemConf

IDPropIDPropName
[Item]<uint32>map<int32, Prop>string
Item’s IDProp’s IDProp’s name
11sweet
21sweet
22delicious

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated Item item_list = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}];
  message Item {
    uint32 id = 1 [(tableau.field) = {name:"ID"}];
    map<int32, Prop> prop_map = 2 [(tableau.field) = {key:"PropID" layout:LAYOUT_VERTICAL}];
    message Prop {
      int32 prop_id = 1 [(tableau.field) = {name:"PropID"}];
      string prop_name = 2 [(tableau.field) = {name:"PropName"}];
    }
  }
}
ItemConf.json
{
    "itemList": [
        {
            "id": 1,
            "propMap": {"1": {"propId": 1, "propName": "sweet"}}
        },
        {
            "id": 2,
            "propMap": {
                "1": {"propId": 1, "propName": "sweet"},
                "2": {"propId": 2, "propName": "delicious"}
            }
        }
    ]
}

单元格内键控列表(Incell KeyedList)

单元格内标量键控列表(Incell scalar KeyedList)

HelloWorld.xlsx 中的工作表 ItemConf

ID
[]<uint32>
ID list
1,2,3

生成结果:

hello_world.proto
// --snip--
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated uint32 id_list = 1 [(tableau.field) = {name:"ID" key:"ID" layout:LAYOUT_INCELL}];
}
ItemConf.json
{
    "idList": [1, 2, 3]
}

单元格内枚举键控列表(Incell enum KeyedList)

common.proto 中预定义的枚举类型 FruitType

enum FruitType {
  FRUIT_TYPE_UNKNOWN = 0 [(tableau.evalue).name = "Unknown"];
  FRUIT_TYPE_APPLE   = 1 [(tableau.evalue).name = "Apple"];
  FRUIT_TYPE_ORANGE  = 3 [(tableau.evalue).name = "Orange"];
  FRUIT_TYPE_BANANA  = 4 [(tableau.evalue).name = "Banana"];
}

HelloWorld.xlsx 中的工作表 ItemConf

Param
[]enum<.FruitType>
Param list
1,FRUIT_TYPE_ORANGE,Banana

Param 列的类型为 incell list []enum<.FruitType>,list 元素为预定义枚举类型 FruitType

生成结果:

hello_world.proto
// --snip--
import "common.proto";
option (tableau.workbook) = {name:"HelloWorld.xlsx" namerow:1 typerow:2 noterow:3 datarow:4};

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  repeated protoconf.FruitType type_list = 1 [(tableau.field) = {name:"Type" key:"Type" layout:LAYOUT_INCELL}];
}
ItemConf.json
{
    "typeList": [
        "FRUIT_TYPE_APPLE",
        "FRUIT_TYPE_ORANGE",
        "FRUIT_TYPE_BANANA"
    ]
}