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.



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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 326

def write_from_scratch workbook, io
  sanitize_worksheets workbook.worksheets
  collect_formats workbook
  sheets = worksheets workbook
  buffer1 = StringIO.new "".dup
  # ●  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
  write_palette workbook, buffer1
  # ○  USESELFS ➜ 5.106
  buffer1.rewind
  # ●● BOUNDSHEET ➜ 5.95
  buffer2 = StringIO.new "".dup
  # ○  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 { |worksheet| worksheet.write_from_scratch }
  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