Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a date-formatted cell using RubyXL?

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?

like image 982
benzado Avatar asked Oct 27 '12 20:10

benzado


1 Answers

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)
like image 138
Winston Kotzan Avatar answered Nov 07 '22 04:11

Winston Kotzan