Created
April 8, 2011 07:09
-
-
Save zdavatz/909425 to your computer and use it in GitHub Desktop.
spreadsheet-patch-fonsan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## changes to excel/writer/worksheet.rb by fonsan | |
module Spreadsheet | |
module Excel | |
module Writer | |
def write_cellblocks row | |
# BLANK ➜ 6.7 | |
# BOOLERR ➜ 6.10 | |
# INTEGER ➜ 6.56 (BIFF2 only) | |
# LABEL ➜ 6.59 (BIFF2-BIFF7) | |
# LABELSST ➜ 6.61 (BIFF8 only) | |
# MULBLANK ➜ 6.64 (BIFF5-BIFF8) | |
# MULRK ➜ 6.65 (BIFF5-BIFF8) | |
# NUMBER ➜ 6.68 | |
# RK ➜ 6.82 (BIFF3-BIFF8) | |
# RSTRING ➜ 6.84 (BIFF5/BIFF7) | |
multiples, first_idx = nil | |
row = row.formatted | |
row.each_with_index do |cell, idx| | |
cell = nil if cell == '' | |
//// Patch fonsan \\\\ | |
unless cell | |
write_blank(row, idx) | |
else | |
\\\\ Patch fonsan //// | |
## it appears that there are limitations to RK precision, both for | |
# Integers and Floats, that lie well below 2^30 significant bits, or | |
# Ruby's Bignum threshold. In that case we'll just write a Number | |
# record | |
need_number = need_number? cell | |
if multiples && (!multiples.last.is_a?(cell.class) || need_number) | |
write_multiples row, first_idx, multiples | |
multiples, first_idx = nil | |
end | |
nxt = idx + 1 | |
case cell | |
when NilClass | |
if multiples | |
multiples.push cell | |
elsif nxt < row.size && row[nxt].nil? | |
multiples = [cell] | |
first_idx = idx | |
else | |
write_blank row, idx | |
end | |
when TrueClass, FalseClass, Error | |
write_boolerr row, idx | |
when String | |
write_labelsst row, idx | |
when Numeric | |
## RK encodes Floats with 30 significant bits, which is a bit more than | |
# 10^9. Not sure what is a good rule of thumb here, but it seems that | |
# Decimal Numbers with more than 4 significant digits are not represented | |
# with sufficient precision by RK | |
if need_number | |
write_number row, idx | |
elsif multiples | |
multiples.push cell | |
elsif nxt < row.size && row[nxt].is_a?(Numeric) | |
multiples = [cell] | |
first_idx = idx | |
else | |
write_rk row, idx | |
end | |
when Formula | |
write_formula row, idx | |
when Date, Time | |
write_number row, idx | |
end | |
end | |
end | |
write_multiples row, first_idx, multiples if multiples | |
end | |
end | |
end | |
end | |
## changes to excel/writer/workbook.rb by fonsan | |
class Workbook | |
def sanitize_worksheets sheets | |
found_selected = false | |
sheets.each do |sheet| | |
found_selected ||= sheet.selected | |
//// Patch by fonsan \\\\ | |
#sheet.format_dates! | |
\\\\ Patch by fonsan //// | |
end | |
unless found_selected | |
sheets.first.selected = true | |
end | |
sheets | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial Email by fonsan: http://groups.google.com/group/rubyspreadsheet/browse_thread/thread/809efbe0a63c7c73