• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

luzexi/xls2lua: A script to convert xls or xlsx to lua files.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

luzexi/xls2lua

开源软件地址(OpenSource Url):

https://github.com/luzexi/xls2lua

开源编程语言(OpenSource Language):

Python 83.4%

开源软件介绍(OpenSource Introduction):

xls2lua

Convert xls to lua script for game resource

(将xls数据文件转化为lua脚本,作为游戏资源使用)

use python xlrd

(使用python xlrd模块)

Blog: http://www.luzexi.com

Email: jesse_luzexi@163.com

What's this.(是什么)

This is a script to convert xls to lua.

If you use lua language , the data write in lua is the best thing for you to code.

So this script will help you convert xls to lua , so you can do your job more easily.

(如果你在使用Lua语言,将数据写进Lua文件是最方便的做法。这个脚本将帮助你将数据xls文件转化为lua文件,这样你就可以更好的工作了。)

Declare (声明)

This script is inherit from https://github.com/zfengzhen/xls2lua .

I improve it to fit my data rule like add array type in script and remove the different talbe name in xls and so on.

Any way , you can choose one that more fit your project.

(这个脚本是从 https://github.com/zfengzhen/xls2lua 继承过来的,我改进了很多东西,也去除了很多东西,我改成了适合我自己的脚本。不管怎样,你可以选择一个适合你的脚本去运行。)

Example(例子xls表格)

example_building.xls

id name use_money use_food is_init defense args1 args2 args3 args4
i s i f b i ai af as ab
1 house 1000 2.33 TRUE 100 1;2;3 1.23;2;3.23 sdf;23e;s true;false;true
2 house2 123 336.2 TRUE 1;2;3 1;2.3445;3 你好;你在哪 true;false
3 456 222.33665 FALSE 130 3;2;5;; 3;2;2.5;; 我在这里啊;你在那;呢 false;true
4 farm 100 220 FALSE 200 2;3; 200.3;3;234.23; df;ssd;dd;dd
5 house5 22.1 2343;6;6;;;7 3;6.3;6;;;7 ss;d;d;d true;true
6 horse3 200 FALSE 333 2e;w;e;we false;false;false;false

Excute Example (举例执行命令)

python ./xls2lua.py example_building.xls ./data/

NOTICE:(注意点)

The sheet name must start with "output_" , the lua file name will be the name behind "output_".
The first row must be title.
The second row must be type
The **type must be i , f , s , b , ai , af , as , ab.
i mean int , f mean float , s mean string , b mean bool , ai mean array int , af mean array float , as mean array string , ab mean array bool.
The first column must be int , so the type in first column must be i.
The string type with char " or ' will be replace by " or '
The empty col will be a default value like 0 or "" or false or {}
(sheet名以"output_"开头的才会被识别转换,否则将被忽略)
(第1行必须是关键字名)
(第2行必须为类型)
(类型有:i,f,s,b,ai,af,as,ab这几种)
(i表示int,f表示float,s表示string,b表示bool,ai表示int数组,af表示float数组,as表示string数组,ab表示bool数组)
(第1列必须为int类型的唯一关键字)
(string类型中"和'会自动用"和'替代) (空列将会被默认值代替,例如:0,"",false,{})

Lua script (生成后的Lua文件示例)

-- this file is generated by program!
-- don't change it manaully.
-- source file: example_building.xls
-- created at: Thu Mar 26 02:53:52 2015

local data = {}

data[1] = { id = 1,  name = "house",  use_money = 1000,  use_food = 2.33,  is_init = true,  defense = 100,  aadd = {1,2,3},  aadddss = {1.23,2,3.23},  ddff = {"sdf","23e","s"},  ffdd = {true,false,true}}
data[2] = { id = 2,  name = "house2",  use_money = 123,  use_food = 336.2,  is_init = true,  defense = 0,  aadd = {1,2,3},  aadddss = {1,2.3445,3},  ddff = {"你好","你在哪"},  ffdd = {true,false}}
data[3] = { id = 3,  name = "",  use_money = 456,  use_food = 222.33665,  is_init = false,  defense = 130,  aadd = {3,2,5},  aadddss = {3,2,2.5},  ddff = {"我在这里啊","你在那",""},  ffdd = {false,true}}
data[4] = { id = 4,  name = "farm",  use_money = 100,  use_food = 220.0,  is_init = false,  defense = 200,  aadd = {2,3},  aadddss = {200.3,3,234.23},  ddff = {"df","ssd","dd","dd"},  ffdd = {}}
data[5] = { id = 5,  name = "house5",  use_money = 0,  use_food = 22.1,  is_init = false,  defense = 234,  aadd = {3,6,6,7},  aadddss = {3,6.3,6,7},  ddff = {"ss","d","d","d"},  ffdd = {true,true}}
data[6] = { id = 6,  name = "horse3",  use_money = 200,  use_food = 0,  is_init = false,  defense = 333,  aadd = {},  aadddss = {},  ddff = {"2e","w","e","we"},  ffdd = {false,false,false,false}}

return data

How to use lua with data. (如何使用生成的lua数据)

local building = require "building"

print(building[1].name)

The console will print "house"




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
RedisLabs/geo.lua: A helper library for Redis geospatial indices发布时间:2022-08-16
下一篇:
bakpakin/binser: Customizable Lua Serializer发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap