Class: Spreadsheet::Format
- Inherits:
-
Object
- Object
- Spreadsheet::Format
- Includes:
- Datatypes, Encodings
- Defined in:
- lib/spreadsheet/format.rb
Overview
Formatting data
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) font
Returns the value of attribute font.
-
- (Object) name
Returns the value of attribute name.
-
- (Object) number_format
Returns the value of attribute number_format.
-
- (Object) pattern
Returns the value of attribute pattern.
-
- (Object) rotation
Text rotation.
-
- (Object) used_merge
Returns the value of attribute used_merge.
Instance Method Summary (collapse)
-
- (Object) align=(location)
Combined method for both horizontal and vertical alignment.
-
- (Object) border
Returns an Array containing the line styles of the four borders: bottom, top, right, left.
-
- (Object) border=(style)
Set same line style on all four borders at once (left, right, top, bottom).
-
- (Object) border_color
Returns an Array containing the colors of the four borders: bottom, top, right, left.
-
- (Object) border_color=(color)
Set all four border colors to color (left, right, top, bottom).
-
- (Object) bottom_color
Color attributes.
-
- (Object) center_across!
(also: #merge!)
Backward compatibility method.
-
- (Object) cross_down
You can set the following boolean attributes:
- #cross_down
-
Draws a Line from the top-left to the bottom-right.
-
- (Boolean) date?
Is the cell formatted as a Date?.
-
- (Boolean) date_or_time?
Is the cell formatted as a Date or Time?.
-
- (Boolean) datetime?
Is the cell formatted as a DateTime?.
-
- (Object) horizontal_align
Horizontal alignment Valid values: :default, :left, :center, :right, :fill, :justify, :merge,.
-
- (Object) indent_level
(also: #indent)
Indentation level.
-
- (Format) initialize(opts = {}) {|_self| ... }
constructor
A new instance of Format.
-
- (Object) text_direction
(also: #reading_order)
Text direction Valid values: :context, :left_to_right, :right_to_left Default: :context.
-
- (Boolean) time?
Is the cell formatted as a Time?.
-
- (Object) vertical_align
Vertical alignment Valid values: :bottom, :top, :middle, :justify, :distributed Default: :bottom.
Methods included from Datatypes
Methods included from Compatibility
Constructor Details
- (Format) initialize(opts = {}) {|_self| ... }
A new instance of Format
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/spreadsheet/format.rb', line 91 def initialize opts={} @font = Font.new client("Arial", 'UTF-8'), :family => :swiss @number_format = client 'GENERAL', 'UTF-8' @rotation = 0 @pattern = 0 @bottom_color = :black @top_color = :black @left_color = :black @right_color = :black @diagonal_color = :black @pattern_fg_color = :border @pattern_bg_color = :pattern_bg @regexes = { :date => Regexp.new(client("[YMD]", 'UTF-8')), :date_or_time => Regexp.new(client("[hmsYMD]", 'UTF-8')), :datetime => Regexp.new(client("([YMD].*[HS])|([HS].*[YMD])", 'UTF-8')), :time => Regexp.new(client("[hms]", 'UTF-8')) } # 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
- (Object) font
Returns the value of attribute font
87 88 89 |
# File 'lib/spreadsheet/format.rb', line 87 def font @font end |
- (Object) name
Returns the value of attribute name
87 88 89 |
# File 'lib/spreadsheet/format.rb', line 87 def name @name end |
- (Object) number_format
Returns the value of attribute number_format
87 88 89 |
# File 'lib/spreadsheet/format.rb', line 87 def number_format @number_format end |
- (Object) pattern
Returns the value of attribute pattern
87 88 89 |
# File 'lib/spreadsheet/format.rb', line 87 def pattern @pattern end |
- (Object) rotation
Text rotation
90 91 92 |
# File 'lib/spreadsheet/format.rb', line 90 def rotation @rotation end |
- (Object) used_merge
Returns the value of attribute used_merge
87 88 89 |
# File 'lib/spreadsheet/format.rb', line 87 def used_merge @used_merge end |
Instance Method Details
- (Object) align=(location)
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.
129 130 131 132 133 |
# File 'lib/spreadsheet/format.rb', line 129 def align= location self.horizontal_align = location rescue ArgumentError self.vertical_align = location rescue ArgumentError end |
- (Object) border
Returns an Array containing the line styles of the four borders: bottom, top, right, left
137 138 139 |
# File 'lib/spreadsheet/format.rb', line 137 def border [bottom, top, right, left] end |
- (Object) border=(style)
Set same line style on all four borders at once (left, right, top, bottom)
142 143 144 |
# File 'lib/spreadsheet/format.rb', line 142 def border=(style) [:bottom=, :top=, :right=, :left=].each do |writer| send writer, style end end |
- (Object) border_color
Returns an Array containing the colors of the four borders: bottom, top, right, left
148 149 150 |
# File 'lib/spreadsheet/format.rb', line 148 def border_color [@bottom_color,@top_color,@right_color,@left_color] end |
- (Object) border_color=(color)
Set all four border colors to color (left, right, top, bottom)
153 154 155 156 |
# File 'lib/spreadsheet/format.rb', line 153 def border_color=(color) [:bottom_color=, :top_color=, :right_color=, :left_color=].each do |writer| send writer, color end end |
- (Object) bottom_color
Color attributes
52 53 54 |
# File 'lib/spreadsheet/format.rb', line 52 colors :bottom_color, :top_color, :left_color, :right_color, :pattern_fg_color, :pattern_bg_color, :diagonal_color |
- (Object) center_across! Also known as: merge!
Backward compatibility method. May disappear at some point in the future.
174 175 176 |
# File 'lib/spreadsheet/format.rb', line 174 def center_across! self.horizontal_align = :merge end |
- (Object) cross_down
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
-
Apply a border style to the left of the cell.
- #right
-
Apply a border style to the right of the cell.
- #top
-
Apply a border style at the top of the cell.
- #bottom
-
Apply a border style 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, :rotation_stacked |
- (Boolean) date?
Is the cell formatted as a Date?
180 181 182 |
# File 'lib/spreadsheet/format.rb', line 180 def date? !!@regexes[:date].match(@number_format.to_s) end |
- (Boolean) date_or_time?
Is the cell formatted as a Date or Time?
185 186 187 |
# File 'lib/spreadsheet/format.rb', line 185 def date_or_time? !!@regexes[:date_or_time].match(@number_format.to_s) end |
- (Boolean) datetime?
Is the cell formatted as a DateTime?
190 191 192 |
# File 'lib/spreadsheet/format.rb', line 190 def datetime? !!@regexes[:datetime].match(@number_format.to_s) end |
- (Object) horizontal_align
Horizontal alignment Valid values: :default, :left, :center, :right, :fill, :justify, :merge,
:distributed
Default: :default
74 75 76 77 78 |
# File 'lib/spreadsheet/format.rb', line 74 enum :horizontal_align, :default, :left, :center, :right, :fill, :justify, :merge, :distributed, :center => :centre, :merge => [ :center_across, :centre_across ], :distributed => :equal_space |
- (Object) indent_level Also known as: indent
Indentation level
66 |
# File 'lib/spreadsheet/format.rb', line 66 enum :indent_level, 0, Integer |
- (Object) text_direction Also known as: reading_order
Text direction Valid values: :context, :left_to_right, :right_to_left Default: :context
59 60 61 |
# File 'lib/spreadsheet/format.rb', line 59 enum :text_direction, :context, :left_to_right, :right_to_left, :left_to_right => [:ltr, :l2r], :right_to_left => [:rtl, :r2l] |
- (Boolean) time?
Is the cell formatted as a Time?
195 196 197 |
# File 'lib/spreadsheet/format.rb', line 195 def time? !!@regexes[:time].match(@number_format.to_s) end |
- (Object) vertical_align
Vertical alignment Valid values: :bottom, :top, :middle, :justify, :distributed Default: :bottom
83 84 85 86 |
# File 'lib/spreadsheet/format.rb', line 83 enum :vertical_align, :bottom, :top, :middle, :justify, :distributed, :distributed => [:vdistributed, :vequal_space, :equal_space], :justify => :vjustify, :middle => [:vcenter, :vcentre, :center, :centre] |