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

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

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



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 525

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 - data.size
    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