快速开始

一页概览:如何使用 tableauc 将工作簿文件转换为 proto 和 JSON 文件。

1. 下载 tableauc

选择合适的 tableauc(即 Tableau Compiler)下载:

更多平台版本请访问 tableau releases →

2. 添加工作簿

添加 HelloWorld.xlsx,包含两个 sheet:

  • Item:将下方数据复制到此 worksheet。
  • @TABLEAU:暂时留空。这是 tableau 的 metasheet →,用于指定解析器选项。
IDNameDesc
map<int32, Item>stringstring
Item’s IDItem’s nameItem’s description
1AppleA kind of delicious fruit.
2OrangeA kind of sour fruit.
3BananaA kind of calorie-rich fruit.

3. 运行 tableauc

执行命令:./tableauc HelloWorld.xlsx

随后会生成 hello_world.protoItem.json

hello_world.proto
syntax = "proto3";

package protoconf;

import "tableau/protobuf/tableau.proto";

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

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

  map<int32, Item> item_map = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}];
  message Item {
    int32 id = 1 [(tableau.field) = {name:"ID"}];
    string name = 2 [(tableau.field) = {name:"Name"}];
    string desc = 3 [(tableau.field) = {name:"Desc"}];
  }
}
Item.json
{
    "itemMap": {
        "1": {
            "id": 1,
            "name": "Apple",
            "desc": "A kind of delicious fruit."
        },
        "2": {
            "id": 2,
            "name": "Orange",
            "desc": "A kind of sour fruit."
        },
        "3": {
            "id": 3,
            "name": "Banana",
            "desc": "A kind of calorie-rich fruit."
        }
    }
}

恭喜!你已经成功使用 tableauc 将工作簿转换为 proto 和 JSON 文件。