Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'axlsx'
require 'pry'
p = Axlsx::Package.new
wb = p.workbook
# Build up a matrix of data
cols = ("A".."L").to_a
rows = (1..100).map do |i|
cols.zip(cols.dup.fill(i.to_s)).map(&:join)
end
wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
rows.each do |row|
sheet.add_row row
end
wb.add_defined_name("'Basic Worksheet'!$A$1:$L$51", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Area')
wb.add_defined_name("'Basic Worksheet'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
wb.add_defined_name("'Basic Worksheet'!$A$1:$B$1", :local_sheet_id => sheet.index, :name => 'Example_Range')
end
p.serialize "#{File.basename(__FILE__, '.rb')}.xlsx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment