summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStefan <[email protected]>2022-09-26 20:16:59 +0200
committerStefan <[email protected]>2022-09-26 20:16:59 +0200
commitbcc88ca556b3b8527ba0ad56424f93ef170b9c31 (patch)
treee6251486043e03f4d7def5dbac4bf043540dbc2a
parent2ed0f25b31aa7ced3ff4e1f8307424be7624c667 (diff)
downloadcaxlsx-bcc88ca556b3b8527ba0ad56424f93ef170b9c31.tar.gz
caxlsx-bcc88ca556b3b8527ba0ad56424f93ef170b9c31.zip
Make sure all examples and docs use binary mode for reading / writing XLSX files
Not using binary mode can cause encoding issues, see #138.
-rw-r--r--examples/stream_example.md2
-rw-r--r--lib/axlsx/package.rb2
-rw-r--r--lib/axlsx/stylesheet/styles.rb6
-rw-r--r--test/benchmark.rb2
4 files changed, 6 insertions, 6 deletions
diff --git a/examples/stream_example.md b/examples/stream_example.md
index 409cc8fb..1d2af693 100644
--- a/examples/stream_example.md
+++ b/examples/stream_example.md
@@ -16,7 +16,7 @@ wb.add_worksheet(name: 'Basic Worksheet') do |sheet|
end
stream = p.to_stream
-File.open('stream_example.xlsx', 'w') { |f| f.write(stream.read) }
+File.open('stream_example.xlsx', 'wb') { |f| f.write(stream.read) }
```
## Output
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 2faec2e3..ccabf799 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -99,7 +99,7 @@ module Axlsx
#
# # Serialize to a stream
# s = p.to_stream()
- # File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
+ # File.open('example_streamed.xlsx', 'wb') { |f| f.write(s.read) }
def serialize(output, options = {}, secondary_options = nil)
confirm_valid, zip_command = parse_serialize_options(options, secondary_options)
return false unless !confirm_valid || self.validate.empty?
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb
index 6bfd0a52..fd741ac5 100644
--- a/lib/axlsx/stylesheet/styles.rb
+++ b/lib/axlsx/stylesheet/styles.rb
@@ -156,7 +156,7 @@ module Axlsx
# ws.add_row ["Least Popular Pets"]
# ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
# ws.add_row ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
- # f = File.open('example_you_got_style.xlsx', 'w')
+ # f = File.open('example_you_got_style.xlsx', 'wb')
# p.serialize(f)
#
# @example Styling specifically
@@ -190,7 +190,7 @@ module Axlsx
# ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
# ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
# ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
- # f = File.open('example_you_got_style.xlsx', 'w')
+ # f = File.open('example_you_got_style.xlsx', 'wb')
# p.serialize(f)
#
# @example Differential styling
@@ -216,7 +216,7 @@ module Axlsx
# ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
#
# ws.add_conditional_formatting("A1:A7", { :type => :cellIs, :operator => :greaterThan, :formula => "2000", :dxfId => profitable, :priority => 1 })
- # f = File.open('example_differential_styling', 'w')
+ # f = File.open('example_differential_styling', 'wb')
# p.serialize(f)
#
def add_style(options={})
diff --git a/test/benchmark.rb b/test/benchmark.rb
index b1162591..8d90cdf5 100644
--- a/test/benchmark.rb
+++ b/test/benchmark.rb
@@ -58,7 +58,7 @@ Benchmark.bmbm(30) do |x|
end
end
s = p.to_stream()
- File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
+ File.open('example_streamed.xlsx', 'wb') { |f| f.write(s.read) }
}
x.report('csv') {