Skip to content

Instantly share code, notes, and snippets.

@randym
Created July 31, 2012 04:09
Show Gist options
  • Save randym/3213525 to your computer and use it in GitHub Desktop.
Save randym/3213525 to your computer and use it in GitHub Desktop.
Excel with Ruby: Printing Header Row for every page with axlsx
#```ruby
require 'axlsx'
p = Axlsx::Package.new
wb = p.workbook
wb.add_worksheet(:name => "repeated header") do |sheet|
sheet.add_row %w(These Column Header Will Render On Every Printed Sheet)
200.times { sheet.add_row %w(1 2 3 4 5 6 7 8) }
# This is the magic
wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
end
p.serialize 'repeating_headers.xlsx'
@marcyliao
Copy link

Hi, which version if ruby and axls were you using?

It does not work for me with axlsx 0.2.0. The header does not repeat in print preview.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment