Closed henriquesobral closed 9 years ago
Please upload the script to gist.github.com and link it here. Also upload your sample file somewhere and link it here.
I'm facing the same issue. I can replicate it with this test:
require 'rails_helper'
RSpec.describe "ExportExcel" do
it "Reopens spreadsheet" do
filename = 'test.xls'
sheet_name = 'Test Sheet'
# Create excel
excel = Spreadsheet::Workbook.new(filename)
sheet = excel.create_worksheet(name: sheet_name)
sheet.row(1).replace ['Data']
excel.write(filename)
# Append something
excel = Spreadsheet.open(filename, 'a+')
sheet = excel.worksheet(sheet_name)
sheet.row(2).replace ['Data2']
excel.write(filename)
# Reopen
excel = Spreadsheet.open filename # Crashes here
sheet = excel.worksheet sheet_name
end
end
I see that you're using minitest on your test suite. Let me try to translate it and I'll post it here. Edit: porting to minitest should be trivial, let me know if you need more info.
I need a simpel test script with a test file so I can replicate your issue. The sample should not contain any dependencies on Rails. Link it all here please.
Hi,
Add this method to test/integration.rb
:
def test_append_and_reopen
puts "Testing append and reopen"
filename = 'test.xls'
sheet_name = 'Test Sheet'
# Create excel
excel = Spreadsheet::Workbook.new(filename)
sheet = excel.create_worksheet(name: sheet_name)
sheet.row(1).replace ['Data']
excel.write(filename)
# Append something
excel = Spreadsheet.open(filename, 'a+')
sheet = excel.worksheet(sheet_name)
sheet.row(2).replace ['Data2']
excel.write(filename)
# Reopen
excel = Spreadsheet.open filename # Crashes here
sheet = excel.worksheet sheet_name
end
or in patch format:
diff --git a/test/integration.rb b/test/integration.rb
index 906f604..481dd69 100644
--- a/test/integration.rb
+++ b/test/integration.rb
@@ -1402,6 +1402,27 @@ module Spreadsheet
book.worksheet(0).row(0)
end
end
+ def test_append_and_reopen
+ puts "Testing append and reopen"
+ filename = 'test.xls'
+ sheet_name = 'Test Sheet'
+
+ # Create excel
+ excel = Spreadsheet::Workbook.new(filename)
+ sheet = excel.create_worksheet(name: sheet_name)
+ sheet.row(1).replace ['Data']
+ excel.write(filename)
+
+ # Append something
+ excel = Spreadsheet.open(filename, 'ab+')
+ sheet = excel.worksheet(sheet_name)
+ sheet.row(2).replace ['Data2']
+ excel.write(filename)
+
+ # Reopen
+ excel = Spreadsheet.open filename # Crashes here
+ sheet = excel.worksheet sheet_name
+ end
private
# Validates the workbook's SST
It doesn't need any dependencies or example .xls file. Thanks in advance.
Thank you! Please send me a pull request.
Just to be sure we're on the same page, should I make a PR of the test itself? That's the best I can do for now; I've been trying to find out where the problem is, but I haven't been able to fix it.
Ok, then lets wait some more time, until you have the solution and then send me the pull request.
I'm using this gem to create and update spreadsheets, but when I try to open a spreadsheet created by this gem, I'm getting the following error:
How do I proceed?
Thanks.