lib/spreadsheet/excel/writer/worksheet.rb in spreadsheet-0.6.3.1 vs lib/spreadsheet/excel/writer/worksheet.rb in spreadsheet-0.6.4
- old
+ new
@@ -46,12 +46,13 @@
return date if date.is_a? Numeric
if date.is_a? Time
date = DateTime.new date.year, date.month, date.day,
date.hour, date.min, date.sec
end
- value = date - @workbook.date_base
- if date > LEAP_ERROR
+ base = @workbook.date_base
+ value = date - base
+ if LEAP_ERROR > base
value += 1
end
value
end
def encode_rk value
@@ -84,13 +85,23 @@
end
def name
unicode_string @worksheet.name
end
def need_number? cell
- (cell.is_a?(Numeric) && cell.abs > 0x1fffffff) \
- || (cell.is_a?(Float) \
- && !/^[\000\001]\000{3}/.match([cell * 100].pack(EIGHT_BYTE_DOUBLE)))
+ if cell.is_a?(Numeric) && cell.abs > 0x1fffffff
+ true
+ elsif cell.is_a?(Float)
+ higher = cell * 100
+ if higher == higher.to_i
+ need_number? higher.to_i
+ else
+ test1, test2 = [cell * 100].pack(EIGHT_BYTE_DOUBLE).unpack('V2')
+ test1 > 0 || need_number?(test2)
+ end
+ else
+ false
+ end
end
def row_blocks
# All cells in an Excel document are divided into blocks of 32 consecutive
# rows, called Row Blocks. The first Row Block starts with the first used
# row in that sheet. Inside each Row Block there will occur ROW records
@@ -499,19 +510,21 @@
# 8 0x00000100 0 = File link or URL
# 1 = UNC path (incl. server name)
].pack('V2')
tail = []
+ ## call internal to get the correct internal encoding in Ruby 1.9
+ nullstr = internal "\000"
unless link == link.url
- desc = internal(link).dup << "\000\000"
+ desc = internal(link).dup << nullstr
tail.push [desc.size / 2].pack('V'), desc
end
if link.target_frame
- frme = internal(link.target_frame).dup << "\000\000"
+ frme = internal(link.target_frame).dup << nullstr
tail.push [frme.size / 2].pack('V'), frme
end
- url = internal(link.url).dup << "\000\000"
+ url = internal(link.url).dup << nullstr
tail.push [
# 6.53.2 Hyperlink containing a URL (Uniform Resource Locator)
# These data fields occur for links which are not local files or files
# in the local network (for instance HTTP and FTP links and e-mail
# addresses). The lower 9 bits of the option flags field must be
@@ -524,11 +537,11 @@
url.size # Size of character array of the URL, including trailing zero
# word (us). There are us/2-1 characters in the following
# string.
].pack('H32V'), url
if link.fragment
- frag = internal(link.fragment).dup << "\000\000"
+ frag = internal(link.fragment).dup << nullstr
tail.push [frag.size / 2].pack('V'), frag
end
write_op opcode(:hlink), cell_range, guid, options, *tail
end
def write_hyperlink_table
@@ -689,12 +702,12 @@
opts |= 0x00000080
opts |= xf_idx << 16
end
opts |= 0x00000100
height = if height == ROW_HEIGHT
- height * TWIPS
+ (height * TWIPS).to_i | 0x8000
else
- ( height * TWIPS ) | 0x8000
+ height * TWIPS
end
# TODO: Row spacing
data = [
row.idx,
row.first_used,