2020-08-09 09:54:42 -06:00
|
|
|
local _ENV = mkmodule('plugins.xlsxreader')
|
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Native functions:
|
|
|
|
|
|
|
|
* file_handle open_xlsx_file(filename)
|
|
|
|
* close_xlsx_file(file_handle)
|
|
|
|
* sheet_names list_sheets(file_handle)
|
|
|
|
|
|
|
|
* sheet_handle open_sheet(file_handle, sheet_name)
|
|
|
|
* close_sheet(sheet_handle)
|
|
|
|
* cell_strings get_row(sheet_handle)
|
|
|
|
|
2020-08-09 10:28:19 -06:00
|
|
|
Sample usage:
|
|
|
|
|
|
|
|
local xlsxreader = require('plugins.xlsxreader')
|
|
|
|
|
2020-08-10 10:18:49 -06:00
|
|
|
local function dump_sheet(xlsx_file, sheet_name)
|
2020-08-09 10:28:19 -06:00
|
|
|
print('reading sheet: '..sheet_name)
|
|
|
|
local xlsx_sheet = xlsxreader.open_sheet(xlsx_file, sheet_name)
|
2020-08-10 10:18:49 -06:00
|
|
|
dfhack.with_finalize(
|
|
|
|
function () xlsxreader.close_sheet(xlsx_sheet) end,
|
|
|
|
function ()
|
|
|
|
local row_cells = xlsxreader.get_row(xlsx_sheet)
|
|
|
|
while row_cells do
|
|
|
|
printall(row_cells)
|
|
|
|
row_cells = xlsxreader.get_row(xlsx_sheet)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2020-08-09 10:28:19 -06:00
|
|
|
end
|
2020-08-10 10:18:49 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
2020-08-09 10:28:19 -06:00
|
|
|
|
2020-08-09 09:54:42 -06:00
|
|
|
--]]
|
|
|
|
|
|
|
|
return _ENV
|