Class: Spreadsheet::Excel::Writer::Worksheet
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::SEPYT_ENILREDNU, Internals::SEPYT_TNEMEPACSE, Internals::SGNIDOCNE_TNOF, Internals::SST_CHUNKSIZE, Internals::TWIPS, Internals::UNDERLINE_TYPES, 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_changes(reader, endpos, sst_status) ⇒ 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_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_page_settings ⇒ Object
-
#write_pagesetup ⇒ 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.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 18
def initialize workbook, worksheet
@workbook = workbook
@worksheet = worksheet
@io = StringIO.new ''
@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.
17
18
19
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 17
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.
38
39
40
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 38
def boundsheet_size
name.size + 10
end
|
#data ⇒ Object
41
42
43
44
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 41
def data
@io.rewind
@io.read
end
|
#encode_date(date) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 45
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
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 58
def encode_rk value
cent = 0
int = 2
higher = value * 100
if 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
86
87
88
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 86
def name
unicode_string @worksheet.name
end
|
#need_number?(cell) ⇒ Boolean
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 89
def need_number? cell
if cell.is_a?(Numeric) && cell.abs > 0x1fffffff
true
elsif cell.is_a?(Float)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 104
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
117
118
119
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 117
def size
@io.size
end
|
#strings ⇒ Object
120
121
122
123
124
125
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 120
def strings
@worksheet.inject [] do |memo, row|
strings = row.select do |cell| cell.is_a?(String) && !cell.empty? end
memo.concat strings
end
end
|
#write_blank(row, idx) ⇒ Object
128
129
130
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 128
def write_blank row, idx
write_cell :blank, row, idx
end
|
#write_bof ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 131
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 151
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
167
168
169
170
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 167
def write_calccount
count = 100 write_op 0x000c, [count].pack('v')
end
|
#write_cell(type, row, idx, *args) ⇒ Object
171
172
173
174
175
176
177
178
179
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 171
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
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 180
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_changes(reader, endpos, sst_status) ⇒ Object
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 242
def write_changes reader, endpos, sst_status
@worksheet.row_count.times do |i|
if @worksheet.row(i).outline_level > 0
@worksheet.row(i).outline_level = @worksheet.row(i).outline_level
end
end
reader.seek @worksheet.offset
blocks = row_blocks
lastpos = reader.pos
offsets = {}
row_offsets = []
changes = @worksheet.changes
@worksheet.offsets.each do |key, pair|
if changes.include?(key) \
|| (sst_status == :complete_update && key.is_a?(Integer))
offsets.store pair, key
end
end
work = offsets.invert
work.each do |key, (pos, len)|
case key
when Integer
row_offsets.push [key, [pos, len]]
when :dimensions
row_offsets.push [-1, [pos, len]]
end
end
row_offsets.sort!
row_offsets.reverse!
control = changes.size
@worksheet.each do |row|
key = row.idx
if changes.include?(key) && !work.include?(key)
row, pair = row_offsets.find do |idx, _| idx <= key end
work.store key, pair
end
end
if changes.size > control
warn <<-EOS
Your Worksheet was modified while it was being written. This should not happen.
Please contact the author (hannes dot wyss at gmail dot com) with a sample file
and minimal code that generates this warning. Thanks!
EOS
end
work = work.sort_by do |key, (pos, len)|
[pos, key.is_a?(Integer) ? key : -1]
end
work.each do |key, (pos, len)|
@io.write reader.read(pos - lastpos) if pos > lastpos
if key.is_a?(Integer)
if block = blocks.find do |rows| rows.any? do |row| row.idx == key end end
write_rowblock block
blocks.delete block
end
else
send "write_#{key}"
end
lastpos = pos + len
reader.seek lastpos
end
write_colinfos
write_guts
@io.write reader.read(endpos - lastpos)
end
|
#write_colinfo(bunch) ⇒ Object
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 317
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
341
342
343
344
345
346
347
348
349
350
351
352
353
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 341
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
354
355
356
357
358
359
360
361
362
363
364
365
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 354
def write_defaultrowheight
data = [
0x00, 0xf2, ]
write_op 0x0225, data.pack('v2')
end
|
#write_defcolwidth ⇒ Object
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 428
def write_defcolwidth
write_op 0x0055, [8].pack('v')
end
|
#write_dimensions ⇒ Object
442
443
444
445
446
447
448
449
450
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 442
def write_dimensions
write_op 0x0200, @worksheet.dimensions.pack(binfmt(:dimensions))
end
|
#write_eof ⇒ Object
451
452
453
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 451
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.
457
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 457
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
515
516
517
518
519
520
521
522
523
524
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 515
def write_from_scratch
write_bof
write_calccount
write_refmode
write_iteration
write_saverecalc
write_guts
write_defaultrowheight
write_wsbool
write_page_settings
write_defcolwidth
write_colinfos
write_dimensions
write_rows
write_window2
write_hyperlink_table
write_eof
end
|
#write_guts ⇒ Object
Write record that contains information about the layout of outline symbols.
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 568
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 588
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
657
658
659
660
661
662
663
664
665
666
667
668
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 657
def write_hyperlink_table
links = []
@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
669
670
671
672
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 669
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.
676
677
678
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 676
def write_labelsst row, idx
write_cell :labelsst, row, idx, @workbook.sst_index(self, row[idx])
end
|
#write_mulblank(row, idx, multiples) ⇒ Object
Write multiple consecutive blank cells.
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 681
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)
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 697
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')
end
|
#write_multiples(row, idx, multiples) ⇒ Object
713
714
715
716
717
718
719
720
721
722
723
724
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 713
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
727
728
729
730
731
732
733
734
735
736
737
738
739
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 727
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
740
741
742
743
744
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 740
def write_op op, *args
data = args.join
@io.write [op,data.size].pack("v2")
@io.write data
end
|
#write_page_settings ⇒ Object
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 366
def write_page_settings
write_pagesetup end
|
#write_pagesetup ⇒ Object
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
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 383
def write_pagesetup
opts = 0
opts |= 0x0002 if @worksheet.orientation == :portrait
data = [
1, 100, 0, @worksheet.fit_width_to_pages || 0, @worksheet.fit_height_to_pages || 0, opts,
300, 300, 0, 0, 1 ]
write_op opcode(:pagesetup), data.pack(binfmt(:pagesetup))
end
|
#write_refmode ⇒ Object
745
746
747
748
749
750
751
752
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 745
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.
755
756
757
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 755
def write_rk row, idx
write_cell :rk, row, idx, encode_rk(row[idx])
end
|
#write_row(row) ⇒ Object
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 758
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
data = [
row.idx,
row.first_used,
row.first_unused,
height,
opts,
].pack binfmt(:row)
write_op opcode(:row), data
end
|
#write_rowblock(block) ⇒ Object
831
832
833
834
835
836
837
838
839
840
841
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 831
def write_rowblock block
block.each do |row|
write_row row
end
block.each do |row|
write_cellblocks row
end
end
|
#write_rows ⇒ Object
842
843
844
845
846
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 842
def write_rows
row_blocks.each do |block|
write_rowblock block
end
end
|
#write_saverecalc ⇒ Object
847
848
849
850
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 847
def write_saverecalc
write_op 0x005f, [1].pack('v')
end
|
#write_window2 ⇒ Object
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 851
def write_window2
flags = 0x0536 if @worksheet.selected
flags |= 0x0200
end
flags |= 0x0080 data = [ flags, 0, 0, 0, 0, 0 ].pack binfmt(:window2)
write_op opcode(:window2), data
end
|
#write_wsbool ⇒ Object
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
|
# File 'lib/spreadsheet/excel/writer/worksheet.rb', line 903
def write_wsbool
fit_print_to_pages = (@worksheet.fit_width_to_pages ||
@worksheet.fit_height_to_pages) ? 1 : 0
bits = [
1, 0, 0, 1, 1, fit_print_to_pages,
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
|