Module Spreadsheet::Excel::Writer::Biff8
In: lib/spreadsheet/excel/writer/biff8.rb
Column Format Row Font Enumerable Worksheet\n[lib/spreadsheet/excel.rb\nlib/spreadsheet/worksheet.rb] Link Workbook Workbook\n[lib/spreadsheet/excel.rb\nlib/spreadsheet/excel/workbook.rb] SstEntry String Row Array Worksheet ExcelCompatibleWorkbook Format Worksheet Workbook DelegateClassSpreadsheet::Format Writer Compatibility Formula Reader\n[lib/parseexcel/parseexcel.rb\nlib/spreadsheet/excel/reader.rb\nlib/spreadsheet/excel/reader/biff5.rb\nlib/spreadsheet/excel/reader/biff8.rb] Error lib/spreadsheet/excel.rb lib/spreadsheet/link.rb lib/spreadsheet/formula.rb lib/spreadsheet/workbook.rb lib/spreadsheet/font.rb lib/spreadsheet/column.rb lib/spreadsheet/format.rb lib/spreadsheet/writer.rb lib/spreadsheet/row.rb Encodings lib/spreadsheet/excel.rb lib/spreadsheet/excel/row.rb lib/spreadsheet/excel/reader/biff5.rb lib/spreadsheet/excel/worksheet.rb lib/spreadsheet/excel/sst_entry.rb lib/spreadsheet/excel/error.rb lib/spreadsheet/excel/workbook.rb lib/spreadsheet/excel/writer/format.rb lib/spreadsheet/excel/writer/workbook.rb lib/spreadsheet/excel/writer/worksheet.rb Biff8 Writer Biff5 Biff8 Internals Offset Excel Datatypes ParseExcel Compatibility Spreadsheet dot/m_34_0.png

This Module collects writer methods such as unicode_string that are specific to Biff8. This Module is likely to be expanded as Support for older Versions of Excel grows and methods get moved here for disambiguation.

Methods

Included Modules

Spreadsheet::Encodings

Public Instance methods

Encode string into a Biff8 Unicode String Header and Body.

[Source]

    # File lib/spreadsheet/excel/writer/biff8.rb, line 42
42:   def _unicode_string string, count_length=1
43:     data = internal string
44:     size = data.send(@@bytesize) / 2
45:     fmt = count_length == 1 ? 'C2' : 'vC'
46:     data, wide = compress_unicode_string data
47:     opts = wide
48:     header = [
49:       size, # Length of the string (character count, ln)
50:       opts, # Option flags:
51:             # Bit  Mask  Contents
52:             #   0  0x01  Character compression (ccompr):
53:             #            0 = Compressed (8-bit characters)
54:             #            1 = Uncompressed (16-bit characters)
55:             #   2  0x04  Asian phonetic settings (phonetic):
56:             #            0 = Does not contain Asian phonetic settings
57:             #            1 = Contains Asian phonetic settings
58:             #   3  0x08  Rich-Text settings (richtext):
59:             #            0 = Does not contain Rich-Text settings
60:             #            1 = Contains Rich-Text settings
61:       #0x00,# (optional, only if richtext=1) Number of Rich-Text
62:             #                                formatting runs (rt)
63:       #0x00,# (optional, only if phonetic=1) Size of Asian phonetic
64:             #                                settings block (in bytes, sz)
65:     ].pack fmt
66:     data << '' # (optional, only if richtext=1)
67:                # List of rt formatting runs (➜ 3.2)
68:     data << '' # (optional, only if phonetic=1)
69:                # Asian Phonetic Settings Block (➜ 3.4.2)
70:     [header, data, wide]
71:   end

Check whether the string data can be compressed (i.e. every second byte is a Null-byte) and perform compression. Returns the data and compression_status (0/1)

[Source]

    # File lib/spreadsheet/excel/writer/biff8.rb, line 16
16:   def compress_unicode_string data
17:     compressed = ''
18:     expect_null = false
19:     data.each_byte do |byte|
20:       if expect_null
21:         if byte != 0
22:           return [data, 1] # 1 => Data consists of wide Chars
23:         end
24:         expect_null = false
25:       else
26:         compressed << byte
27:         expect_null = true
28:       end
29:     end
30:     [compressed, 0] # 0 => Data consists of compressed Chars
31:   end

Encode string into a Biff8 Unicode String. Header and body are encoded separately by _unicode_string. This method simply combines the two.

[Source]

    # File lib/spreadsheet/excel/writer/biff8.rb, line 35
35:   def unicode_string string, count_length=1
36:     header, data, _ = _unicode_string string, count_length
37:     header << data
38:   end

[Validate]