#16239 - Fix linebreaks in excel export

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@1013 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
t.felgentreff 15 years ago
parent c6187b73f6
commit 89c9aece9d
  1. 2
      lib/xls_report/spreadsheet_builder.rb
  2. 11
      spec/helpers/spreadsheet_builder_spec.rb

@ -99,7 +99,7 @@ class SpreadsheetBuilder
value = if ['Time', 'Date', 'Fixnum', 'Float', 'Integer'].include?(c.class.name)
c
else
c.to_s.gsub('_', ' ').gsub("\n", "\r\n").gsub("\r", "\r\n")
c.to_s.gsub('_', ' ').gsub("\r\n", "\n").gsub("\r", "\n")
end
column_array << value
@column_widths[i] = 0 if @column_widths[i].nil?

@ -81,9 +81,12 @@ describe "SpreadsheetBuilder" do
@sheet.last_row.format(0).should == @sheet.last_row.format(1)
end
it "should always use windows newlines" do
@spreadsheet.add_row(["Some text including a unix newline (\n)", "And an old-style mac os newline (\r)"])
@spreadsheet.send("raw_sheet").last_row[0].should include("\r\n")
@spreadsheet.send("raw_sheet").last_row[1].should include("\r\n")
it "should always use unix newlines" do
@spreadsheet.add_row(["Some text including a windows newline (\r\n)", "And an old-style mac os newline (\r)"])
2.times do |i|
@spreadsheet.send("raw_sheet").last_row[i].should_not include("\r")
@spreadsheet.send("raw_sheet").last_row[i].should_not include("\r\n")
@spreadsheet.send("raw_sheet").last_row[i].should include("\n")
end
end
end
Loading…
Cancel
Save