Saad Rehman Shah
Saad Rehman Shah

Reputation: 946

How to format a Spreadsheet cell via Ruby gem?

I am using the following Spreadsheet gem to generate an excel sheet from ruby-on-rails.. http://spreadsheet.rubyforge.org/GUIDE_txt.html

I want to format a cell such that I can see it's top and bottom border, but not any other. Is there anybody who's been there and done that, and knows how to?

http://spreadsheet.rubyforge.org/Spreadsheet/Format.html

The - (Object) border=(boolean) Activate or deactivate all four borders (left, right, top, bottom).

Upvotes: 1

Views: 6600

Answers (4)

Kalyani
Kalyani

Reputation: 11

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

Reference:https://github.com/zdavatz/spreadsheet/blob/master/lib/spreadsheet/format.rb

Upvotes: 1

nerdinand
nerdinand

Reputation: 876

How about this:

book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
format = Spreadsheet::Format.new
format.bottom = true
format.top = true
sheet.rows[4].set_format(8, format)

Upvotes: 6

randym
randym

Reputation: 36

If you are generating excel, axlsx and the rails plugin acts_as_xlsx is probably your best bet.

http://rubygems.org/gems/axlsx

Upvotes: 2

Soundar Rathinasamy
Soundar Rathinasamy

Reputation: 6728

Hi I am not sure but this gem might be helpful to you.

http://roo.rubyforge.org/

Upvotes: 0

Related Questions