Class | Spreadsheet::Format |
In: |
lib/spreadsheet/format.rb
|
Parent: | Object |
Formatting data
text_direction | -> | reading_order |
text_direction= | -> | reading_order= |
indent_level | -> | indent |
indent_level= | -> | indent= |
font | [RW] | |
name | [RW] | |
number_format | [RW] | |
pattern | [RW] | |
rotation | [R] | Text rotation |
used_merge | [RW] |
# File lib/spreadsheet/format.rb, line 75 75: def initialize opts={} 76: @font = Font.new client("Arial", 'UTF-8'), :family => :swiss 77: @number_format = client 'GENERAL', 'UTF-8' 78: @rotation = 0 79: @pattern = 0 80: @bottom_color = :builtin_black 81: @top_color = :builtin_black 82: @left_color = :builtin_black 83: @right_color = :builtin_black 84: @diagonal_color = :builtin_black 85: @pattern_fg_color = :border 86: @pattern_bg_color = :pattern_bg 87: # Temp code to prevent merged formats in non-merged cells. 88: @used_merge = 0 89: opts.each do |key, val| 90: writer = "#{key}=" 91: if @font.respond_to? writer 92: @font.send writer, val 93: else 94: self.send writer, val 95: end 96: end 97: yield self if block_given? 98: end
Combined method for both horizontal and vertical alignment. Sets the first valid value (e.g. Format#align = :justify only sets the horizontal alignment. Use one of the aliases prefixed with :v if you need to disambiguate.)
This is essentially a backward-compatibility method and may be removed at some point in the future.
# File lib/spreadsheet/format.rb, line 107 107: def align= location 108: self.horizontal_align = location 109: rescue ArgumentError 110: self.vertical_align = location rescue ArgumentError 111: end
Activate or deactivate all four borders (left, right, top, bottom)
# File lib/spreadsheet/format.rb, line 120 120: def border=(boolean) 121: [:bottom=, :top=, :right=, :left=].each do |writer| send writer, boolean end 122: end
Backward compatibility method. May disappear at some point in the future.
# File lib/spreadsheet/format.rb, line 152 152: def center_across! 153: self.horizontal_align = :merge 154: end
Is the cell formatted as a Date?
# File lib/spreadsheet/format.rb, line 158 158: def date? 159: !!Regexp.new(client("[YMD]", 'UTF-8')).match(@number_format.to_s) 160: end
Is the cell formatted as a Date or Time?
# File lib/spreadsheet/format.rb, line 163 163: def date_or_time? 164: !!Regexp.new(client("[hmsYMD]", 'UTF-8')).match(@number_format.to_s) 165: end
Is the cell formatted as a DateTime?
# File lib/spreadsheet/format.rb, line 168 168: def datetime? 169: !!Regexp.new(client("([YMD].*[HS])|([HS].*[YMD])", 'UTF-8')).match(@number_format.to_s) 170: end
Set the Text rotation Valid values: Integers from -90 to 90, or :stacked (sets rotation_stacked to true)
# File lib/spreadsheet/format.rb, line 139 139: def rotation=(rot) 140: if rot.to_s.downcase == 'stacked' 141: @rotation_stacked = true 142: @rotation = 0 143: elsif rot.kind_of?(Integer) 144: @rotation_stacked = false 145: @rotation = rot % 360 146: else 147: raise TypeError, "rotation value must be an Integer or the String 'stacked'" 148: end 149: end