Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I format a specific cell using the Ruby Spreadsheet library?

Formatting a column or row seems to be no problem. I've poked around the documentation a bunch, did some searches, and looked through the "methods" result on some spreadsheet objects and I can't figure out how to format a specific cell. Has anyone done this?

The Spreadsheet library is here: http://spreadsheet.rubyforge.org/ http://spreadsheet.rubyforge.org/GUIDE_txt.html

like image 328
Tony Avatar asked May 13 '11 20:05

Tony


1 Answers

Use set_format method:

require 'spreadsheet'
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet

format = Spreadsheet::Format.new :color => :blue,
                                 :weight => :bold,
                                 :size => 18
row = sheet1.row(0)
row[0] = 'test0'
row[1] = 'test1'
row.set_format(0, format) # set format for the first cell

book.write 'C:\\test.xls'
like image 111
Vasiliy Ermolovich Avatar answered Oct 10 '22 00:10

Vasiliy Ermolovich