Method: Spreadsheet::Excel::Reader#read_xf

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

#read_xf(work, pos, len) ⇒ Object



1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File 'lib/spreadsheet/excel/reader.rb', line 1047

def read_xf work, pos, len
  # Offset  Size  Contents
  #      0     2  Index to FONT record (➜ 6.43)
  #      2     2  Index to FORMAT record (➜ 6.45)
  #      4     2   Bit  Mask    Contents
  #                2-0  0x0007  XF_TYPE_PROT – XF type, cell protection
  #                             Bit  Mask  Contents
  #                               0  0x01  1 = Cell is locked
  #                               1  0x02  1 = Formula is hidden
  #                               2  0x04  0 = Cell XF; 1 = Style XF
  #               15-4  0xfff0  Index to parent style XF
  #                             (always 0xfff in style XFs)
  #      6     1   Bit  Mask    Contents
  #                2-0  0x07    XF_HOR_ALIGN – Horizontal alignment
  #                             Value  Horizontal alignment
  #                             0x00   General
  #                             0x01   Left
  #                             0x02   Centred
  #                             0x03   Right
  #                             0x04   Filled
  #                             0x05   Justified (BIFF4-BIFF8X)
  #                             0x06   Centred across selection
  #                                    (BIFF4-BIFF8X)
  #                             0x07   Distributed (BIFF8X)
  #                  3  0x08    1 = Text is wrapped at right border
  #                6-4  0x70    XF_VERT_ALIGN – Vertical alignment
  #                             Value  Vertical alignment
  #                             0x00   Top
  #                             0x01   Centred
  #                             0x02   Bottom
  #                             0x03   Justified (BIFF5-BIFF8X)
  #                             0x04   Distributed (BIFF8X)
  #      7     1  XF_ROTATION: Text rotation angle (see above)
  #                Value  Text rotation
  #                    0  Not rotated
  #                 1-90  1 to 90 degrees counterclockwise
  #               91-180  1 to 90 degrees clockwise
  #                  255  Letters are stacked top-to-bottom,
  #                       but not rotated
  #      8     1   Bit  Mask    Contents
  #                3-0  0x0f    Indent level
  #                  4  0x10    1 = Shrink content to fit into cell
  #                  5  0x40    1 = Merge Range (djberger)
  #                7-6  0xc0    Text direction (BIFF8X only)
  #                             0 = According to context
  #                             1 = Left-to-right
  #                             2 = Right-to-left
  #      9     1   Bit  Mask    Contents
  #                7-2  0xfc    XF_USED_ATTRIB – Used attributes
  #                             Each bit describes the validity of a
  #                             specific group of attributes. In cell XFs
  #                             a cleared bit means the attributes of the
  #                             parent style XF are used (but only if the
  #                             attributes are valid there), a set bit
  #                             means the attributes of this XF are used.
  #                             In style XFs a cleared bit means the
  #                             attribute setting is valid, a set bit
  #                             means the attribute should be ignored.
  #                             Bit  Mask  Contents
  #                               0  0x01  Flag for number format
  #                               1  0x02  Flag for font
  #                               2  0x04  Flag for horizontal and
  #                                        vertical alignment, text wrap,
  #                                        indentation, orientation,
  #                                        rotation, and text direction
  #                               3  0x08  Flag for border lines
  #                               4  0x10  Flag for background area style
  #                               5  0x20  Flag for cell protection (cell
  #                                        locked and formula hidden)
  #     10     4  Cell border lines and background area:
  #                 Bit  Mask        Contents
  #                3- 0  0x0000000f  Left line style (➜ 3.10)
  #                7- 4  0x000000f0  Right line style (➜ 3.10)
  #               11- 8  0x00000f00  Top line style (➜ 3.10)
  #               15-12  0x0000f000  Bottom line style (➜ 3.10)
  #               22-16  0x007f0000  Colour index (➜ 6.70)
  #                                  for left line colour
  #               29-23  0x3f800000  Colour index (➜ 6.70)
  #                                  for right line colour
  #                  30  0x40000000  1 = Diagonal line
  #                                  from top left to right bottom
  #                  31  0x80000000  1 = Diagonal line
  #                                  from bottom left to right top
  #     14     4    Bit  Mask        Contents
  #                6- 0  0x0000007f  Colour index (➜ 6.70)
  #                                  for top line colour
  #               13- 7  0x00003f80  Colour index (➜ 6.70)
  #                                  for bottom line colour
  #               20-14  0x001fc000  Colour index (➜ 6.70)
  #                                  for diagonal line colour
  #               24-21  0x01e00000  Diagonal line style (➜ 3.10)
  #               31-26  0xfc000000  Fill pattern (➜ 3.11)
  #     18     2    Bit  Mask        Contents
  #                 6-0  0x007f      Colour index (➜ 6.70)
  #                                  for pattern colour
  #                13-7  0x3f80      Colour index (➜ 6.70)
  #                                  for pattern background
  fmt = Format.new
  font_idx, numfmt, _, xf_align, xf_rotation, xf_indent, _,
    xf_borders, xf_brdcolors, xf_pattern = work.unpack binfmt(:xf)
  fmt.number_format = @formats[numfmt]
  ## this appears to be undocumented: the first 4 fonts seem to be accessed
  #  with a 0-based index, but all subsequent font indices are 1-based.
  fmt.font = @workbook.font((font_idx > 3) ? font_idx - 1 : font_idx)
  fmt.horizontal_align = NGILA_H_FX[xf_align & 0x07]
  fmt.text_wrap = xf_align & 0x08 > 0
  fmt.vertical_align = NGILA_V_FX[xf_align & 0x70]
  fmt.rotation = if xf_rotation == 255
    :stacked
  elsif xf_rotation > 90
    90 - xf_rotation
  else
    xf_rotation
  end
  fmt.indent_level = xf_indent & 0x0f
  fmt.shrink = xf_indent & 0x10 > 0
  fmt.text_direction = NOITCERID_TXET_FX[xf_indent & 0xc0]
  fmt.left = XF_BORDER_LINE_STYLES[xf_borders & 0x0000000f]
  fmt.right = XF_BORDER_LINE_STYLES[(xf_borders & 0x000000f0) >> 4]
  fmt.top = XF_BORDER_LINE_STYLES[(xf_borders & 0x00000f00) >> 8]
  fmt.bottom = XF_BORDER_LINE_STYLES[(xf_borders & 0x0000f000) >> 12]
  fmt.left_color = COLOR_CODES[(xf_borders & 0x007f0000) >> 16] || :black
  fmt.right_color = COLOR_CODES[(xf_borders & 0x3f800000) >> 23] || :black
  fmt.cross_down = xf_borders & 0x40000000 > 0
  fmt.cross_up = xf_borders & 0x80000000 > 0
  if xf_brdcolors
    fmt.top_color = COLOR_CODES[xf_brdcolors & 0x0000007f] || :black
    fmt.bottom_color = COLOR_CODES[(xf_brdcolors & 0x00003f80) >> 7] || :black
    fmt.diagonal_color = COLOR_CODES[(xf_brdcolors & 0x001fc000) >> 14] || :black
    # fmt.diagonal_style = COLOR_CODES[xf_brdcolors & 0x01e00000]
    fmt.pattern = (xf_brdcolors & 0xfc000000) >> 26
  end
  fmt.pattern_fg_color = COLOR_CODES[xf_pattern & 0x007f] || :border
  fmt.pattern_bg_color = COLOR_CODES[(xf_pattern & 0x3f80) >> 7] || :pattern_bg
  @workbook.add_format fmt
end