Class: Spreadsheet::Format
- Inherits:
-
Object
- Object
- Spreadsheet::Format
- Defined in:
- lib/spreadsheet/format.rb
Overview
Formatting data
Direct Known Subclasses
Instance Attribute Summary collapse
-
#font ⇒ Object
Returns the value of attribute font.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number_format ⇒ Object
Returns the value of attribute number_format.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#rotation ⇒ Object
Text rotation.
-
#used_merge ⇒ Object
Returns the value of attribute used_merge.
Instance Method Summary collapse
-
#align=(location) ⇒ Object
Combined method for both horizontal and vertical alignment.
-
#border ⇒ Object
Returns an Array containing the status of the four borders: bottom, top, right, left.
-
#border=(boolean) ⇒ Object
Activate or deactivate all four borders (left, right, top, bottom).
-
#border_color ⇒ Object
Returns an Array containing the colors of the four borders: bottom, top, right, left.
-
#border_color=(color) ⇒ Object
Set all four border colors to color (left, right, top, bottom).
-
#bottom_color ⇒ Object
Color attributes.
-
#center_across! ⇒ Object
(also: #merge!)
Backward compatibility method.
-
#cross_down ⇒ Object
- You can set the following boolean attributes: #cross_down
-
Draws a Line from the top-left to the bottom-right corner of a cell.
-
#date? ⇒ Boolean
Is the cell formatted as a Date?.
-
#date_or_time? ⇒ Boolean
Is the cell formatted as a Date or Time?.
-
#datetime? ⇒ Boolean
Is the cell formatted as a DateTime?.
-
#horizontal_align ⇒ Object
Horizontal alignment Valid values: :default, :left, :center, :right, :fill, :justify, :merge, :distributed Default: :default.
-
#indent_level ⇒ Object
(also: #indent)
Indentation level.
-
#initialize(opts = {}) {|_self| ... } ⇒ Format
constructor
A new instance of Format.
-
#text_direction ⇒ Object
(also: #reading_order)
Text direction Valid values: :context, :left_to_right, :right_to_left Default: :context.
-
#time? ⇒ Boolean
Is the cell formatted as a Time?.
-
#vertical_align ⇒ Object
Vertical alignment Valid values: :bottom, :top, :middle, :justify, :distributed Default: :bottom.
Methods included from Datatypes
Methods included from Compatibility
Constructor Details
#initialize(opts = {}) {|_self| ... } ⇒ Format
Returns a new instance of Format.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/spreadsheet/format.rb', line 75 def initialize opts={} @font = Font.new client("Arial", 'UTF-8'), :family => :swiss @number_format = client 'GENERAL', 'UTF-8' @rotation = 0 @pattern = 0 @bottom_color = :builtin_black @top_color = :builtin_black @left_color = :builtin_black @right_color = :builtin_black @diagonal_color = :builtin_black @pattern_fg_color = :border @pattern_bg_color = :pattern_bg # Temp code to prevent merged formats in non-merged cells. @used_merge = 0 opts.each do |key, val| writer = "#{key}=" if @font.respond_to? writer @font.send writer, val else self.send writer, val end end yield self if block_given? end |
Instance Attribute Details
#font ⇒ Object
Returns the value of attribute font.
71 72 73 |
# File 'lib/spreadsheet/format.rb', line 71 def font @font end |
#name ⇒ Object
Returns the value of attribute name.
71 72 73 |
# File 'lib/spreadsheet/format.rb', line 71 def name @name end |
#number_format ⇒ Object
Returns the value of attribute number_format.
71 72 73 |
# File 'lib/spreadsheet/format.rb', line 71 def number_format @number_format end |
#pattern ⇒ Object
Returns the value of attribute pattern.
71 72 73 |
# File 'lib/spreadsheet/format.rb', line 71 def pattern @pattern end |
#rotation ⇒ Object
Text rotation
74 75 76 |
# File 'lib/spreadsheet/format.rb', line 74 def rotation @rotation end |
#used_merge ⇒ Object
Returns the value of attribute used_merge.
71 72 73 |
# File 'lib/spreadsheet/format.rb', line 71 def used_merge @used_merge end |
Instance Method Details
#align=(location) ⇒ Object
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.
107 108 109 110 111 |
# File 'lib/spreadsheet/format.rb', line 107 def align= location self.horizontal_align = location rescue ArgumentError self.vertical_align = location rescue ArgumentError end |
#border ⇒ Object
Returns an Array containing the status of the four borders: bottom, top, right, left
115 116 117 |
# File 'lib/spreadsheet/format.rb', line 115 def border [bottom,top,right,left] end |
#border=(boolean) ⇒ Object
Activate or deactivate all four borders (left, right, top, bottom)
120 121 122 |
# File 'lib/spreadsheet/format.rb', line 120 def border=(boolean) [:bottom=, :top=, :right=, :left=].each do |writer| send writer, boolean end end |
#border_color ⇒ Object
Returns an Array containing the colors of the four borders: bottom, top, right, left
126 127 128 |
# File 'lib/spreadsheet/format.rb', line 126 def border_color [@bottom_color,@top_color,@left_color,@right_color] end |
#border_color=(color) ⇒ Object
Set all four border colors to color (left, right, top, bottom)
131 132 133 134 |
# File 'lib/spreadsheet/format.rb', line 131 def border_color=(color) [:bottom_color=, :top_color=, :right_color=, :left_color=].each do |writer| send writer, color end end |
#bottom_color ⇒ Object
Color attributes
36 37 38 |
# File 'lib/spreadsheet/format.rb', line 36 colors :bottom_color, :top_color, :left_color, :right_color, :pattern_fg_color, :pattern_bg_color, :diagonal_color |
#center_across! ⇒ Object Also known as: merge!
Backward compatibility method. May disappear at some point in the future.
152 153 154 |
# File 'lib/spreadsheet/format.rb', line 152 def center_across! self.horizontal_align = :merge end |
#cross_down ⇒ Object
You can set the following boolean attributes:
- #cross_down
-
Draws a Line from the top-left to the bottom-right corner of a cell.
- #cross_up
-
Draws a Line from the bottom-left to the top-right corner of a cell.
- #hidden
-
The cell is hidden.
- #locked
-
The cell is locked.
- #merge_range
-
The cell is in a merged range.
- #shrink
-
Shrink the contents to fit the cell.
- #text_justlast
-
Force the last line of a cell to be justified. This probably makes sense if horizontal_align = :justify
- #left
-
Draw a border to the left of the cell.
- #right
-
Draw a border to the right of the cell.
- #top
-
Draw a border at the top of the cell.
- #bottom
-
Draw a border at the bottom of the cell.
- #rotation_stacked
-
Characters in the cell are stacked on top of each other. Excel will ignore other rotation values if this is set.
31 32 33 |
# File 'lib/spreadsheet/format.rb', line 31 boolean :cross_down, :cross_up, :hidden, :locked, :merge_range, :shrink, :text_justlast, :text_wrap, :left, :right, :top, :bottom, :rotation_stacked |
#date? ⇒ Boolean
Is the cell formatted as a Date?
158 159 160 |
# File 'lib/spreadsheet/format.rb', line 158 def date? !!Regexp.new(client("[YMD]", 'UTF-8')).match(@number_format.to_s) end |
#date_or_time? ⇒ Boolean
Is the cell formatted as a Date or Time?
163 164 165 |
# File 'lib/spreadsheet/format.rb', line 163 def date_or_time? !!Regexp.new(client("[hmsYMD]", 'UTF-8')).match(@number_format.to_s) end |
#datetime? ⇒ Boolean
Is the cell formatted as a DateTime?
168 169 170 |
# File 'lib/spreadsheet/format.rb', line 168 def datetime? !!Regexp.new(client("([YMD].*[HS])|([HS].*[YMD])", 'UTF-8')).match(@number_format.to_s) end |
#horizontal_align ⇒ Object
Horizontal alignment Valid values: :default, :left, :center, :right, :fill, :justify, :merge,
:distributed
Default: :default
58 59 60 61 62 |
# File 'lib/spreadsheet/format.rb', line 58 enum :horizontal_align, :default, :left, :center, :right, :fill, :justify, :merge, :distributed, :center => :centre, :merge => [ :center_across, :centre_across ], :distributed => :equal_space |
#indent_level ⇒ Object Also known as: indent
Indentation level
50 |
# File 'lib/spreadsheet/format.rb', line 50 enum :indent_level, 0, Integer |
#text_direction ⇒ Object Also known as: reading_order
Text direction Valid values: :context, :left_to_right, :right_to_left Default: :context
43 44 45 |
# File 'lib/spreadsheet/format.rb', line 43 enum :text_direction, :context, :left_to_right, :right_to_left, :left_to_right => [:ltr, :l2r], :right_to_left => [:rtl, :r2l] |
#time? ⇒ Boolean
Is the cell formatted as a Time?
173 174 175 |
# File 'lib/spreadsheet/format.rb', line 173 def time? !!Regexp.new(client("[hms]", 'UTF-8')).match(@number_format.to_s) end |
#vertical_align ⇒ Object
Vertical alignment Valid values: :bottom, :top, :middle, :justify, :distributed Default: :bottom
67 68 69 70 |
# File 'lib/spreadsheet/format.rb', line 67 enum :vertical_align, :bottom, :top, :middle, :justify, :distributed, :distributed => [:vdistributed, :vequal_space, :equal_space], :justify => :vjustify, :middle => [:vcenter, :vcentre, :center, :centre] |