I have a daily-downloaded (using mechanize & whenever/sidekiq+redis) .xls file with two worksheets and want to split them into two files, with each having one sheet. I've tried many ways to no avail (tossed in a random delete
method hoping that would work, nope):
# goal: start with 1 file w/2 sheets and split into 2 files with 1 sheet each
def split_file
open_xls = Spreadsheet.open 'my_file.xls'
open_xls.write 'destination1.xls'
open_xls.write 'destination2.xls'
File.delete('my_file.xls')
# open first new file and try to delete one sheet
open_xls1 = Spreadsheet.open 'destination1.xls'
sheet1 = open_xls1.worksheet(0)
open_xls1.sheet1.delete # from log: "NoMethodError: undefined method `delete'"
open_xls1.write 'destination_only_sheet2.xls'
# "" other sheet
# repeat on 2nd file to remove other sheet
end
Starting thinking "does spreadsheet gem treat workbooks like arrays--can I use Array methods?"...then threw up the hands.
Main spreadsheet-gem resources: