Method: Spreadsheet::Excel::Writer::Workbook#write_string_part

Defined in:
lib/spreadsheet/excel/writer/workbook.rb

#write_string_part(writer, op, data, wide) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 480

def write_string_part writer, op, data, wide
  bef = data.size
  ## if we're writing wide characters, we need to make sure we don't cut
  #  characters in half
  if wide > 0 && data.size > @recordsize_limit
    remove = @recordsize_limit - bef
    remove -= remove % 2
    rest = data.slice!(remove..-1)
    write_op writer, op, data
    data = rest
  else
    data = write_op writer, op, data
  end
  op = 0x003c
  # Unicode strings are split in a special way. At the beginning of each
  # CONTINUE record the option flags byte is repeated. Only the
  # character size flag will be set in this flags byte, the Rich-Text
  # flag and the Far-East flag are set to zero.
  unless data.empty?
    if wide == 1
      # check if we can compress the rest of the string
      data, wide = compress_unicode_string data
    end
    data = [wide].pack("C") << data
  end
  [op, data, wide]
end