diff options
| author | Jan-Hendrik Hühne <[email protected]> | 2012-06-06 15:31:31 +0200 |
|---|---|---|
| committer | Jan-Hendrik Hühne <[email protected]> | 2012-06-06 15:47:35 +0200 |
| commit | ac94d6ff30467bdfdfb182bf2f8fcd945fbd748a (patch) | |
| tree | 87ba4f973040d6ddfbcad6e0d526a5d786d6e6ff /lib/axlsx/workbook/worksheet/pane.rb | |
| parent | 91ca0f8cc747ad2156370304361469a5c4bd20eb (diff) | |
| download | caxlsx-ac94d6ff30467bdfdfb182bf2f8fcd945fbd748a.tar.gz caxlsx-ac94d6ff30467bdfdfb182bf2f8fcd945fbd748a.zip | |
Basic pane stuff.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/pane.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/pane.rb | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/worksheet/pane.rb b/lib/axlsx/workbook/worksheet/pane.rb new file mode 100644 index 00000000..11722d58 --- /dev/null +++ b/lib/axlsx/workbook/worksheet/pane.rb @@ -0,0 +1,140 @@ +# encoding: UTF-8 +module Axlsx + # Pane options for a worksheet. + # + # @note The recommended way to manage the pane options is via SheetView#pane + # @see SheetView#pane + class Pane + + # Active Pane + # The pane that is active. + # Options are + # * bottom_left: Bottom left pane, when both vertical and horizontal + # splits are applied. This value is also used when only + # a horizontal split has been applied, dividing the pane + # into upper and lower regions. In that case, this value + # specifies the bottom pane. + # * bottom_right: Bottom right pane, when both vertical and horizontal + # splits are applied. + # * top_left: Top left pane, when both vertical and horizontal splits + # are applied. This value is also used when only a horizontal + # split has been applied, dividing the pane into upper and lower + # regions. In that case, this value specifies the top pane. + # This value is also used when only a vertical split has + # been applied, dividing the pane into right and left + # regions. In that case, this value specifies the left pane + # * top_right: Top right pane, when both vertical and horizontal + # splits are applied. This value is also used when only + # a vertical split has been applied, dividing the pane + # into right and left regions. In that case, this value + # specifies the right pane. + # @see type + # @return [Symbol] + # @default nil + attr_reader :active_pane + + + # Split State + # Indicates whether the pane has horizontal / vertical + # splits, and whether those splits are frozen. + # Options are + # * frozen: Panes are frozen, but were not split being frozen. In + # this state, when the panes are unfrozen again, a single + # pane results, with no split. In this state, the split + # bars are not adjustable. + # * frozen_split: Panes are frozen and were split before being frozen. In + # this state, when the panes are unfrozen again, the split + # remains, but is adjustable. + # * split: Panes are split, but not frozen. In this state, the split + # bars are adjustable by the user. + # @see type + # @return [Symbol] + # @default nil + attr_reader :state + + + # Top Left Visible Cell + # Location of the top left visible cell in the bottom + # right pane (when in Left-To-Right mode). + # @see type + # @return [String] + # @default nil + attr_reader :top_left_cell + + + # Horizontal Split Position + # Horizontal position of the split, in 1/20th of a point; 0 (zero) + # if none. If the pane is frozen, this value indicates the number + # of columns visible in the top pane. + # @see type + # @return [Integer] + # @default nil + attr_reader :x_split + + + # Vertical Split Position + # Vertical position of the split, in 1/20th of a point; 0 (zero) + # if none. If the pane is frozen, this value indicates the number + # of rows visible in the left pane. + # @see type + # @return [Integer] + # @default nil + attr_reader :y_split + + + # Creates a new {Pane} object + # @option options [Symbol] active_pane Active Pane + # @option options [Symbol] state Split State + # @option options [Cell, String] top_left_cell Top Left Visible Cell + # @option options [Integer] x_split Horizontal Split Position + # @option options [Integer] y_split Vertical Split Position + def initialize(options={}) + #defaults + @active_pane = @state = @top_left_cell = @x_split = @y_split = nil + + # write options to instance variables + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + end + + + # @see active_pane + def active_pane=(v); Axlsx::validate_active_pane_type(v); @active_pane = v end + + + # @see state + def state=(v); Axlsx::validate_split_state_type(v); @state = v end + + + # @see top_left_cell + def top_left_cell=(v) + cell = (v.class == Axlsx::Cell ? v.r_abs : v) + Axlsx::validate_string(cell) + @top_left_cell = cell + end + + + # @see x_split + def x_split=(v); Axlsx::validate_unsigned_int(v); @x_split = v end + + + # @see y_split + def y_split=(v); Axlsx::validate_unsigned_int(v); @y_split = v end + + + # Serializes the data validation + # @param [String] str + # @return [String] + def to_xml_string(str = '') + str << '<pane ' + instance_values.map { |key, value| '' << key.gsub(/_(.)/){ $1.upcase } << %{="#{format_value(key, value)}"} unless value.nil? }.join(' ') + str << '/>' + end + end + +private + def format_value(key, value) + [:active_pane, :state].include?(key) ? value.gsub(/_(.)/){ $1.upcase } : value + end +end
\ No newline at end of file |
