I have used below code to read and write from worksheet.But when the worksheet is already in open and if I try to run the code its failing because of permission error.I want to make sure when I hit the run the opened excel file should close.
require 'rubyXL'
# reading from excel
workbook=RubyXL::Parser.parse("#{Dir.pwd}/test.xlsx")
# here I want to make sure the excel get closed
#workbook.close -> this code not working
worksheet= workbook['Sheet1']
header_row=worksheet.sheet_data[1]
header_data=Array.new
header_row.size.times do |i|
header_data<<header_row[i].value
end
#writing to excel
worksheet.add_cell(0,2,'Pass')
worksheet.add_cell(0,3,'Fail')
workbook.write("#{Dir.pwd}/test.xlsx")