如何使用rubyXL gem关闭打开的工作簿

时间:2017-05-27 06:21:52

标签: ruby excel rubyxl

我使用下面的代码从工作表中读取和写入。但是当工作表已经打开并且我尝试运行代码时由于权限错误而失败。我想确保当我点击运行时打开excel文件应该关闭。

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")

0 个答案:

没有答案