8000 GitHub - huiliu/xls2pb: convert excel to protobuf
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

huiliu/xls2pb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

说明

用于游戏开发中的数据转换

依赖

  • python包"openxl"和"google.protobuf"

目标

  • 将Excel数据文件直接转换为Protobuf格式保存
  • 自动处理Excel数据

考虑的点

ProtoBuf支持的数据类型 openxl中读取得到的数据类型

  • 文件字符编码问题
  • Excel中的数据格式,以及与Protobuf的对应关系。如Excel中的整形、浮点、公式、日期等怎么转换为Protobuf数据
  • 将Excel中的列值设置到Protobuf
  • 预留接口处理需要处理的特殊字段

当前实现

游戏中使用的数据类型使用的数据类型其实相对简单,protobuff提供的类型基本满足要求的(虽然感觉有些浪费空间);openxl经过测试也可以使用的支持整形,浮点,日期(datetime.datetime)。由于日期解析为了python类型,所以稍微调整一下即可。预留接口registerFieldProcessor用户可以注册一个处理函数来处理表中的特殊字段。

学习知识点

protobuf

protobuf的基本语法: * syntax = "proto3"; * package Arrow; * 重复字段(与proto2一样)使用关键字"repeated"

对repeated字段的操作: * 添加

// item为itemTable中的一个重复字段
// 使用add方法即添加了一个新的空记录
newRecord = itemTable.item.add()
  • 访问

    for record in itemTable.item:
        // 字段不遍历比较麻烦
        print(record)

python

TODO

将处理类改写为一个通用类,可以处理任何一个表。

About

convert excel to protobuf

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0