Method: BCL::ComponentFromSpreadsheet#initialize
- Defined in:
- lib/bcl/component_from_spreadsheet.rb
#initialize(xlsx_path, worksheet_names = ['all']) ⇒ ComponentFromSpreadsheet
initialize with Excel spreadsheet to read seems to only be working with xls spreadsheets
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bcl/component_from_spreadsheet.rb', line 21 def initialize(xlsx_path, worksheet_names = ['all']) @xlsx_path = Pathname.new(xlsx_path).realpath.to_s @worksheets = [] begin xlsx = Spreadsheet.open(@xlsx_path) # by default, operate on all worksheets if worksheet_names == ['all'] xlsx.worksheets.each do |xlsx_worksheet| parse_xlsx_worksheet(xlsx_worksheet) end else # if specific worksheets are specified, operate on them worksheet_names.each do |worksheet_name| parse_xlsx_worksheet(xlsx.worksheet(worksheet_name)) end end # save spreadsheet if changes have been made if @@changed xlsx.write(@xlsx_path) puts '[ComponentFromSpreadsheet] Spreadsheet changes saved' end ensure xlsx = nil end end |