google-drive-ruby icon indicating copy to clipboard operation
google-drive-ruby copied to clipboard

Inserting numeric values (making it possible to write serial number dates/times)

Open Drowze opened this issue 5 years ago • 0 comments

#380 - tests are passing

I had to patch Worksheet#[]= method to, instead of setting @numeric_values[[row, cel]] always to nil, to set it to the value itself if it's a numeric value or nil otherwise. Having the numeric value saved, I can use it on #save and that's enough for Google to parse the value as numeric if adequate.

Worksheet#[]= and Worksheet#[] APIs should be untouched, while Worksheet#numeric_value behaviour have changed a bit.

before:

ws[1, 1] = 8
ws[1, 2] = '8'
ws.numeric_value(1, 1) # => nil
ws.numeric_value(1, 2) # => nil
ws.synchronize
ws.numeric_value(1, 1) #=> 8
ws.numeric_value(1, 2) #=> 8

# if it's a date cell
ws[1, 3] = 8
ws[1, 4] = '8'
ws[1, 3] #=> '8'
ws[1, 4] #=> '8'
ws.synchronize
ws[1, 3] #=> '8'
ws[1, 4] #=> '8'

after:

ws[1, 1] = 8
ws[1, 2] = '8'
ws.numeric_value(1, 1) # => 8
ws.numeric_value(1, 2) # => nil
ws.synchronize
ws.numeric_value(1, 1) #=> 8
ws.numeric_value(1, 2) # => 8

# if it's a date cell
ws[1, 3] = 8
ws[1, 4] = '8'
ws[1, 3] #=> '8'
ws[1, 4] #=> '8'
ws.synchronize
ws[1, 3] #=> 7/1/1900 # or whatever is the date format on the cell
ws[1, 4] #=> '8'

Drowze avatar Jul 23 '20 23:07 Drowze