Change the cell format as MM/DD/YYYY in Spreadsheet gem on Ruby On Rails

Change the cell format with the following simple example.

Create the local variable using Spreadsheet::Format.new  then assign it to the particular column as  default_fomat. Here in my example states as column(1) means that is changing the second column as the date format.

Sample Code:

sheet = doc.create_worksheet(:name => "#{new_sheet_name}")
df = Spreadsheet::Format.new :number_format => 'MM/DD/YYYY'
sheet.column(1).default_format = df

Reference:  spreadsheet.rubyforge.org/

Leave a Reply