List 嵌套 Struct

Excel list 中嵌套 struct 的规范说明。

纵向 list 中的嵌套

纵向 list 中的 struct

HelloWorld.xlsx 中的 worksheet ItemConf

IDNamePropIDPropValue
[Item]uint32string{Prop}int32int64
Item’s IDItem’s nameProp’s IDProp’s value
1Apple110
2Orange220
3Banana

生成结果:

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) = {layout:LAYOUT_VERTICAL}];
  message Item {
    uint32 id = 1 [(tableau.field) = {name:"ID"}];
    string name = 2 [(tableau.field) = {name:"Name"}];
    Prop prop = 3 [(tableau.field) = {name:"Prop"}];
    message Prop {
      int32 id = 1 [(tableau.field) = {name:"ID"}];
      int64 value = 2 [(tableau.field) = {name:"Value"}];
    }
  }
}
ItemConf.json
{
    "itemList": [
        {"id": 1, "name": "Apple", "prop": {"id": 1, "value": "10"}},
        {"id": 2, "name": "Orange", "prop": {"id": 2, "value": "20"}},
        {"id": 3, "name": "Banana", "prop": null}
    ]
}

纵向 list 中的 incell struct

HelloWorld.xlsx 中的 worksheet ItemConf

IDNamePropID
[Item]uint32string{int32 ID,int64 Value}Prop
Item’s IDItem’s nameProp’s ID
1Apple1,100
2Orange2,200
3Banana

生成结果:

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) = {layout:LAYOUT_VERTICAL}];
  message Item {
    uint32 id = 1 [(tableau.field) = {name:"ID"}];
    string name = 2 [(tableau.field) = {name:"Name"}];
    Prop prop_id = 3 [(tableau.field) = {name:"PropID" span:SPAN_INNER_CELL}];
    message Prop {
      int32 id = 1 [(tableau.field) = {name:"ID"}];
      int64 value = 2 [(tableau.field) = {name:"Value"}];
    }
  }
}
ItemConf.json
{
    "itemList": [
        {"id": 1, "name": "Apple", "propId": {"id": 1, "value": "100"}},
        {"id": 2, "name": "Orange", "propId": {"id": 2, "value": "200"}},
        {"id": 3, "name": "Banana", "propId": null}
    ]
}

横向 list 的第一个字段

横向 list 中的 struct

HelloWorld.xlsx 中的 worksheet ItemConf

Reward1ItemIDReward1ItemNumReward1NameReward2ItemIDReward2ItemNumReward2Name
[Reward]{Item}int32int32stringint32int32string
Item1’s IDItem1’s numReward’s nameItem1’s IDItem1’s numReward’s name
110Lotto10100Super Lotto

生成结果:

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 Reward reward_list = 1 [(tableau.field) = {name:"Reward" layout:LAYOUT_HORIZONTAL}];
  message Reward {
    Item item = 1 [(tableau.field) = {name:"Item"}];
    message Item {
      int32 id = 1 [(tableau.field) = {name:"ID"}];
      int32 num = 2 [(tableau.field) = {name:"Num"}];
    }
    string name = 2 [(tableau.field) = {name:"Name"}];
  }
}
ItemConf.json
{
    "rewardList": [
        {"item": {"id": 1, "num": 10}, "name": "Lotto"},
        {"item": {"id": 10, "num": 100}, "name": "Super Lotto"}
    ]
}

横向 list 中的 predefined struct

common.proto 中预定义的 Item

message Item {
    int32 id = 1 [(tableau.field) = {name:"ID"}];
    int32 num = 2 [(tableau.field) = {name:"Num"}];
}

HelloWorld.xlsx 中的 worksheet ItemConf

Reward1ItemIDReward1ItemNumReward1NameReward2ItemIDReward2ItemNumReward2Name
[Reward]{.Item}int32int32stringint32int32string
Item1’s IDItem1’s numReward’s nameItem1’s IDItem1’s numReward’s name
110Lotto10100Super Lotto

生成结果:

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 Reward reward_list = 1 [(tableau.field) = {name:"Reward" layout:LAYOUT_HORIZONTAL}];
  message Reward {
    protoconf.Item item = 1 [(tableau.field) = {name:"Item"}];
    string name = 2 [(tableau.field) = {name:"Name"}];
  }
}
ItemConf.json
{
    "rewardList": [
        {"item": {"id": 1, "num": 10}, "name": "Lotto"},
        {"item": {"id": 10, "num": 100}, "name": "Super Lotto"}
    ]
}

横向 list 中的 incell struct

HelloWorld.xlsx 中的 worksheet ItemConf

Reward1ItemReward1NameReward2ItemReward2Name
[Reward]{int32 ID, int32 Num}ItemstringItemstring
Reward1’s itemReward’s nameReward2’s itemReward’s name
1,10Lotto2,20Super Lotto

生成结果:

ItemConf.json
{
    "rewardList": [
        {"item": {"id": 1, "num": 10}, "name": "Lotto"},
        {"item": {"id": 2, "num": 20}, "name": "Super Lotto"}
    ]
}