update sample code for xlsxreader to use finalize

develop
Myk Taylor 2020-08-10 09:18:49 -07:00
parent 69322ec429
commit 17c509a596
1 changed files with 22 additions and 10 deletions

@ -16,19 +16,31 @@ Sample usage:
local xlsxreader = require('plugins.xlsxreader') local xlsxreader = require('plugins.xlsxreader')
local filepath = "path/to/some_file.xlsx" local function dump_sheet(xlsx_file, sheet_name)
local xlsx_file = xlsxreader.open_xlsx_file(filepath)
for _, sheet_name in ipairs(xlsxreader.list_sheets(xlsx_file)) do
print('reading sheet: '..sheet_name) print('reading sheet: '..sheet_name)
local xlsx_sheet = xlsxreader.open_sheet(xlsx_file, sheet_name) local xlsx_sheet = xlsxreader.open_sheet(xlsx_file, sheet_name)
local row_cells = xlsxreader.get_row(xlsx_sheet) dfhack.with_finalize(
while row_cells do function () xlsxreader.close_sheet(xlsx_sheet) end,
printall(row_cells) function ()
row_cells = xlsxreader.get_row(xlsx_sheet) local row_cells = xlsxreader.get_row(xlsx_sheet)
end while row_cells do
xlsxreader.close_sheet(xlsx_sheet) printall(row_cells)
row_cells = xlsxreader.get_row(xlsx_sheet)
end
end
)
end end
xlsxreader.close_xlsx_file(xlsx_file)
local filepath = "path/to/some_file.xlsx"
local xlsx_file = xlsxreader.open_xlsx_file(filepath)
dfhack.with_finalize(
function () xlsxreader.close_xlsx_file(xlsx_file) end,
function ()
for _, sheet_name in ipairs(xlsxreader.list_sheets(xlsx_file)) do
dump_sheet(xlsx_file, sheet_name)
end
end
)
--]] --]]