Class: Spreadsheet::Format

### Home Classes Methods

### In Files

- lib/spreadsheet/format.rb

### Parent

Object

### Methods

- ::new
- #align=
- #border
- #border=
- #border_color
- #border_color=
- #bottom_color
- #center_across!
- #cross_down
- #date?
- #date_or_time?
- #datetime?
- #horizontal_align
- #indent
- #indent_level
- #merge!
- #number?
- #rotation=
- #time?
- #update_format

### Included Modules

- Spreadsheet::Datatypes
- Spreadsheet::Encodings

### Files

- LICENSE.txt
- Manifest.txt

### Class/Module Index

Quicksearch

- Spreadsheet
- Spreadsheet::Column
- Spreadsheet::Compatibility
- Spreadsheet::Datatypes
- Spreadsheet::Encodings
- Spreadsheet::Errors
- Spreadsheet::Excel
- Spreadsheet::Excel::Error
- Spreadsheet::Excel::ExcelCompatibleWorkbook
- Spreadsheet::Excel::Internals
- Spreadsheet::Excel::Internals::Biff5
- Spreadsheet::Excel::Internals::Biff8
- Spreadsheet::Excel::Offset
- Spreadsheet::Excel::Password
- Spreadsheet::Excel::Reader
- Spreadsheet::Excel::Reader::Biff5
- Spreadsheet::Excel::Rgb
- Spreadsheet::Excel::Row
- Spreadsheet::Excel::SstEntry
- Spreadsheet::Excel::Workbook
- Spreadsheet::Excel::Worksheet
- Spreadsheet::Font
- Spreadsheet::Format
- Spreadsheet::Formula
- Spreadsheet::Helpers
- Spreadsheet::Link
- Spreadsheet::Note
- Spreadsheet::NoteObject
- Spreadsheet::ParseExcel
- Spreadsheet::ParseExcel::Worksheet
- Spreadsheet::ParseExcel::Worksheet::Cell
- Spreadsheet::Row
- Spreadsheet::Workbook
- Spreadsheet::Worksheet
- Spreadsheet::Writer

No matching classes.

# Spreadsheet::Format

Formatting data

### Attributes

font[RW]
name[RW]
number_format[RW]
pattern[RW]
rotation[R]

Text rotation

used_merge[RW]

### Public Class Methods

new(opts={}) click to toggle source

    # File lib/spreadsheet/format.rb, line 90
    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')),
        :number       => Regexp.new(client("[\#]", 'UTF-8'))
      }

      # Temp code to prevent merged formats in non-merged cells.
      @used_merge = 0
      update_format(opts)

      yield self if block_given?
    end

### Public Instance Methods

align=(location) click to toggle source

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 133
    def align= location
      self.horizontal_align = location
    rescue ArgumentError
      self.vertical_align = location rescue ArgumentError
    end

border() click to toggle source

Returns an Array containing the line styles of the four borders: bottom, top, right, left

    # File lib/spreadsheet/format.rb, line 141
    def border
      [bottom, top, right, left]
    end

border=(style) click to toggle source

Set same line style on all four borders at once (left, right, top, bottom)

    # File lib/spreadsheet/format.rb, line 146
    def border=(style)
      [:bottom=, :top=, :right=, :left=].each do |writer| send writer, style end
    end

border_color() click to toggle source

Returns an Array containing the colors of the four borders: bottom, top, right, left

    # File lib/spreadsheet/format.rb, line 152
    def border_color
      [@bottom_color,@top_color,@right_color,@left_color]
    end

border_color=(color) click to toggle source

Set all four border colors to color (left, right, top, bottom)

    # File lib/spreadsheet/format.rb, line 157
    def border_color=(color)
      [:bottom_color=, :top_color=, :right_color=, :left_color=].each do |writer|
        send writer, color end
    end

bottom_color click to toggle source

Color attributes

    # File lib/spreadsheet/format.rb, line 51
    colors  :bottom_color, :top_color, :left_color, :right_color,
            :pattern_fg_color, :pattern_bg_color,
            :diagonal_color

center_across!() click to toggle source

Backward compatibility method. May disappear at some point in the future.

    # File lib/spreadsheet/format.rb, line 178
    def center_across!
      self.horizontal_align = :merge
    end

Also aliased as: merge!
cross_down click to toggle source

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.

    # File lib/spreadsheet/format.rb, line 30
    boolean :cross_down, :cross_up, :hidden, :locked,
            :merge_range, :shrink, :text_justlast, :text_wrap,
                                                :rotation_stacked

date?() click to toggle source

Is the cell formatted as a Date?

    # File lib/spreadsheet/format.rb, line 184
    def date?
      !number? && !!@regexes[:date].match(@number_format.to_s)
    end

date_or_time?() click to toggle source

Is the cell formatted as a Date or Time?

    # File lib/spreadsheet/format.rb, line 189
    def date_or_time?
      !number? && !!@regexes[:date_or_time].match(@number_format.to_s)
    end

datetime?() click to toggle source

Is the cell formatted as a DateTime?

    # File lib/spreadsheet/format.rb, line 194
    def datetime?
      !number? && !!@regexes[:datetime].match(@number_format.to_s)
    end

horizontal_align click to toggle source

Horizontal alignment Valid values: :default, :left, :center, :right, :fill, :justify, :merge,

    :distributed

Default: :default

    # File lib/spreadsheet/format.rb, line 73
    enum :horizontal_align, :default, :left, :center, :right, :fill, :justify,
                            :merge, :distributed,
         :center      => :centre,
         :merge       => [ :center_across, :centre_across ],
         :distributed => :equal_space

indent click to toggle source
Alias for: indent_level
indent_level click to toggle source

Indentation level

    # File lib/spreadsheet/format.rb, line 65
    enum :indent_level, 0, Integer

Also aliased as: indent
merge!() click to toggle source
Alias for: center_across!
number?() click to toggle source

Is the cell formatted as a number?

    # File lib/spreadsheet/format.rb, line 204
    def number?
      !!@regexes[:number].match(@number_format.to_s)
    end

rotation=(rot) click to toggle source

Set the Text rotation Valid values: Integers from -90 to 90, or :stacked (sets rotation_stacked to true)

    # File lib/spreadsheet/format.rb, line 165
    def rotation=(rot)
      if rot.to_s.downcase == 'stacked'
        @rotation_stacked = true
        @rotation = 0
      elsif rot.kind_of?(Integer)
        @rotation_stacked = false
        @rotation = rot % 360
      else
        raise TypeError, "rotation value must be an Integer or the String 'stacked'"
      end
    end

time?() click to toggle source

Is the cell formatted as a Time?

    # File lib/spreadsheet/format.rb, line 199
    def time?
      !number? && !!@regexes[:time].match(@number_format.to_s)
    end

update_format(opts = {}) click to toggle source

    # File lib/spreadsheet/format.rb, line 117
    def update_format(opts = {})
      opts.each do |attribute, value|
        writer = "#{attribute}="
        @font.respond_to?(writer) ? @font.send(writer,value) : self.send(writer, value)
      end
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.