I see methods for col_style and row_style and add_conditional_formatting, but can't figure out how to set just one cell. In my example, col 1 is a date and column 2 is a percent. when i highlight the background of a row, i lose the date/percent formatting because Randy explained a cell can only have 1 style. How do I assign a date_with_background style to just the 1st cell in that row when necessary?
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
To apply a style to just one cell, when you call add_row you can specify an array of styles at the end. Place your style in the first one and fill the rest with nil. I think it may also work if you just have one style in the array,as you want it in the first column, but I'm not sure. Fell free to try it.
Example: