ruby/caxlsx: how to define different surrounding cell's borders styles?

301 Views Asked by At

I cannot find a way to have different borders on a cell with the excellent caxlsx gem on ruby. From the doc, the expected style for borders is defined using (for instance):

{style: :thick, color: 'FF0000', edges:[:left,:right]}

So, it seems imposible to have a red thick border on the left, and a blue dash border on the right for instance. Am i wrong?

1

There are 1 best solutions below

0
Cris On

I'm a bit late to the game, but maybe someone else will stumble over the same issue.

When you use edges, you can't mix the styles. However, you can pass in border_left, border_top and so on. So something like this works:

    sheet["A1:A1"].each do |cell|
      cell.style = styles.add_style(
        border_right: { style: :medium, color: '000000' },
        border_bottom: { style: :thin, color: '000000' }
      )
    end
style = workbook.styles.add_style(
  border: { style: :none, color: nil },
  border_top: { style: :double, color: '0000FF' },
  border_right: { style: :thick, color: 'FF0000' },
  border_bottom: { style: :double, color: '0000FF' },
  border_left: { style: :thick, color: 'FF0000' }
)

source: https://github.com/axlsx-styler-gem/axlsx_styler/issues/31#issuecomment-943905188