GithubHelp home page GithubHelp logo

youlanhai / exceltocode Goto Github PK

View Code? Open in Web Editor NEW
62.0 4.0 29.0 528 KB

将Excel表转换成Python, Lua, json数据表,自动生成java类。

License: MIT License

Python 100.00%
excel python lua json java

exceltocode's Introduction

导表工具

项目主页:https://github.com/youlanhai/ExcelToCode

Excel文件:

转换后的python数据表:

# -*- coding: utf-8 -*-
# 此文件由导表工具自动生成,禁止手动修改。
# from example.xlsx

# A ID                  编号
# B name                名称
# C describe            描述
# D quality             品质
# E drop                掉落关卡
main_sheet = {
    1: {"describe": "切菜用的", "drop": [1, 2, 3, 4, ], "name": "菜刀", "quality": 1, },
    2: {"drop": [2, ], "name": "上方宝剑", "quality": 5, },
    3: {"name": "偃月弯刀", "quality": 0, },
}

原理

  1. 构造exporter对象,开始整个导表流程
  2. 搜索INPUT_PATH路径下的所有Excel文件
  3. 构造parser对象,将Excel数据转换成python格式的中间数据表
  4. 如果定义了后处理操作,exporter将对数据表执行后处理操作。比如表头合并,合法性检查
  5. 实例化writer对象,将python表转换成最终的python、lua、json等格式的数据表。

准备

  • python 2.7
  • 安装python插件openpyxl。使用pip install openpyxl安装,或者在config文件配置DEPENDENCIES项,指定openpyxl的安装包路径,导表工具会自动安装。

工具用法

python main.py --export your_configure_file
main导表参数 说明
config_file python格式的配置文件。配置文件的详细写法,参考配置文件参数详解
--gen-code 生成类代码,目前仅支持Java。需要在config文件中,指定代码生成器参数CODE_GENERATORS
--export 执行导表
--fast-mode 快速模式,仅重新解析最近修改过的Excel表。解析Excel表的过程非常慢,快速模式会使用已经生成的中间文件来避免二次解析Excel表
--force-run 出错后是否继续进行导表。常用于发现更多的错误
--gen-header 根据转换器描述信息,自动生成表头

范例

samples目录。direct-mode目录下的例子使用的是直接模式(Direct)config-mode目录下的例子使用的是配置模式(Config)mix-mode目录下的例子使用的是混合模式(Mix)

文件名称 描述
config.py 导表工具配置文件
export.bat/export.sh 导表批处理文件
excels 存放excel文件所在目录
converters 转换器父级目录
converters/converter 转换器脚本存放路径

文档

  1. 配置文件参数详解
  2. 表格添加方法

路径说明

路径 说明
codegen 代码生成器。如,生成Java代码
doc 文档
exporters 导出器。用于将excel表转换成相应的数据结构
parsers excel解析器。解析单个excel表格
postprocess 后处理器。导表结束后,可以执行一些额外的操作。比如,移动文件目录,生成文件列表等
samples 一些例子
tps 通用类型转换器。用于将数据转换成具体的Python数据类型
writers 写出器。用于将Python数据表,写出成不同格式的数据表。如,Lua、Json等。

exceltocode's People

Contributors

youlanhai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

exceltocode's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.