Thursday, September 20, 2012

Axlsx to support line break (\n)

Hello Rubies,
      Yesterday when i was playing with axlsx gem find something interesting. Requirement is need to allow line break in content. And current axlsx gem does not support that feature. So add this patch to your existing gem or either point directly to git repository b'coze that patch is unpublished as for now.

Add this line to axlsx1.2.3/lib/axlsx/workbook/worksheet/worksheet.rb

Remove line #500  

str.gsub(/[[:cntrl:]]/,'')

and Replace with

  if RUBY_VERSION == "1.8.7"
    nasty_control_char_matcher = Regexp.new("[\x01\x02\x03\x04\x05\x06\x07\x08\x1F\v\xE2]")
  else
    nasty_control_char_matcher = Regexp.new("[\x01\x02\x03\x04\x05\x06\x07\x08\x1F\v\u2028]")
  end

  str.gsub(nasty_control_char_matcher,'')

or

gem 'axlsx', '1.2.3', :git => 'git://github.com/randym/axlsx.git'

Hope this post is useful to you folks :).

No comments:

Post a Comment