Question

I'm using RubyXL to dynamically generate a spreadsheet file that contains some dates. The documentation is kind of sparse so I've been looking at the source, and it appears the library only has special handling for Date and DateTime when you call change_contents, so that's what I'm doing:

cell = sheet.add_cell_obj RubyXL::Cell.new(sheet, row_index, col_index)
cell.change_contents(Time.now.to_datetime)

When I create a spreadsheet this way, Excel does not format those cells as dates. I'm guessing that I need to set some other field, perhaps cell.datatype, but I'm not sure. Or maybe I'm barking up the wrong tree. Does anybody know what to do?

Was it helpful?

Solution

See https://github.com/weshatheleopard/rubyXL/issues/210

c = workbook[0].add_cell(0,0)
c.set_number_format('m/d/yy')
c.change_contents(Date.today)

OTHER TIPS

After finally forking the library and attempting to fix it myself, I've decided that RubyXL is a mess beyond repair. Fortunately, before descending completely into madness, I discovered Axlsx, a much better written, actively supported Ruby gem. Ditch RubyXL and use Axlsx instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top