Method: Spreadsheet::Excel::Writer::Workbook#write_from_scratch

Defined in:
lib/spreadsheet/excel/writer/workbook.rb

#write_from_scratch(workbook, io) ⇒ Object

Write a new Excel file.



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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 384

def write_from_scratch workbook, io
  sanitize_worksheets workbook.worksheets
  collect_formats workbook
  sheets = worksheets workbook
  buffer1 = StringIO.new ''
  # ●  BOF Type = workbook globals (➜ 6.8)
  write_bof workbook, buffer1, :globals
  # ○  File Protection Block ➜ 4.19
  # ○  WRITEACCESS User name (BIFF3-BIFF8, ➜ 5.112)
  # ○  FILESHARING File sharing options (BIFF3-BIFF8, ➜ 5.44)
  # ○  CODEPAGE ➜ 6.17
  write_encoding workbook, buffer1
  # ○  DSF ➜ 6.32
  write_dsf workbook, buffer1
  # ○  TABID
  write_tabid workbook, buffer1
  # ○  FNGROUPCOUNT
  # ○  Workbook Protection Block ➜ 4.18
  # ○  WINDOWPROTECT Window settings: 1 = protected (➜ 5.111)
  # ○  PROTECT Cell contents: 1 = protected (➜ 5.82)
  write_protect workbook, buffer1
  # ○  OBJECTPROTECT Embedded objects: 1 = protected (➜ 5.72)
  # ○  PASSWORD Hash value of the password; 0 = No password (➜ 5.76)
  write_password workbook, buffer1
  # ○  BACKUP ➜ 5.5
  # ○  HIDEOBJ ➜ 5.56
  # ●  WINDOW1 ➜ 5.109
  write_window1 workbook, buffer1
  # ○  DATEMODE ➜ 5.28
  write_datemode workbook, buffer1
  # ○  PRECISION ➜ 5.79
  write_precision workbook, buffer1
  # ○  REFRESHALL
  write_refreshall workbook, buffer1
  # ○  BOOKBOOL ➜ 5.9
  write_bookbool workbook, buffer1
  # ●● FONT ➜ 5.45
  write_fonts workbook, buffer1
  # ○○ FORMAT ➜ 5.49
  write_formats workbook, buffer1
  # ●● XF ➜ 5.115
  write_xfs workbook, buffer1
  # ●● STYLE ➜ 5.103
  write_styles workbook, buffer1
  # ○  PALETTE ➜ 5.74
  # ○  USESELFS ➜ 5.106
  buffer1.rewind
  # ●● BOUNDSHEET ➜ 5.95
  buffer2 = StringIO.new ''
  # ○  COUNTRY ➜ 5.22
  # ○  Link Table ➜ 4.10.3
  # ○○ NAME ➜ 6.66
  # ○  Shared String Table ➜ 4.11
  # ●  SST ➜ 5.100
  # ●  EXTSST ➜ 5.42
  write_sst workbook, buffer2, buffer1.size
  # ●  EOF ➜ 5.37
  write_eof workbook, buffer2
  buffer2.rewind
  # worksheet data can only be assembled after write_sst
  sheets.each do |worksheet| worksheet.write_from_scratch end
  Ole::Storage.open io do |ole|
    ole.file.open 'Workbook', 'w' do |writer|
      writer.write buffer1.read
      write_boundsheets workbook, writer, buffer1.size + buffer2.size
      writer.write buffer2.read
      sheets.each do |worksheet|
        writer.write worksheet.data
      end
    end
  end
end