Skip to content

Instantly share code, notes, and snippets.

@gregory
Created April 26, 2012 11:56
Show Gist options
  • Save gregory/2499101 to your computer and use it in GitHub Desktop.
Save gregory/2499101 to your computer and use it in GitHub Desktop.
Axlsx::Worksheet.class_eval do
def add_row_with_position(values = [], options = {})
if options.try(:[], :start_at).present?
val = []
options[:start_at].times { val.push nil}
options.delete(:start_at)
values = val + values
end
add_row_without_position(values, options)
end
alias_method_chain :add_row, :position
end
@randym
Copy link

randym commented Apr 28, 2012

#!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'

Axlsx::Worksheet.class_eval do
  def add_row_with_position(values = [], options = {})
    values = Array.new(options[:start_at] || 0) + values
    add_row(values, options)
  end
end

p = Axlsx::Package.new
wb = p.workbook
wb.add_worksheet do |ws|
ws.add_row_with_position [1,2,3,4,5]
ws.add_row_with_position [1,2,3,4,5], :start_at => 5

end
p.validate.each { |e| puts e.message }
p.serialize("stack.xlsx")

@randym
Copy link

randym commented Apr 28, 2012

greets mate- obviously you don't need the load path bit there - but I think this is what your looking todo.
Ill add an :offset option to add row that provides this functionality. definitely beats [nil, nil, nil, nil, 'real data'] stuff

@gregory
Copy link
Author

gregory commented Apr 28, 2012

yes it's sexier :D
I ll try this on monday when i m back at work and i ll let you know if ever i still get that stack too deep error message.

Anyway thanks dude! I ve been hacking into poi with monkey patching to get the kind of stuffs you bring trough your gem .. thanks

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