Method: Spreadsheet::Excel::Reader#read_style

Defined in:
lib/spreadsheet/excel/reader.rb

#read_style(work, pos, len) ⇒ Object



1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'lib/spreadsheet/excel/reader.rb', line 1003

def read_style work, pos, len
  # User-Defined Cell Styles:
  # Offset  Size  Contents
  #      0     2  Bit   Mask    Contents
  #               11-0  0x0fff  Index to style XF record (➜ 6.115)
  #                 15  0x8000  Always 0 for user-defined styles
  #      2  var.  BIFF2-BIFF7:  Non-empty byte string,
  #                             8-bit string length (➜ 3.3)
  #               BIFF8:        Non-empty Unicode string,
  #                             16-bit string length (➜ 3.4)
  #
  # Built-In Cell Styles
  # Offset  Size  Contents
  #      0     2  Bit   Mask    Contents
  #               11-0  0x0FFF  Index to style XF record (➜ 6.115)
  #                 15  0x8000  Always 1 for built-in styles
  #      2     1  Identifier of the built-in cell style:
  #               0x00 = Normal
  #               0x01 = RowLevel_lv (see next field)
  #               0x02 = ColLevel_lv (see next field)
  #               0x03 = Comma
  #               0x04 = Currency
  #               0x05 = Percent
  #               0x06 = Comma [0] (BIFF4-BIFF8)
  #               0x07 = Currency [0] (BIFF4-BIFF8)
  #               0x08 = Hyperlink (BIFF8)
  #               0x09 = Followed Hyperlink (BIFF8)
  #      3     1  Level for RowLevel or ColLevel style (zero-based, lv),
  #               FFH otherwise
  flags, = work.unpack "v"
  xf_idx = flags & 0x0fff
  xf = @workbook.format xf_idx
  builtin = flags & 0x8000
  if builtin == 0
    xf.name = client read_string(work[2..], 2), @workbook.encoding
  else
    id, level = work.unpack "x2C2"
    if (name = BUILTIN_STYLES[id])
      name.sub "_lv", "_#{level}"
      xf.name = client name, "UTF-8"
    end
  end
end