Posted by Doug Hays on the 14th of January, 2008 at 1:28 pm under Rails.    This post has 2,098 comments.

A client of mine let me know today that the Excel spreadsheets I was generating for them had data truncated at 255 characters. I didn’t find anything on the web that gave a reason or offered a fix so I decided to dig into the code myself. I am using the Ruby Spreadsheet-Excel gem.

Sure enough, on line 289, of workbook.rb (v0.3.5.1), there was this:

      # Truncate strings over 255 characters
      if strlen > StrMax
         str    = str[0..StrMax-1]
         length = 0x0008 + StrMax
         strlen = StrMax
      end

No idea why this was done and I wasn’t going to waste anytime considering the downsides of not truncating, so I commented this block out and it works fine.

Maybe it has something to do with an older version of Excel? Who knows.

Sorry, but you have to log in to submit comments.