我正在使用以下Spreadsheet gem从ruby-on-rails生成excel表格。http://spreadsheet.rubyforge.org/GUIDE_txt.html
我想格式化一个单元格,以便我可以看到它的顶部和底部边框,但不是任何其他边框。有没有人去过那里并且知道如何做到?
http://spreadsheet.rubyforge.org/Spreadsheet/Format.html
- (对象)border =(boolean) 激活或停用所有四个边框(左,右,上,下)。
答案 0 :(得分:5)
这个怎么样:
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)
答案 1 :(得分:2)
如果你正在生成excel,axlsx和rails插件acts_as_xlsx可能是你最好的选择。
答案 2 :(得分:1)
以下是电子表格 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
参考:https://github.com/zdavatz/spreadsheet/blob/master/lib/spreadsheet/format.rb
答案 3 :(得分:0)
嗨,我不确定,但这个宝石可能对你有所帮助。