spreadsheet 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/parseexcel/parseexcel.rb +66 -58
- data/lib/parseexcel/parser.rb +1 -1
- data/lib/parseexcel.rb +1 -1
- data/lib/spreadsheet/column.rb +11 -9
- data/lib/spreadsheet/compatibility.rb +3 -1
- data/lib/spreadsheet/datatypes.rb +149 -147
- data/lib/spreadsheet/encodings.rb +20 -16
- data/lib/spreadsheet/errors.rb +2 -2
- data/lib/spreadsheet/excel/error.rb +23 -22
- data/lib/spreadsheet/excel/internals/biff5.rb +11 -11
- data/lib/spreadsheet/excel/internals/biff8.rb +13 -13
- data/lib/spreadsheet/excel/internals.rb +451 -451
- data/lib/spreadsheet/excel/offset.rb +32 -31
- data/lib/spreadsheet/excel/password_hash.rb +18 -18
- data/lib/spreadsheet/excel/reader/biff5.rb +34 -35
- data/lib/spreadsheet/excel/reader/biff8.rb +234 -222
- data/lib/spreadsheet/excel/reader.rb +1320 -1274
- data/lib/spreadsheet/excel/rgb.rb +91 -91
- data/lib/spreadsheet/excel/row.rb +99 -91
- data/lib/spreadsheet/excel/sst_entry.rb +40 -38
- data/lib/spreadsheet/excel/workbook.rb +86 -76
- data/lib/spreadsheet/excel/worksheet.rb +125 -107
- data/lib/spreadsheet/excel/writer/biff8.rb +56 -55
- data/lib/spreadsheet/excel/writer/format.rb +273 -256
- data/lib/spreadsheet/excel/writer/n_worksheet.rb +837 -798
- data/lib/spreadsheet/excel/writer/workbook.rb +671 -635
- data/lib/spreadsheet/excel/writer/worksheet.rb +898 -861
- data/lib/spreadsheet/excel/writer.rb +1 -1
- data/lib/spreadsheet/excel.rb +18 -11
- data/lib/spreadsheet/font.rb +30 -26
- data/lib/spreadsheet/format.rb +74 -59
- data/lib/spreadsheet/link.rb +7 -5
- data/lib/spreadsheet/note.rb +6 -6
- data/lib/spreadsheet/noteObject.rb +5 -5
- data/lib/spreadsheet/row.rb +33 -23
- data/lib/spreadsheet/version.rb +1 -1
- data/lib/spreadsheet/workbook.rb +27 -13
- data/lib/spreadsheet/worksheet.rb +102 -68
- data/lib/spreadsheet/writer.rb +3 -0
- data/lib/spreadsheet.rb +12 -15
- data/test/excel/reader.rb +8 -8
- data/test/excel/row.rb +35 -31
- data/test/excel/writer/workbook.rb +18 -16
- data/test/excel/writer/worksheet.rb +10 -8
- data/test/font.rb +44 -32
- data/test/format.rb +38 -33
- data/test/integration.rb +627 -598
- data/test/row.rb +5 -3
- data/test/suite.rb +7 -7
- data/test/workbook.rb +15 -14
- data/test/workbook_protection.rb +5 -5
- data/test/worksheet.rb +36 -34
- metadata +48 -6
@@ -1,264 +1,281 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "delegate"
|
2
|
+
require "spreadsheet/format"
|
3
|
+
require "spreadsheet/excel/internals"
|
4
4
|
|
5
5
|
module Spreadsheet
|
6
6
|
module Excel
|
7
7
|
module Writer
|
8
|
-
##
|
9
|
-
# This class encapsulates everything that is needed to write an XF record.
|
10
|
-
class Format < DelegateClass Spreadsheet::Format
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
8
|
+
##
|
9
|
+
# This class encapsulates everything that is needed to write an XF record.
|
10
|
+
class Format < DelegateClass Spreadsheet::Format
|
11
|
+
include Spreadsheet::Excel::Internals
|
12
|
+
def self.boolean *args
|
13
|
+
args.each do |key|
|
14
|
+
define_method key do
|
15
|
+
@format.send(:"#{key}?") ? 1 : 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.color key, default
|
21
|
+
define_method key do
|
22
|
+
color_code(@format.send(key) || default)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.line_style key, default
|
27
|
+
define_method key do
|
28
|
+
style_code(@format.send(key) || default)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
boolean :hidden, :locked, :merge_range, :shrink, :text_justlast, :text_wrap,
|
30
32
|
:cross_down, :cross_up
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
33
|
+
line_style :left, :none
|
34
|
+
line_style :right, :none
|
35
|
+
line_style :top, :none
|
36
|
+
line_style :bottom, :none
|
37
|
+
color :left_color, :black
|
38
|
+
color :right_color, :black
|
39
|
+
color :top_color, :black
|
40
|
+
color :bottom_color, :black
|
41
|
+
color :diagonal_color, :black
|
42
|
+
color :pattern_fg_color, :pattern_bg
|
43
|
+
color :pattern_bg_color, :pattern_bg
|
44
|
+
attr_reader :format
|
45
|
+
def initialize writer, workbook, format = workbook.default_format, opts = {}
|
46
|
+
@opts = {type: :format}.merge opts
|
47
|
+
@format = format
|
48
|
+
@writer = writer
|
49
|
+
@workbook = workbook
|
50
|
+
super(format)
|
51
|
+
end
|
52
|
+
|
53
|
+
def color_code color
|
54
|
+
SEDOC_ROLOC[color]
|
55
|
+
end
|
56
|
+
|
57
|
+
def style_code style
|
58
|
+
SELYTS_ENIL_REDROB_FX[style]
|
59
|
+
end
|
60
|
+
|
61
|
+
def font_index
|
62
|
+
@writer.font_index @workbook, font.key
|
63
|
+
end
|
64
|
+
|
65
|
+
def horizontal_align
|
66
|
+
XF_H_ALIGN.fetch @format.horizontal_align, 0
|
67
|
+
end
|
68
|
+
|
69
|
+
def num_format
|
70
|
+
@writer.number_format_index @workbook, @format.number_format
|
71
|
+
end
|
72
|
+
|
73
|
+
def text_direction
|
74
|
+
XF_TEXT_DIRECTION.fetch @format.text_direction, 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def vertical_align
|
78
|
+
XF_V_ALIGN.fetch @format.vertical_align, 2
|
79
|
+
end
|
80
|
+
|
81
|
+
def write_op writer, op, *args
|
82
|
+
data = args.join
|
83
|
+
writer.write [op, data.size].pack("v2")
|
84
|
+
writer.write data
|
85
|
+
end
|
86
|
+
|
87
|
+
def write_xf writer, type = @opts[:type]
|
88
|
+
xf_type = xf_type_prot type
|
89
|
+
data = [
|
90
|
+
font_index, # Index to FONT record (➜ 6.43)
|
91
|
+
num_format, # Index to FORMAT record (➜ 6.45)
|
92
|
+
xf_type, # Bit Mask Contents
|
93
|
+
# 2-0 0x0007 XF_TYPE_PROT – XF type, cell protection
|
94
|
+
# Bit Mask Contents
|
95
|
+
# 0 0x01 1 = Cell is locked
|
96
|
+
# 1 0x02 1 = Formula is hidden
|
97
|
+
# 2 0x04 0 = Cell XF; 1 = Style XF
|
98
|
+
# 15-4 0xfff0 Index to parent style XF
|
99
|
+
# (always 0xfff in style XFs)
|
100
|
+
xf_align, # Bit Mask Contents
|
101
|
+
# 2-0 0x07 XF_HOR_ALIGN – Horizontal alignment
|
102
|
+
# Value Horizontal alignment
|
103
|
+
# 0x00 General
|
104
|
+
# 0x01 Left
|
105
|
+
# 0x02 Centred
|
106
|
+
# 0x03 Right
|
107
|
+
# 0x04 Filled
|
108
|
+
# 0x05 Justified (BIFF4-BIFF8X)
|
109
|
+
# 0x06 Centred across selection
|
110
|
+
# (BIFF4-BIFF8X)
|
111
|
+
# 0x07 Distributed (BIFF8X)
|
112
|
+
# 3 0x08 1 = Text is wrapped at right border
|
113
|
+
# 6-4 0x70 XF_VERT_ALIGN – Vertical alignment
|
114
|
+
# Value Vertical alignment
|
115
|
+
# 0x00 Top
|
116
|
+
# 0x01 Centred
|
117
|
+
# 0x02 Bottom
|
118
|
+
# 0x03 Justified (BIFF5-BIFF8X)
|
119
|
+
# 0x04 Distributed (BIFF8X)
|
120
|
+
xf_rotation, # XF_ROTATION: Text rotation angle
|
121
|
+
# Value Text rotation
|
122
|
+
# 0 Not rotated
|
123
|
+
# 1-90 1 to 90 degrees counterclockwise
|
124
|
+
# 91-180 1 to 90 degrees clockwise
|
125
|
+
# 255 Letters are stacked top-to-bottom,
|
126
|
+
# but not rotated
|
127
|
+
xf_indent, # Bit Mask Contents
|
128
|
+
# 3-0 0x0f Indent level
|
129
|
+
# 4 0x10 1 = Shrink content to fit into cell
|
130
|
+
# 5 0x40 1 = Merge Range (djberger)
|
131
|
+
# 7-6 0xc0 Text direction (BIFF8X only)
|
132
|
+
# 0 = According to context
|
133
|
+
# 1 = Left-to-right
|
134
|
+
# 2 = Right-to-left
|
135
|
+
xf_used_attr, # Bit Mask Contents
|
136
|
+
# 7-2 0xfc XF_USED_ATTRIB – Used attributes
|
137
|
+
# Each bit describes the validity of a
|
138
|
+
# specific group of attributes. In cell XFs
|
139
|
+
# a cleared bit means the attributes of the
|
140
|
+
# parent style XF are used (but only if the
|
141
|
+
# attributes are valid there), a set bit
|
142
|
+
# means the attributes of this XF are used.
|
143
|
+
# In style XFs a cleared bit means the
|
144
|
+
# attribute setting is valid, a set bit
|
145
|
+
# means the attribute should be ignored.
|
146
|
+
# Bit Mask Contents
|
147
|
+
# 0 0x01 Flag for number format
|
148
|
+
# 1 0x02 Flag for font
|
149
|
+
# 2 0x04 Flag for horizontal and
|
150
|
+
# vertical alignment, text wrap,
|
151
|
+
# indentation, orientation,
|
152
|
+
# rotation, and text direction
|
153
|
+
# 3 0x08 Flag for border lines
|
154
|
+
# 4 0x10 Flag for background area style
|
155
|
+
# 5 0x20 Flag for cell protection (cell
|
156
|
+
# locked and formula hidden)
|
157
|
+
xf_borders, # Cell border lines and background area:
|
158
|
+
# Bit Mask Contents
|
159
|
+
# 3- 0 0x0000000f Left line style (➜ 3.10)
|
160
|
+
# 7- 4 0x000000f0 Right line style (➜ 3.10)
|
161
|
+
# 11- 8 0x00000f00 Top line style (➜ 3.10)
|
162
|
+
# 15-12 0x0000f000 Bottom line style (➜ 3.10)
|
163
|
+
# 22-16 0x007f0000 Colour index (➜ 6.70)
|
164
|
+
# for left line colour
|
165
|
+
# 29-23 0x3f800000 Colour index (➜ 6.70)
|
166
|
+
# for right line colour
|
167
|
+
# 30 0x40000000 1 = Diagonal line
|
168
|
+
# from top left to right bottom
|
169
|
+
# 31 0x80000000 1 = Diagonal line
|
170
|
+
# from bottom left to right top
|
171
|
+
xf_brdcolors, # Bit Mask Contents
|
172
|
+
# 6- 0 0x0000007f Colour index (➜ 6.70)
|
173
|
+
# for top line colour
|
174
|
+
# 13- 7 0x00003f80 Colour index (➜ 6.70)
|
175
|
+
# for bottom line colour
|
176
|
+
# 20-14 0x001fc000 Colour index (➜ 6.70)
|
177
|
+
# for diagonal line colour
|
178
|
+
# 24-21 0x01e00000 Diagonal line style (➜ 3.10)
|
179
|
+
# 31-26 0xfc000000 Fill pattern (➜ 3.11)
|
180
|
+
xf_pattern # Bit Mask Contents
|
181
|
+
# 6-0 0x007f Colour index (➜ 6.70)
|
182
|
+
# for pattern colour
|
183
|
+
# 13-7 0x3f80 Colour index (➜ 6.70)
|
184
|
+
# for pattern background
|
185
|
+
]
|
186
|
+
write_op writer, 0x00e0, data.pack(binfmt(:xf))
|
187
|
+
end
|
188
|
+
|
189
|
+
def xf_align
|
190
|
+
align = horizontal_align
|
191
|
+
align |= text_wrap << 3
|
192
|
+
align |= vertical_align << 4
|
193
|
+
align |= text_justlast << 7
|
194
|
+
align
|
195
|
+
end
|
196
|
+
|
197
|
+
def xf_borders
|
198
|
+
border = left
|
199
|
+
border |= right << 4
|
200
|
+
border |= top << 8
|
201
|
+
border |= bottom << 12
|
202
|
+
border |= left_color << 16
|
203
|
+
border |= right_color << 23
|
204
|
+
border |= cross_down << 30
|
205
|
+
border |= cross_up << 31
|
206
|
+
border
|
207
|
+
end
|
208
|
+
|
209
|
+
def xf_brdcolors
|
210
|
+
border = top_color
|
211
|
+
border |= bottom_color << 7
|
212
|
+
border |= diagonal_color << 14
|
213
|
+
border |= pattern << 26
|
214
|
+
border
|
215
|
+
end
|
216
|
+
|
217
|
+
def xf_indent
|
218
|
+
indent = indent_level & 0x0f
|
219
|
+
indent |= shrink << 4
|
220
|
+
indent |= merge_range << 5
|
221
|
+
indent |= text_direction << 6
|
222
|
+
indent
|
223
|
+
end
|
224
|
+
|
225
|
+
def xf_pattern
|
226
|
+
ptrn = pattern_fg_color
|
227
|
+
ptrn |= pattern_bg_color << 7
|
228
|
+
ptrn
|
229
|
+
end
|
230
|
+
|
231
|
+
def xf_rotation
|
232
|
+
rot = @format.rotation
|
233
|
+
if @format.rotation_stacked?
|
234
|
+
rot = 255
|
235
|
+
elsif rot >= -90 || rotation <= 90
|
236
|
+
rot = -rot + 90 if rot < 0
|
237
|
+
else
|
238
|
+
warn "rotation outside -90..90; rotation set to 0"
|
239
|
+
rot = 0
|
240
|
+
end
|
241
|
+
rot
|
242
|
+
end
|
243
|
+
|
244
|
+
def xf_type_prot type
|
245
|
+
type = (type.to_s.downcase == "style") ? 0xfff4 : 0x0000
|
246
|
+
type |= locked
|
247
|
+
type |= hidden << 1
|
248
|
+
type
|
249
|
+
end
|
250
|
+
|
251
|
+
def xf_used_attr
|
252
|
+
atr_num = num_format & 1
|
253
|
+
atr_fnt = font_index & 1
|
254
|
+
atr_fnt = 1 unless @format.font.color == :text
|
255
|
+
atr_alc = 0
|
256
|
+
if horizontal_align != 0 \
|
257
|
+
|| vertical_align != 2 \
|
258
|
+
|| indent_level > 0 \
|
259
|
+
|| shrink? || merge_range? || text_wrap?
|
260
|
+
atr_alc = 1
|
261
|
+
end
|
262
|
+
atr_bdr = 1
|
263
|
+
atr_pat = 0
|
264
|
+
if @format.pattern_fg_color != :border \
|
265
|
+
|| @format.pattern_bg_color != :pattern_bg \
|
266
|
+
|| pattern != 0x00
|
267
|
+
atr_pat = 1
|
268
|
+
end
|
269
|
+
atr_prot = (hidden? || locked?) ? 1 : 0
|
270
|
+
attrs = atr_num
|
271
|
+
attrs |= atr_fnt << 1
|
272
|
+
attrs |= atr_alc << 2
|
273
|
+
attrs |= atr_bdr << 3
|
274
|
+
attrs |= atr_pat << 4
|
275
|
+
attrs |= atr_prot << 5
|
276
|
+
attrs << 2
|
277
|
+
end
|
278
|
+
end
|
262
279
|
end
|
263
280
|
end
|
264
281
|
end
|