Here are a few examples with Spreadsheet gem

#Defining formats

float_format   = Spreadsheet::Format.new :number_format => "#,##0"
percent_format = Spreadsheet::Format.new :number_format => "0.00%"
bold_format    = Spreadsheet::Format.new :weight => :bold
cell_format    = Spreadsheet::Format.new :bottom => :medium,
                                         :horizontal_align => :center,
                                         :weight => :bold

#Implementation

sheet.default_format = float_format.                    #Format sheet
sheet.column(col_idx).default_format = percent_format   #Format a column
sheet.row(row_idx).default_format = bold_format         #Format a row
sheet.row(row_idx).set_format(col_idx, cell_format)     #Format a cell

sheet.column(1).width = 12                              #Format column width

  

posted @ 2023-05-23 11:02  鞋带松了  阅读(9)  评论(0编辑  收藏  举报