3
votes

I have a requirement to export an Excel template, with just a header row containing the column names, and each of the columns set to the appropriate data type for the entire spreadsheet. Is this possible to do using the axlsx gem?

I tried this as an example, but it just formats the one 'Count' cell with the number format, not all cells in the column.

wb.styles do |s|
  num_format = s.add_style(:format_code => "#,###")
  wb.add_worksheet(:name => "Formatting Data") do |sheet|
    #add header row for template
    sheet.add_row ["Product", "Count"]
    #format column
    sheet.col_style(1, num_format)
  end
end
1
have you tried anything? please provide any attemptsxlembouras
I updated my question with an example that I tried. I don't know if what I'm trying to accomplish is possible with axlsx.user3393022

1 Answers

2
votes

I am just implementing this gem and came across this so thought I would answer. You must create all rows you need before you can apply the style. In your example you only create the first row so the style can only be applied to this row. I can't find a way to apply style to uncreated rows but hopefully this answer help.