Skip to content

Instantly share code, notes, and snippets.

@cschneid
Forked from randym/repeating_header.rb
Created July 31, 2012 14:00
Show Gist options
  • Save cschneid/3217251 to your computer and use it in GitHub Desktop.
Save cschneid/3217251 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment