Predefined types
Tableau support predefined types to be imported, then you can use it in Excel/CSV/XML/YAML.
On this page
Overview
You can define enum
or struct
types in a protoconf file (such as common.proto
) ahead. It means you create predefined types, and then can use them to specify the column type or cross-cell struct type of a worksheet.
Usage
- Syntax: prepend a dot
.
to predefinedCustomType
(a.k.a..CustomType
) when you use it in a worksheet. - Import: specify the
importedProtoFiles
option of tableauc config to import the common proto files, where predefinedenum
orstruct
types are defined. Refer: Tableau Options.
Enum
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"
},
}
}
Struct
For example, struct type Prop
in common.proto
is defined as:
message Prop {
int32 id = 1 [(tableau.field).name = "ID"];
int32 value = 2 [(tableau.field).name = "Value"];
}
A worksheet ItemConf
in HelloWorld.xlsx:
ID | Prop1ID | Prop1Value | Prop2ID | Prop2Value |
---|---|---|---|---|
map<uint32, Item> | [.Prop]int32 | int32 | int32 | int32 |
Item’s ID | Prop1’s ID | Prop1’s value | Prop2’s ID | Prop2’s value |
1 | 1 | 100 | 2 | 200 |
2 | 3 | 300 | 4 | 400 |
3 | 5 | 500 |
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"}];
repeated Prop prop_list = 2 [(tableau.field) = {name:"Prop" layout:LAYOUT_HORIZONTAL}];
}
}
ItemConf.json
{
"itemMap": {
"1": {
"id": 1,
"propList": [
{
"id": 1,
"value": 100
},
{
"id": 2,
"value": 200
}
]
},
"2": {
"id": 2,
"propList": [
{
"id": 3,
"value": 300
},
{
"id": 4,
"value": 400
}
]
},
"3": {
"id": 3,
"propList": [
{
"id": 5,
"value": 500
}
]
}
}
}
Variable naming
In horizontal map
or horizontal list
, you can define custom variable name with the predefined struct.