Created
April 26, 2012 11:56
-
-
Save gregory/2499101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
#!/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")
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
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
@randym hey dude, i taught it would be nice tough this bunch of code drops me some stack level too deep.
Their might be something breaking down deeper in your code, thats why i came to you :)