Class: Writeexcel::Worksheet::ColInfo
- Inherits:
-
Object
- Object
- Writeexcel::Worksheet::ColInfo
- Defined in:
- lib/writeexcel/col_info.rb
Instance Method Summary collapse
-
#biff_record ⇒ Object
Write BIFF record COLINFO to define column widths.
-
#grbit ⇒ Object
Set the options flags.
-
#initialize(*args) ⇒ ColInfo
constructor
new(firstcol, lastcol, width, [format, hidden, level, collapsed]).
- #ixfe ⇒ Object
-
#level ⇒ Object
Set the limits for the outline levels (0 <= x <= 7).
-
#pixels ⇒ Object
Excel rounds the column width to the nearest pixel.
Constructor Details
#initialize(*args) ⇒ ColInfo
new(firstcol, lastcol, width, [format, hidden, level, collapsed])
firstcol : First formatted column
lastcol : Last formatted column
width : Col width in user units, 8.43 is default
format : format object
hidden : hidden flag
level : outline level
collapsed : ?
18 19 20 21 22 |
# File 'lib/writeexcel/col_info.rb', line 18 def initialize(*args) @firstcol, @lastcol, @width, @format, @hidden, @level, @collapsed = args @width ||= 8.43 # default width @level ||= 0 # default level end |
Instance Method Details
#biff_record ⇒ Object
Write BIFF record COLINFO to define column widths
Note: The SDK says the record length is 0x0B but Excel writes a 0x0C length record.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/writeexcel/col_info.rb', line 29 def biff_record record = 0x007D # Record identifier length = 0x000B # Number of bytes to follow coldx = (pixels * 256 / 7).to_i # Col width in internal units reserved = 0x00 # Reserved header = [record, length].pack("vv") data = [@firstcol, @lastcol, coldx, ixfe, grbit, reserved].pack("vvvvvC") [header, data] end |
#grbit ⇒ Object
Set the options flags. (See set_row() for more details).
75 76 77 78 79 80 81 |
# File 'lib/writeexcel/col_info.rb', line 75 def grbit grbit = 0x0000 # Option flags grbit |= 0x0001 if @hidden && @hidden != 0 grbit |= level << 8 grbit |= 0x1000 if @collapsed && @collapsed != 0 grbit end |
#ixfe ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/writeexcel/col_info.rb', line 55 def ixfe if @format && @format.respond_to?(:xf_index) @format.xf_index else 0x0F end end |
#level ⇒ Object
Set the limits for the outline levels (0 <= x <= 7).
64 65 66 67 68 69 70 71 72 |
# File 'lib/writeexcel/col_info.rb', line 64 def level if @level < 0 0 elsif 7 < @level 7 else @level end end |
#pixels ⇒ Object
Excel rounds the column width to the nearest pixel. Therefore we first convert to pixels and then to the internal units. The pixel to users-units relationship is different for values less than 1.
46 47 48 49 50 51 52 53 |
# File 'lib/writeexcel/col_info.rb', line 46 def pixels if @width < 1 result = @width * 12 else result = @width * 7 + 5 end result.to_i end |