开发者

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

开发者 https://www.devze.com 2023-03-06 06:31 出处:网络
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 fi

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

精彩评论

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