当前位置:网站首页>Excel转换为Lua的配置文件
Excel转换为Lua的配置文件
2022-07-06 05:02:00 【帅_shuai_】
Excel转换为Lua的配置文件
1.下载Excel转Lua的第三方库
首先我们下载一个第三方开源库,来给Excel表生成lua配置文件,下载地址https://github.com/XINCGer/Unity3DTraining/tree/master/XlsxTools
2.准备生成Lua配置文件
- 在跟Assets平级的目录下,新建一个Tools文件夹,然后把下载的XlsxTools文件夹放在这里
- 然后在debug模式下编译这个解决方案

这个文件有几点需要注意:
excel文件必须保存为.xls格式,而不是.xlsx格式
左下角的tab页签名字必须个文件名一样,并且加一个#前缀,比如我的这个CharacterTable文件,tab页签名字是#CharacterTable
excel的前4行是有特殊含义的:
第1行是每个字段的名字说明
第2行是每个字段的变量类型,一般只支持int和string类型
第3行是每个字段的变量名字,这个变量名字是可以在代码中直接使用的
第4行是注释,可以详细解释这个字段的含义

还有最重要的一点:首字段必须是int型,并且变量名必须是Id
- 配置.ini文件,设置Excel读取和输出的路径
- 接下来,我们在Tools文件夹下新建一个ExcelToLua.bat文件,用来自动将Excel文件生成出对应的lua文件
cd ./XlsxTools/Xls2Lua/Xls2Lua/bin/Debug/
Xls2Lua ^
pause
双击运行即可生成Lua配置文件
3.使用Lua配置文件
- 创建ExcelMgr 来管理所有的lua配置文件
ExcelMgr = {
}
-- Excel表管理器
ExcelMgr.CacheTable = {
}
ExcelMgr.CacheTableRow = {
}
function ExcelMgr:GetTable(tableName)
local oneTable = self.CacheTable[tableName]
if oneTable ~= nil then
return oneTable
end
oneTable = require(tableName)
self.CacheTable[tableName] = oneTable
return self.CacheTable[tableName]
end
function ExcelMgr:GetRow(tableName, id)
if self.CacheTableRow[tableName] == nil then
local oneTable = self:GetTable(tableName)
self.CacheTableRow[tableName] = {
}
for _,v in ipairs(oneTable) do
self.CacheTableRow[tableName][v.Id]= v
end
end
if self.CacheTableRow[tableName] then
return self.CacheTableRow[tableName][id]
end
end
return ExcelMgr
边栏推荐
- Yolov5 tensorrt acceleration
- 从0到1建设智能灰度数据体系:以vivo游戏中心为例
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Postman test report
- Bubble sort
- ISP学习(2)
- What should the project manager do if there is something wrong with team collaboration?
- Class inheritance in yyds dry inventory C
- Extension of graph theory
- Supreme Court, judgment standard of divorce cases
猜你喜欢

Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected

Postman前置脚本-全局变量和环境变量

DMA use of stm32

A blog to achieve embedded entry

Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago

Application of Flody

GAMES202-WebGL中shader的編譯和連接(了解向)

麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東

Flink kakfa data read and write to Hudi

Compilation and connection of shader in games202 webgl (learn from)
随机推荐
Fuzzy -- basic application method of AFL
Postman manage test cases
Vite configures the development environment and production environment
Yyds dry inventory SSH Remote Connection introduction
Summary of redis AOF and RDB knowledge points
Yolov5 tensorrt acceleration
Postman前置脚本-全局变量和环境变量
Crazy God said redis notes
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Realize a binary read-write address book
Programmers' position in the Internet industry | daily anecdotes
2021 robocom world robot developer competition - undergraduate group (semi-finals)
Postman管理测试用例
麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
Class inheritance in yyds dry inventory C
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
集合详解之 Collection + 面试题
Orm-f & Q object