Skip to content

Commit

Permalink
扩展导表工具参数
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Apr 23, 2024
2 parents f51ba7e + 59cf5b3 commit afa3da1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tools/excel2lua/convertor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,27 @@ local function export_records_to_json(output, title, fname, records)
end

local function find_sheet_data_struct(sheet)
local header = {}
local field_type = {}
local headers = {}
local field_types = {}
if not head_line then
head_line = start_line - 1
end
for col = sheet.first_col, sheet.last_col do
-- 读取类型行,作为筛选条件
field_type[col] = get_sheet_value(sheet, type_line, col)
-- 读取第四行作为表头
header[col] = get_sheet_value(sheet, head_line, col)
headers[col] = get_sheet_value(sheet, head_line, col)
-- 读取类型行,作为筛选条件
local field_type = get_sheet_value(sheet, type_line, col)
if field_type and field_type ~= "" then
field_types[col] = field_type
end
end
return header, field_type
return headers, field_types
end

--导出到目标文件
local function export_sheet_to_output(sheet, output, fname, shname)
local header, field_type = find_sheet_data_struct(sheet)
if tsize(field_type) <= 1 then
local headers, field_types = find_sheet_data_struct(sheet)
if tsize(field_types) <= 1 then
--未定义数据定义,不导出此sheet
print(sformat("export excel %s sheet %s not need export!", fname, shname))
return
Expand Down Expand Up @@ -349,10 +352,10 @@ local function export_sheet_to_output(sheet, output, fname, shname)
-- 遍历每一列
for col = start_row, sheet.last_col do
-- 过滤掉没有配置的行
if field_type[col] and header[col] then
local value = get_sheet_value(sheet, row, col, field_type[col], header[col])
if field_types[col] and headers[col] then
local value = get_sheet_value(sheet, row, col, field_types[col], headers[col])
if value ~= nil then
tinsert(record, {header[col], value, field_type[col]})
tinsert(record, {headers[col], value, field_types[col]})
end
end
end
Expand Down

0 comments on commit afa3da1

Please sign in to comment.