我看到col_style和row_style以及add_conditional_formatting的方法,但无法弄清楚如何只设置一个单元格.在我的示例中,col 1是日期,列2是百分比.当我突出显示行的背景时,我会丢失日期/百分比格式,因为Randy解释说一个单元格只能有1种样式.如何在必要时将date_with_background样式分配给该行中的第一个单元格?
xlsx_package = Stuff.all.to_xlsx
xlsx_package.workbook.worksheets.first.tap do |sheet|
sheet.col_style 0, date_format, {row_offset: 1}
sheet.col_style 1, percent_format, {row_offset: 1}
list_of_my_stuff.each_with_index do |item,index|
if needs_background?(item)
sheet.row_style index+1, with_background
else
sheet.row_style index+1, no_background
end
end
end
Run Code Online (Sandbox Code Playgroud)