0

This style only aligns left, the font is not bold.

    bold_italic = styles.add_style :b => true, :i => true 
    bold        = styles.add_style :b => true
    yellow_bg   = styles.add_style :b => true, :bg_color => 'FFF60B',

    sheet.add_row ['År:', Time.now.year, "Pågår"],  
      :style => [bold_italic, yellow_bg, bold]

The yellow_bg styling also works. Is there a new syntax for getting the font bold?

martins
  • 9,669
  • 11
  • 57
  • 85
  • 1
    What program are you using to read the spreadsheet? Using the `:b=>true` param works for me when reading spreadsheets with Excel. Also, what is the `bold` style that you are passing to the `add_row` method? – alkalinecoffee May 14 '14 at 13:53

2 Answers2

6

:b => true does not work in Numbers. Only in Excel.

Thanks for the help, guys! :-)

martins
  • 9,669
  • 11
  • 57
  • 85
0

I do not see bold defined as a style. Have you tried bold = styles.add_style :b => true?

What is happening underneath is you are adding a set of cells(values) and it is mapping them to styles by index unless you pass a single style then this will apply to all values. So you are stating the following

for 'År:' use bold_italic,

for Time.now.year use yellow_bg,

for "Pågår" use bold

but since bold is not a style i.e. nil it does not assign a style.

From Axlsx::Cell#initialize

self.style = val unless val.nil? || val == 0
engineersmnky
  • 25,495
  • 2
  • 36
  • 52
  • I forgot to copy the declaration of the bold variable when I posted here. Sorry about that. :-) – martins May 15 '14 at 08:54