开发者

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:开发者_JAVA百科//spreadsheet.rubyforge.org/ http://spreadsheet.rubyforge.org/GUIDE_txt.html


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜