简体   繁体   English

如何使用Ruby Spreadsheet库格式化特定单元格?

[英]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 电子表格库位于: http//spreadsheet.rubyforge.org/ http://spreadsheet.rubyforge.org/GUIDE_txt.html

Use set_format method: 使用set_format方法:

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM