Class: Spreadsheet::Excel::Writer::Worksheet
- Inherits:
-
Object
- Object
- Spreadsheet::Excel::Writer::Worksheet
show all
- Includes:
- Internals, Internals::Biff8, Biff8
- Defined in:
- lib/spreadsheet/excel/writer/worksheet.rb,
lib/spreadsheet/excel/writer/n_worksheet.rb
Overview
If you think you do, look at #write_worksheet
Constant Summary
Internals::Biff8::BINARY_FORMATS
Constants included
from Internals
Internals::BINARY_FORMATS, Internals::BUILTIN_FORMATS, Internals::BUILTIN_STYLES, Internals::CODEPAGES, Internals::COLOR_CODES, Internals::EIGHT_BYTE_DOUBLE, Internals::ESCAPEMENT_TYPES, Internals::FONT_ENCODINGS, Internals::FONT_FAMILIES, Internals::FONT_WEIGHTS, Internals::LEAP_ERROR, Internals::NGILA_H_FX, Internals::NGILA_V_FX, Internals::NOITCERID_TXET_FX, Internals::OPCODES, Internals::OPCODE_SIZE, Internals::ROW_HEIGHT, Internals::SEDOCPO, Internals::SEDOC_ROLOC, Internals::SEGAPEDOC, Internals::SEILIMAF_TNOF, Internals::SEITILIBISIV_TEEHSKROW, Internals::SELYTS_ENIL_REDROB_FX, Internals::SEPYT_ENILREDNU, Internals::SEPYT_TNEMEPACSE, Internals::SGNIDOCNE_TNOF, Internals::SST_CHUNKSIZE, Internals::TWIPS, Internals::UNDERLINE_TYPES, Internals::WORKSHEET_VISIBILITIES, Internals::XF_BORDER_LINE_STYLES, Internals::XF_H_ALIGN, Internals::XF_TEXT_DIRECTION, Internals::XF_V_ALIGN
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#boundsheet_size ⇒ Object
The number of bytes needed to write a Boundsheet record for this Worksheet Used by Writer::Worksheet to calculate various offsets.
-
#data ⇒ Object
-
#encode_date(date) ⇒ Object
-
#encode_rk(value) ⇒ Object
-
#initialize(workbook, worksheet) ⇒ Worksheet
constructor
A new instance of Worksheet.
-
#name ⇒ Object
-
#need_number?(cell) ⇒ Boolean
-
#row_blocks ⇒ Object
-
#size ⇒ Object
-
#strings ⇒ Object
-
#write_blank(row, idx) ⇒ Object
-
#write_bof ⇒ Object
-
#write_boolerr(row, idx) ⇒ Object
Write a cell with a Boolean or Error value.
-
#write_calccount ⇒ Object
-
#write_cell(type, row, idx, *args) ⇒ Object
-
#write_cellblocks(row) ⇒ Object
-
#write_colinfo(bunch) ⇒ Object
-
#write_colinfos ⇒ Object
-
#write_defaultrowheight ⇒ Object
-
#write_defcolwidth ⇒ Object
-
#write_dimensions ⇒ Object
-
#write_eof ⇒ Object
-
#write_formula(row, idx) ⇒ Object
Write a cell with a Formula.
-
#write_from_scratch ⇒ Object
-
#write_guts ⇒ Object
Write record that contains information about the layout of outline symbols.
-
#write_hlink(row, col, link) ⇒ Object
-
#write_hyperlink_table ⇒ Object
-
#write_iteration ⇒ Object
-
#write_labelsst(row, idx) ⇒ Object
Write a cell with a String value.
-
#write_margins ⇒ Object
-
#write_merged_cells ⇒ Object
-
#write_mulblank(row, idx, multiples) ⇒ Object
Write multiple consecutive blank cells.
-
#write_mulrk(row, idx, multiples) ⇒ Object
Write multiple consecutive cells with RK values (see #write_rk).
-
#write_multiples(row, idx, multiples) ⇒ Object
-
#write_number(row, idx) ⇒ Object
Write a cell with a 64-bit double precision Float value.
-
#write_op(op, *args) ⇒ Object
-
#write_pagesetup ⇒ Object
-
#write_proctection ⇒ Object
-
#write_refmode ⇒ Object
-
#write_rk(row, idx) ⇒ Object
Write a cell with a Numeric or Date value.
-
#write_row(row) ⇒ Object
-
#write_rowblock(block) ⇒ Object
-
#write_rows ⇒ Object
-
#write_saverecalc ⇒ Object
-
#write_window2 ⇒ Object
-
#write_wsbool ⇒ Object
#binfmt
Methods included from Internals
#binfmt, #opcode
Methods included from Biff8
#_unicode_string, #compress_unicode_string, #unicode_string
Constructor Details
#initialize(workbook, worksheet) ⇒ Worksheet
Returns a new instance of Worksheet.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 20
def initialize workbook, worksheet
@workbook = workbook
@worksheet = worksheet
@io = StringIO.new ''.dup
@biff_version = 0x0600
@bof = 0x0809
@build_id = 3515
@build_year = 1996
@bof_types = {
:globals => 0x0005,
:visual_basic => 0x0006,
:worksheet => 0x0010,
:chart => 0x0020,
:macro_sheet => 0x0040,
:workspace => 0x0100,
}
end
|
Instance Attribute Details
#worksheet ⇒ Object
Returns the value of attribute worksheet.
19
20
21
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 19
def worksheet
@worksheet
end
|
Instance Method Details
#boundsheet_size ⇒ Object
The number of bytes needed to write a Boundsheet record for this Worksheet Used by Writer::Worksheet to calculate various offsets.
40
41
42
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 40
def boundsheet_size
name.size + 10
end
|
#data ⇒ Object
43
44
45
46
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 43
def data
@io.rewind
@io.read
end
|
#encode_date(date) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 47
def encode_date date
return date if date.is_a? Numeric
if date.is_a? Time
date = DateTime.new date.year, date.month, date.day,
date.hour, date.min, date.sec
end
base = @workbook.date_base
value = date - base
if LEAP_ERROR > base
value += 1
end
value
end
|
#encode_rk(value) ⇒ Object
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 60
def encode_rk value
cent = 0
int = 2
higher = value * 100
if (higher.is_a?(Rational) or higher.is_a?(BigDecimal) or higher.is_a?(Float)) && higher < 0xfffffffc
cent = 1
if higher == higher.to_i
value = higher.to_i
else
value = higher
end
end
if value.is_a?(Integer)
value <<= 2
else
int = 0
value, = [value].pack(EIGHT_BYTE_DOUBLE).unpack('x4V')
value &= 0xfffffffc
end
value | cent | int
end
|
#name ⇒ Object
88
89
90
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 88
def name
unicode_string @worksheet.name
end
|
#need_number?(cell) ⇒ Boolean
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 91
def need_number? cell
if cell.is_a?(Numeric) && cell.abs > 0x1fffffff
true
elsif cell.is_a?(Rational) or ((cell.is_a?(BigDecimal) or cell.is_a?(Float)) and not cell.nan?)
higher = cell * 100
if higher == higher.to_i
need_number? higher.to_i
else
test1, test2 = [cell * 100].pack(EIGHT_BYTE_DOUBLE).unpack('V2')
test1 > 0 || need_number?(test2)
end
else
false
end
end
|
#row_blocks ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 106
def row_blocks
blocks = []
@worksheet.reject do |row| row.empty? end.each_with_index do |row, idx|
blocks << [] if idx % 32 == 0
blocks.last << row
end
blocks
end
|
#size ⇒ Object
119
120
121
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 119
def size
@io.size
end
|
#strings ⇒ Object
122
123
124
125
126
127
128
129
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 122
def strings
@worksheet.inject(Hash.new(0)) do |memo, row|
row.each do |cell|
memo[cell] += 1 if (cell.is_a?(String) && !cell.empty?)
end
memo
end
end
|
#write_blank(row, idx) ⇒ Object
132
133
134
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 132
def write_blank row, idx
write_cell :blank, row, idx
end
|
#write_bof ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 135
def write_bof
data = [
@biff_version, 0x0010, @build_id, @build_year, 0x000, 0x006, ]
write_op @bof, data.pack("v4V2")
end
|
#write_boolerr(row, idx) ⇒ Object
Write a cell with a Boolean or Error value
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 155
def write_boolerr row, idx
value = row[idx]
type = 0
numval = 0
if value.is_a? Error
type = 1
numval = value.code
elsif value
numval = 1
end
data = [
numval, type ]
write_cell :boolerr, row, idx, *data
end
|
#write_calccount ⇒ Object
171
172
173
174
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 171
def write_calccount
count = 100 write_op 0x000c, [count].pack('v')
end
|
#write_cell(type, row, idx, *args) ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 175
def write_cell type, row, idx, *args
xf_idx = @workbook.xf_index @worksheet.workbook, row.format(idx)
data = [
row.idx, idx, xf_idx, ].concat args
write_op opcode(type), data.pack(binfmt(type))
end
|
#write_cellblocks(row) ⇒ Object
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 184
def write_cellblocks row
multiples, first_idx = nil
row = row.formatted
row.each_with_index do |cell, idx|
cell = nil if cell == ''
need_number = need_number? cell
if multiples && (!multiples.last.is_a?(cell.class) || need_number)
write_multiples row, first_idx, multiples
multiples, first_idx = nil
end
nxt = idx + 1
case cell
when NilClass
if multiples
multiples.push cell
elsif nxt < row.size && row[nxt].nil?
multiples = [cell]
first_idx = idx
else
write_blank row, idx
end
when TrueClass, FalseClass, Error
write_boolerr row, idx
when String
write_labelsst row, idx
when Numeric
if need_number
write_number row, idx
elsif multiples
multiples.push cell
elsif nxt < row.size && row[nxt].is_a?(Numeric)
multiples = [cell]
first_idx = idx
else
write_rk row, idx
end
when Formula
write_formula row, idx
when Date, Time
write_number row, idx
end
end
write_multiples row, first_idx, multiples if multiples
end
|
#write_colinfo(bunch) ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 246
def write_colinfo bunch
col = bunch.first
width = col.width.to_f * 256
xf_idx = @workbook.xf_index @worksheet.workbook, col.default_format
opts = 0
opts |= 0x0001 if col.hidden?
opts |= col.outline_level.to_i << 8
opts |= 0x1000 if col.collapsed?
data = [
col.idx, bunch.last.idx, width.to_i, xf_idx.to_i, opts, ]
write_op opcode(:colinfo), data.pack(binfmt(:colinfo))
end
|
#write_colinfos ⇒ Object
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 270
def write_colinfos
cols = @worksheet.columns
bunch = []
cols.each_with_index do |column, idx|
if column
bunch << column
if cols[idx.next] != column
write_colinfo bunch
bunch.clear
end
end
end
end
|
#write_defaultrowheight ⇒ Object
283
284
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 283
def write_defaultrowheight
data = [
0x00, 0xf2, ]
write_op 0x0225, data.pack('v2')
end
|
#write_defcolwidth ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 295
def write_defcolwidth
write_op 0x0055, [8].pack('v')
end
|
#write_dimensions ⇒ Object
309
310
311
312
313
314
315
316
317
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 309
def write_dimensions
write_op 0x0200, @worksheet.dimensions.pack(binfmt(:dimensions))
end
|
#write_eof ⇒ Object
318
319
320
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 318
def write_eof
write_op 0x000a
end
|
Write a cell with a Formula. May write an additional String record depending on the stored result of the Formula.
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 324
def write_formula row, idx
xf_idx = @workbook.xf_index @worksheet.workbook, row.format(idx)
cell = row[idx]
data1 = [
row.idx, idx, xf_idx, ].pack 'v3'
data2 = nil
case value = cell.value
when Numeric data2 = [value].pack EIGHT_BYTE_DOUBLE
when String
data2 = [
0x00, 0xffff, ].pack 'Cx5v'
when true, false
value = value ? 1 : 0
data2 = [
0x01, value, 0xffff, ].pack 'CxCx3v'
when Error
data2 = [
0x02, value.code, 0xffff, ].pack 'CxCx3v'
when nil
data2 = [
0x03, 0xffff, ].pack 'Cx5v'
else
data2 = [
0x02, 0x2a, 0xffff, ].pack 'CxCx3v'
end
opts = 0x03
opts |= 0x08 if cell.shared
data3 = [
opts ].pack 'vx4'
write_op opcode(:formula), data1, data2, data3, cell.data
if cell.value.is_a?(String)
write_op opcode(:string), unicode_string(cell.value, 2)
end
end
|
#write_from_scratch ⇒ Object
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 382
def write_from_scratch
write_bof
write_calccount
write_refmode
write_iteration
write_saverecalc
write_guts
write_defaultrowheight
write_wsbool
write_proctection
write_defcolwidth
write_colinfos
write_dimensions
write_rows
write_window2
write_merged_cells
write_pagesetup
write_margins
write_hyperlink_table
write_eof
end
|
#write_guts ⇒ Object
Write record that contains information about the layout of outline symbols.
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 438
def write_guts
row_outline_level = 0
col_outline_level = 0
if(row = @worksheet.rows.select{|x| x!=nil}.max{|a,b| a.outline_level <=> b.outline_level})
row_outline_level = row.outline_level
end
if(col = @worksheet.columns.select{|x| x!=nil}.max{|a,b| a.outline_level <=> b.outline_level})
col_outline_level = col.outline_level
end
data = [
0, 0, row_outline_level+1, col_outline_level+1 ]
write_op opcode(:guts), data.pack('v4')
end
|
#write_hlink(row, col, link) ⇒ Object
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 458
def write_hlink row, col, link
cell_range = [
row, row, col, col, ].pack 'v4'
guid = [
"d0c9ea79f9bace118c8200aa004ba90b",
].pack 'H32'
opts = 0x01
opts |= 0x02
opts |= 0x14 unless link == link.url
opts |= 0x08 if link.fragment
opts |= 0x80 if link.target_frame
options = [
2, opts,
].pack('V2')
tail = []
nullstr = internal "\000"
unless link == link.url
desc = internal(link).dup << nullstr
tail.push [desc.size / 2].pack('V'), desc
end
if link.target_frame
frme = internal(link.target_frame).dup << nullstr
tail.push [frme.size / 2].pack('V'), frme
end
url = internal(link.url).dup << nullstr
tail.push [
'e0c9ea79f9bace118c8200aa004ba90b',
url.size ].pack('H32V'), url
if link.fragment
frag = internal(link.fragment).dup << nullstr
tail.push [frag.size / 2].pack('V'), frag
end
write_op opcode(:hlink), cell_range, guid, options, *tail
end
|
#write_hyperlink_table ⇒ Object
527
528
529
530
531
532
533
534
535
536
537
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 527
def write_hyperlink_table
@worksheet.each do |row|
row.each_with_index do |cell, idx|
if cell.is_a? Link
write_hlink row.idx, idx, cell
end
end
end
end
|
#write_iteration ⇒ Object
538
539
540
541
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 538
def write_iteration
its = 0 write_op 0x0011, [its].pack('v')
end
|
#write_labelsst(row, idx) ⇒ Object
Write a cell with a String value. The String must have been stored in the Shared String Table.
545
546
547
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 545
def write_labelsst row, idx
write_cell :labelsst, row, idx, @workbook.sst_index(self, row[idx])
end
|
#write_margins ⇒ Object
824
825
826
827
828
829
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 824
def write_margins
@worksheet.margins.each do |key, value|
next unless [:left, :top, :right, :bottom].include?(key)
write_op opcode(:"#{key}margin"), [value].pack(binfmt(:margin))
end
end
|
#write_merged_cells ⇒ Object
797
798
799
800
801
802
803
804
805
806
807
808
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 797
def write_merged_cells
return unless @worksheet.merged_cells.any?
merge_cells = @worksheet.merged_cells.dup
while (window = merge_cells.slice!(0...1027)).any?
count = window.size
data = ([count] + window.flatten).pack('v2v*')
write_op opcode(:mergedcells), data
end
end
|
#write_mulblank(row, idx, multiples) ⇒ Object
Write multiple consecutive blank cells.
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 550
def write_mulblank row, idx, multiples
data = [
row.idx, idx, ]
multiples.each_with_index do |blank, cell_idx|
xf_idx = @workbook.xf_index @worksheet.workbook, row.format(idx + cell_idx)
data.push xf_idx
end
data.push idx + multiples.size - 1
write_op opcode(:mulblank), data.pack('v*')
end
|
#write_mulrk(row, idx, multiples) ⇒ Object
Write multiple consecutive cells with RK values (see #write_rk)
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 566
def write_mulrk row, idx, multiples
fmt = ['v2']
data = [
row.idx, idx, ]
multiples.each_with_index do |cell, cell_idx|
xf_idx = @workbook.xf_index @worksheet.workbook, row.format(idx + cell_idx)
data.push xf_idx, encode_rk(cell)
fmt << 'vV'
end
data.push idx + multiples.size - 1
write_op opcode(:mulrk), data.pack((fmt << 'v').join)
end
|
#write_multiples(row, idx, multiples) ⇒ Object
582
583
584
585
586
587
588
589
590
591
592
593
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 582
def write_multiples row, idx, multiples
case multiples.last
when NilClass
write_mulblank row, idx, multiples
when Numeric
if multiples.size > 1
write_mulrk row, idx, multiples
else
write_rk row, idx
end
end
end
|
#write_number(row, idx) ⇒ Object
Write a cell with a 64-bit double precision Float value
596
597
598
599
600
601
602
603
604
605
606
607
608
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 596
def write_number row, idx
value = row[idx]
case value
when Date, Time
value = encode_date(value)
end
write_cell :number, row, idx, value
end
|
#write_op(op, *args) ⇒ Object
609
610
611
612
613
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 609
def write_op op, *args
data = args.join
@io.write [op,data.size].pack("v2")
@io.write data
end
|
#write_pagesetup ⇒ Object
810
811
812
813
814
815
816
817
818
819
820
821
822
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 810
def write_pagesetup
return unless @worksheet.pagesetup
data = @worksheet.pagesetup[:orig_data].dup
if @worksheet.pagesetup[:orientation]
data[5] = @worksheet.pagesetup[:orientation] == :landscape ? 0 : 2
end
if @worksheet.pagesetup[:adjust_to]
data[1] = @worksheet.pagesetup[:adjust_to]
end
write_op opcode(:pagesetup), data.pack(binfmt(:pagesetup))
end
|
#write_proctection ⇒ Object
831
832
833
834
835
836
837
838
839
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 831
def write_proctection
return unless @worksheet.protected?
write_op opcode(:protect), [1].pack('v')
write_op opcode(:password), [@worksheet.password_hash].pack('v')
end
|
#write_refmode ⇒ Object
614
615
616
617
618
619
620
621
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 614
def write_refmode
mode = 1 write_op 0x000f, [mode].pack('v')
end
|
#write_rk(row, idx) ⇒ Object
Write a cell with a Numeric or Date value.
624
625
626
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 624
def write_rk row, idx
write_cell :rk, row, idx, encode_rk(row[idx])
end
|
#write_row(row) ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 627
def write_row row
height = row.height || ROW_HEIGHT
opts = row.outline_level & 0x00000007
opts |= 0x00000010 if row.collapsed?
opts |= 0x00000020 if row.hidden?
opts |= 0x00000040 if height != ROW_HEIGHT
if fmt = row.default_format
xf_idx = @workbook.xf_index @worksheet.workbook, fmt
opts |= 0x00000080
opts |= xf_idx << 16
end
opts |= 0x00000100
height = if height == ROW_HEIGHT
(height * TWIPS).to_i | 0x8000
else
height * TWIPS
end
attrs = [
row.idx,
row.first_used,
row.first_unused,
height,
opts]
return if attrs.any?(&:nil?)
data = attrs.pack binfmt(:row)
write_op opcode(:row), data
end
|
#write_rowblock(block) ⇒ Object
704
705
706
707
708
709
710
711
712
713
714
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 704
def write_rowblock block
block.each do |row|
write_row row
end
block.each do |row|
write_cellblocks row
end
end
|
#write_rows ⇒ Object
715
716
717
718
719
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 715
def write_rows
row_blocks.each do |block|
write_rowblock block
end
end
|
#write_saverecalc ⇒ Object
720
721
722
723
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 720
def write_saverecalc
write_op 0x005f, [1].pack('v')
end
|
#write_window2 ⇒ Object
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 724
def write_window2
flags = 0x0536 if @worksheet.selected
flags |= 0x0200
end
flags |= 0x0080
if @worksheet.has_frozen_panel?
flags |= 0x0008 end
data = [ flags, 0, 0, 0, 0, 0 ].pack binfmt(:window2)
write_op opcode(:window2), data
if @worksheet.has_frozen_panel?
pane_data = [@worksheet.froze_left, @worksheet.froze_top, @worksheet.froze_top, @worksheet.froze_left, 3].pack binfmt(:colinfo)
write_op opcode(:pane), pane_data
end
end
|
#write_wsbool ⇒ Object
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 841
def write_wsbool
bits = [
1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, ]
weights = [4,5,6,7,8,9,10,11,12,13,14,15]
value = bits.inject do |a, b| a | (b << weights.shift) end
write_op 0x0081, [value].pack('v')
end
|