Skip to content

Commit

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

local function find_sheet_data_struct(sheet)
local header = {}
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
-- 读取第四行作为表头
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] = get_sheet_value(sheet, type_line, col)
field_types[col] = field_type
end
-- 读取第四行作为表头
header[col] = get_sheet_value(sheet, head_line, col)
end
return header, field_types
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 @@ -352,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 8930a28

Please sign in to comment.