summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/sheet_view.rb34
-rw-r--r--lib/axlsx/util/validators.rb32
-rw-r--r--lib/axlsx/workbook/workbook.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/page_setup.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/pane.rb144
-rw-r--r--lib/axlsx/workbook/worksheet/selection.rb111
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_view.rb376
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb37
-rw-r--r--test/util/tc_validators.rb79
-rw-r--r--test/workbook/worksheet/tc_pane.rb88
-rw-r--r--test/workbook/worksheet/tc_selection.rb94
-rw-r--r--test/workbook/worksheet/tc_sheet_view.rb223
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb7
13 files changed, 1197 insertions, 34 deletions
diff --git a/examples/sheet_view.rb b/examples/sheet_view.rb
new file mode 100644
index 00000000..2cbe680a
--- /dev/null
+++ b/examples/sheet_view.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby -w -s
+# -*- coding: utf-8 -*-
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+require 'axlsx'
+
+p = Axlsx::Package.new
+ws = p.workbook.add_worksheet :name => "Sheetview - Split"
+ws.sheet_view do |vs|
+ vs.pane do |p|
+ p.active_pane = :top_right
+ p.state = :split
+ p.x_split = 11080
+ p.y_split = 5000
+ p.top_left_cell = 'C44'
+ end
+
+ vs.add_selection(:top_left, { :active_cell => 'A2', :sqref => 'A2' })
+ vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
+ vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
+ vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
+end
+
+
+ws = p.workbook.add_worksheet :name => "Sheetview - Frozen"
+ws.sheet_view do |vs|
+ vs.pane do |p|
+ p.state = :frozen
+ p.x_split = 3
+ p.y_split = 4
+ end
+end
+
+
+p.serialize 'sheet_view.xlsx' \ No newline at end of file
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 27d895e8..0f4f0dce 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -109,9 +109,14 @@ module Axlsx
end
# Requires that the value is an integer ranging from 10 to 400.
- def self.validate_page_scale(v)
+ def self.validate_scale_10_400(v)
DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg >= 10 && arg <= 400 }
end
+
+ # Requires that the value is an integer ranging from 10 to 400 or 0.
+ def self.validate_scale_0_10_400(v)
+ DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
+ end
# Requires that the value is one of :default, :landscape, or :portrait.
def self.validate_page_orientation(v)
@@ -132,8 +137,6 @@ module Axlsx
# thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
def self.validate_time_period_type(v)
RestrictionValidator.validate :time_period_type, [:today, :yesterday, :tomorrow, :last7Days, :thisMonth, :lastMonth, :nextMonth, :thisWeek, :lastWeek, :nextWeek], v
-
-
end
# Requires that the value is one of the valid ST_IconSet types
@@ -238,4 +241,25 @@ module Axlsx
def self.validate_data_validation_type(v)
RestrictionValidator.validate :data_validation_type, [:custom, :data, :decimal, :list, :none, :textLength, :time, :whole], v
end
-end
+
+ # Requires that the value is a valid sheet view type.
+ # valid types must be one of normal, page_break_preview, page_layout
+ # @param [Any] v The value validated
+ def self.validate_sheet_view_type(v)
+ RestrictionValidator.validate :sheet_view_type, [:normal, :page_break_preview, :page_layout], v
+ end
+
+ # Requires that the value is a valid active pane type.
+ # valid types must be one of bottom_left, bottom_right, top_left, top_right
+ # @param [Any] v The value validated
+ def self.validate_pane_type(v)
+ RestrictionValidator.validate :active_pane_type, [:bottom_left, :bottom_right, :top_left, :top_right], v
+ end
+
+ # Requires that the value is a valid split state type.
+ # valid types must be one of frozen, frozen_split, split
+ # @param [Any] v The value validated
+ def self.validate_split_state_type(v)
+ RestrictionValidator.validate :split_state_type, [:frozen, :frozen_split, :split], v
+ end
+end \ No newline at end of file
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index f0b926db..d53a0b44 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -21,7 +21,9 @@ require 'axlsx/workbook/worksheet/worksheet.rb'
require 'axlsx/workbook/shared_strings_table.rb'
require 'axlsx/workbook/worksheet/table.rb'
require 'axlsx/workbook/worksheet/data_validation.rb'
-
+require 'axlsx/workbook/worksheet/sheet_view.rb'
+require 'axlsx/workbook/worksheet/pane.rb'
+require 'axlsx/workbook/worksheet/selection.rb'
# The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
# The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
#
diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb
index fdfab981..10cba403 100644
--- a/lib/axlsx/workbook/worksheet/page_setup.rb
+++ b/lib/axlsx/workbook/worksheet/page_setup.rb
@@ -79,7 +79,7 @@ module Axlsx
# @see paper_width
def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
# @see scale
- def scale=(v); Axlsx::validate_page_scale(v); @scale = v; end
+ def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
# convenience method to achieve sanity when setting fit_to_width and fit_to_height
# as they both default to 1 if only their counterpart is specified.
diff --git a/lib/axlsx/workbook/worksheet/pane.rb b/lib/axlsx/workbook/worksheet/pane.rb
new file mode 100644
index 00000000..8403c9ec
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/pane.rb
@@ -0,0 +1,144 @@
+# 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 0
+ 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 0
+ 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 = nil
+ @x_split = @y_split = 0
+
+ # 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_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 = '')
+ if @state == :frozen && @top_left_cell.nil?
+ row = @y_split || 0
+ column = @x_split || 0
+
+ @top_left_cell = "#{('A'..'ZZ').to_a[column]}#{row+1}"
+ end
+
+ str << '<pane '
+ str << instance_values.map { |key, value| '' << key.gsub(/_(.)/){ $1.upcase } <<
+ %{="#{[:active_pane, :state].include?(key.to_sym) ? value.to_s.gsub(/_(.)/){ $1.upcase } : value}"} unless value.nil? }.join(' ')
+ str << '/>'
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/axlsx/workbook/worksheet/selection.rb b/lib/axlsx/workbook/worksheet/selection.rb
new file mode 100644
index 00000000..6674c55d
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/selection.rb
@@ -0,0 +1,111 @@
+# encoding: UTF-8
+module Axlsx
+ # Selection options for worksheet panes.
+ #
+ # @note The recommended way to manage the selection pane options is via SheetView#add_selection
+ # @see SheetView#add_selection
+ class Selection
+
+ # Active Cell Location
+ # Location of the active cell.
+ # @see type
+ # @return [String]
+ # @default nil
+ attr_reader :active_cell
+
+
+ # Active Cell Index
+ # 0-based index of the range reference (in the array of references listed in sqref)
+ # containing the active cell. Only used when the selection in sqref is not contiguous.
+ # Therefore, this value needs to be aware of the order in which the range references are
+ # written in sqref.
+ # When this value is out of range then activeCell can be used.
+ # @see type
+ # @return [Integer]
+ # @default nil
+ attr_reader :active_cell_id
+
+
+ # Pane
+ # The pane to which this selection belongs.
+ # 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 :pane
+
+
+ # Sequence of References
+ # Range of the selection. Can be non-contiguous set of ranges.
+ # @see type
+ # @return [String]
+ # @default nil
+ attr_reader :sqref
+
+
+ # Creates a new {Selection} object
+ # @option options [Cell, String] active_cell Active Cell Location
+ # @option options [Integer] active_cell_id Active Cell Index
+ # @option options [Symbol] pane Pane
+ # @option options [String] sqref Sequence of References
+ def initialize(options={})
+ #defaults
+ @active_cell = @active_cell_id = @pane = @sqref = 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_cell
+ def active_cell=(v)
+ cell = (v.class == Axlsx::Cell ? v.r_abs : v)
+ Axlsx::validate_string(cell)
+ @active_cell = cell
+ end
+
+
+ # @see active_cell_id
+ def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
+
+
+ # @see pane
+ def pane=(v); Axlsx::validate_pane_type(v); @pane = v end
+
+
+ # @see sqref
+ def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+
+
+ # Serializes the data validation
+ # @param [String] str
+ # @return [String]
+ def to_xml_string(str = '')
+ str << '<selection '
+ str << instance_values.map { |key, value| '' << key.gsub(/_(.)/){ $1.upcase } <<
+ %{="#{[:pane].include?(key.to_sym) ? value.to_s.gsub(/_(.)/){ $1.upcase } : value}"} unless value.nil? }.join(' ')
+ str << '/>'
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/axlsx/workbook/worksheet/sheet_view.rb b/lib/axlsx/workbook/worksheet/sheet_view.rb
new file mode 100644
index 00000000..0cc50200
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/sheet_view.rb
@@ -0,0 +1,376 @@
+# encoding: UTF-8
+module Axlsx
+ # View options for a worksheet.
+ #
+ # @note The recommended way to manage the sheet view is via Worksheet#sheet_view
+ # @see Worksheet#sheet_view
+ class SheetView
+
+ # instance values that must be serialized as their own elements - e.g. not attributes.
+ CHILD_ELEMENTS = [ :pane, :selections ]
+
+ # The pane object for the sheet view
+ # @return [Pane]
+ # @see [Pane]
+ def pane
+ @pane ||= Pane.new
+ yield @pane if block_given?
+ @pane
+ end
+
+
+ # Color Id
+ # Index to the color value for row/column
+ # text headings and gridlines. This is an
+ # 'index color value' (ICV) rather than
+ # rgb value.
+ # @see type
+ # @return [Integer]
+ # @default nil
+ attr_reader :color_id
+
+
+ # Default Grid Color
+ # Flag indicating that the consuming application
+ # should use the default grid lines color
+ # (system dependent). Overrides any color
+ # specified in colorId.
+ # @see type
+ # @return [Boolean]
+ # @default true
+ attr_reader :default_grid_color
+
+
+ # Right To Left
+ # Flag indicating whether the sheet is in
+ # 'right to left' display mode. When in this
+ # mode, Column A is on the far right, Column B ;
+ # is one column left of Column A, and so on. Also,
+ # information in cells is displayed in the Right
+ # to Left format.
+ # @see type
+ # @return [Boolean]
+ # @default false
+ attr_reader :right_to_left
+
+
+ # Show Formulas
+ # Flag indicating whether this sheet should
+ # display formulas.
+ # @see type
+ # @return [Boolean]
+ # @default false
+ attr_reader :show_formulas
+
+
+ # Show Grid Lines
+ # Flag indicating whether this sheet
+ # should display gridlines.
+ # @see type
+ # @return [Boolean]
+ # @default true
+ attr_reader :show_grid_lines
+
+
+ # Show Outline Symbols
+ # Flag indicating whether the sheet has outline
+ # symbols visible. This flag shall always override
+ # SheetPr element's outlinePr child element
+ # whose attribute is named showOutlineSymbols
+ # when there is a conflict.
+ # @see type
+ # @return [Boolean]
+ # @default false
+ attr_reader :show_outline_symbols
+
+
+ # Show Headers
+ # Flag indicating whether the sheet should
+ # display row and column headings.
+ # @see type
+ # @return [Boolean]
+ # @default true
+ attr_reader :show_row_col_headers
+
+
+ # Show Ruler
+ # Show the ruler in Page Layout View.
+ # @see type
+ # @return [Boolean]
+ # @default true
+ attr_reader :show_ruler
+
+
+ # Show White Space
+ # Flag indicating whether page layout
+ # view shall display margins. False means
+ # do not display left, right, top (header),
+ # and bottom (footer) margins (even when
+ # there is data in the header or footer).
+ # @see type
+ # @return [Boolean]
+ # @default false
+ attr_reader :show_white_space
+
+
+ # Show Zero Values
+ # Flag indicating whether the window should
+ # show 0 (zero) in cells containing zero value.
+ # When false, cells with zero value appear
+ # blank instead of showing the number zero.
+ # @see type
+ # @return [Boolean]
+ # @default true
+ attr_reader :show_zeros
+
+
+ # Sheet Tab Selected
+ # Flag indicating whether this sheet is selected.
+ # When only 1 sheet is selected and active, this
+ # value should be in synch with the activeTab value.
+ # In case of a conflict, the Start Part setting
+ # wins and sets the active sheet tab. Multiple
+ # sheets can be selected, but only one sheet shall
+ # be active at one time.
+ # @see type
+ # @return [Boolean]
+ # @default false
+ attr_reader :tab_selected
+
+
+ # Top Left Visible Cell
+ # Location of the 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
+
+
+ # View Type
+ # Indicates the view type.
+ # Options are
+ # * normal: Normal view
+ # * page_break_preview: Page break preview
+ # * page_layout: Page Layout View
+ # @see type
+ # @return [Symbol]
+ # @default :normal
+ attr_reader :view
+
+
+ # Window Protection
+ # Flag indicating whether the panes in the window
+ # are locked due to workbook protection.
+ # This is an option when the workbook structure is
+ # protected.
+ # @see type
+ # @return [Boolean]
+ # @default true
+ attr_reader :window_protection
+
+
+ # Workbook View Index
+ # Zero-based index of this workbook view, pointing
+ # to a workbookView element in the bookViews collection.
+ # @see type
+ # @return [Integer]
+ # @default 0
+ attr_reader :workbook_view_id
+
+
+ # Zoom Scale
+ # Window zoom magnification for current view
+ # representing percent values. This attribute
+ # is restricted to values ranging from 10 to 400.
+ # Horizontal & Vertical scale together.
+ # Current view can be Normal, Page Layout, or
+ # Page Break Preview.
+ # @see type
+ # @return [Integer]
+ # @default 100
+ attr_reader :zoom_scale
+
+
+ # Zoom Scale Normal View
+ # Zoom magnification to use when in normal view,
+ # representing percent values. This attribute is
+ # restricted to values ranging from 10 to 400.
+ # Horizontal & Vertical scale together.
+ # Applies for worksheets only; zero implies the
+ # automatic setting.
+ # @see type
+ # @return [Integer]
+ # @default 0
+ attr_reader :zoom_scale_normal
+
+
+ # Zoom Scale Page Layout View
+ # Zoom magnification to use when in page layout
+ # view, representing percent values. This attribute
+ # is restricted to values ranging from 10 to 400.
+ # Horizontal & Vertical scale together.
+ # Applies for worksheets only; zero implies
+ # the automatic setting.
+ # @see type
+ # @return [Integer]
+ # @default 0
+ attr_reader :zoom_scale_page_layout_view
+
+
+ # Zoom Scale Page Break Preview
+ # Zoom magnification to use when in page break
+ # preview, representing percent values. This
+ # attribute is restricted to values ranging
+ # from 10 to 400. Horizontal & Vertical scale
+ # together.
+ # Applies for worksheet only; zero implies
+ # the automatic setting.
+ # @see type
+ # @return [Integer]
+ # @default 0
+ attr_reader :zoom_scale_sheet_layout_view
+
+
+ # Creates a new {SheetView} object
+ # @option options [Integer] color_id Color Id
+ # @option options [Boolean] default_grid_color Default Grid Color
+ # @option options [Boolean] right_to_left Right To Left
+ # @option options [Boolean] show_formulas Show Formulas
+ # @option options [Boolean] show_grid_lines Show Grid Lines
+ # @option options [Boolean] show_outline_symbols Show Outline Symbols
+ # @option options [Boolean] show_row_col_headers Show Headers
+ # @option options [Boolean] show_ruler Show Ruler
+ # @option options [Boolean] show_white_space Show White Space
+ # @option options [Boolean] show_zeros Show Zero Values
+ # @option options [Boolean] tab_selected Sheet Tab Selected
+ # @option options [String, Cell] top_left_cell Top Left Visible Cell
+ # @option options [Symbol] view View Type
+ # @option options [Boolean] window_protection Window Protection
+ # @option options [Integer] workbook_view_id Workbook View Index
+ # @option options [Integer] zoom_scale_normal Zoom Scale Normal View
+ # @option options [Integer] zoom_scale_page_layout_view Zoom Scale Page Layout View
+ # @option options [Integer] zoom_scale_sheet_layout_view Zoom Scale Page Break Preview
+ def initialize(options={})
+ #defaults
+ @color_id = @top_left_cell = @pane = nil
+ @right_to_left = @show_formulas = @show_outline_symbols = @show_white_space = @tab_selected = @window_protection = false
+ @default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = true
+ @zoom_scale = 100
+ @zoom_scale_normal = @zoom_scale_page_layout_view = @zoom_scale_sheet_layout_view = @workbook_view_id = 0
+ @selections = {}
+
+ # write options to instance variables
+ options.each do |o|
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
+ end
+ end
+
+
+ # Adds a new selection
+ # param [Symbol] pane
+ # param [Hash] options
+ # return [Selection]
+ def add_selection(pane, options = {})
+ @selections[pane] = Selection.new(options.merge(:pane => pane))
+ end
+
+ # @see color_id
+ def color_id=(v); Axlsx::validate_unsigned_int(v); @color_id = v end
+
+
+ # @see default_grid_color
+ def default_grid_color=(v); Axlsx::validate_boolean(v); @default_grid_color = v end
+
+
+ # @see right_to_left
+ def right_to_left=(v); Axlsx::validate_boolean(v); @right_to_left = v end
+
+
+ # @see show_formulas
+ def show_formulas=(v); Axlsx::validate_boolean(v); @show_formulas = v end
+
+
+ # @see show_grid_lines
+ def show_grid_lines=(v); Axlsx::validate_boolean(v); @show_grid_lines = v end
+
+
+ # @see show_outline_symbols
+ def show_outline_symbols=(v); Axlsx::validate_boolean(v); @show_outline_symbols = v end
+
+
+ # @see show_row_col_headers
+ def show_row_col_headers=(v); Axlsx::validate_boolean(v); @show_row_col_headers = v end
+
+
+ # @see show_ruler
+ def show_ruler=(v); Axlsx::validate_boolean(v); @show_ruler = v end
+
+
+ # @see show_white_space
+ def show_white_space=(v); Axlsx::validate_boolean(v); @show_white_space = v end
+
+
+ # @see show_zeros
+ def show_zeros=(v); Axlsx::validate_boolean(v); @show_zeros = v end
+
+
+ # @see tab_selected
+ def tab_selected=(v); Axlsx::validate_boolean(v); @tab_selected = 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 view
+ def view=(v); Axlsx::validate_sheet_view_type(v); @view = v end
+
+
+ # @see window_protection
+ def window_protection=(v); Axlsx::validate_boolean(v); @window_protection = v end
+
+
+ # @see workbook_view_id
+ def workbook_view_id=(v); Axlsx::validate_unsigned_int(v); @workbook_view_id = v end
+
+
+ # @see zoom_scale
+ def zoom_scale=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale = v end
+
+
+ # @see zoom_scale_normal
+ def zoom_scale_normal=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_normal = v end
+
+
+ # @see zoom_scale_page_layout_view
+ def zoom_scale_page_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
+
+
+ # @see zoom_scale_sheet_layout_view
+ def zoom_scale_sheet_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
+
+
+ # Serializes the data validation
+ # @param [String] str
+ # @return [String]
+ def to_xml_string(str = '')
+ str << '<sheetViews>'
+ str << '<sheetView '
+ str << instance_values.map { |key, value| '' << key.gsub(/_(.)/){ $1.upcase } << %{="#{value}"} unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
+ str << '>'
+ @pane.to_xml_string(str) if @pane
+ @selections.each do |key, selection|
+ selection.to_xml_string(str)
+ end
+ str << '<selection activeCell="A1" sqref="A1" />'
+ str << '</sheetView>'
+ str << '</sheetViews>'
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 3f73ee19..741e38b1 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -16,6 +16,15 @@ module Axlsx
yield @sheet_protection if block_given?
@sheet_protection
end
+
+ # The sheet view object for this worksheet
+ # @return [SheetView]
+ # @see [SheetView]
+ def sheet_view
+ @sheet_view ||= SheetView.new
+ yield @sheet_view if block_given?
+ @sheet_view
+ end
# The workbook that owns this worksheet
# @return [Workbook]
@@ -51,14 +60,21 @@ module Axlsx
# Indicates if the worksheet should show gridlines or not
# @return Boolean
- attr_reader :show_gridlines
-
+ # @deprecated Use {SheetView#show_grid_lines} instead.
+ def show_gridlines
+ warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
+ sheet_view.show_grid_lines
+ end
# Indicates if the worksheet is selected in the workbook
# It is possible to have more than one worksheet selected, however it might cause issues
# in some older versions of excel when using copy and paste.
# @return Boolean
- attr_reader :selected
+ # @deprecated Use {SheetView#tab_selected} instead.
+ def selected
+ warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
+ sheet_view.tab_selected
+ end
# Indicates if the worksheet will be fit by witdh or height to a specific number of pages.
# To alter the width or height for page fitting, please use page_setup.fit_to_widht or page_setup.fit_to_height.
@@ -160,14 +176,12 @@ module Axlsx
self.workbook = wb
@workbook.worksheets << self
@page_marging = @page_setup = @print_options = nil
- @drawing = @page_margins = @auto_filter = @sheet_protection = nil
+ @drawing = @page_margins = @auto_filter = @sheet_protection = @sheet_view = nil
@merged_cells = []
@auto_fit_data = []
@conditional_formattings = []
@data_validations = []
@comments = Comments.new(self)
- @selected = false
- @show_gridlines = true
self.name = "Sheet" + (index+1).to_s
@page_margins = PageMargins.new options[:page_margins] if options[:page_margins]
@page_setup = PageSetup.new options[:page_setup] if options[:page_setup]
@@ -246,16 +260,20 @@ module Axlsx
# Indicates if gridlines should be shown in the sheet.
# This is true by default.
# @return [Boolean]
+ # @deprecated Use {SheetView#show_grid_lines=} instead.
def show_gridlines=(v)
+ warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
Axlsx::validate_boolean v
- @show_gridlines = v
+ sheet_view.show_grid_lines = v
end
# @see selected
# @return [Boolean]
+ # @deprecated Use {SheetView#tab_selected=} instead.
def selected=(v)
+ warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
Axlsx::validate_boolean v
- @selected = v
+ sheet_view.tab_selected = v
end
@@ -492,8 +510,7 @@ module Axlsx
str.concat "<worksheet xmlns=\"%s\" xmlns:r=\"%s\">" % [XML_NS, XML_NS_R]
str.concat "<sheetPr><pageSetUpPr fitToPage=\"%s\"></pageSetUpPr></sheetPr>" % fit_to_page if fit_to_page
str.concat "<dimension ref=\"%s\"></dimension>" % dimension unless rows.size == 0
- str.concat "<sheetViews><sheetView tabSelected='%s' workbookViewId='0' showGridLines='%s'><selection activeCell=\"A1\" sqref=\"A1\"/></sheetView></sheetViews>" % [@selected, show_gridlines]
-
+ @sheet_view.to_xml_string(str) if @sheet_view
if @column_info.size > 0
str << "<cols>"
@column_info.each { |col| col.to_xml_string(str) }
diff --git a/test/util/tc_validators.rb b/test/util/tc_validators.rb
index bcb2eadf..4de13ec3 100644
--- a/test/util/tc_validators.rb
+++ b/test/util/tc_validators.rb
@@ -83,15 +83,25 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "mm" }
assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "-29cm" }
- #page_scale
- assert_nothing_raised { Axlsx.validate_page_scale 10 }
- assert_nothing_raised { Axlsx.validate_page_scale 100 }
- assert_nothing_raised { Axlsx.validate_page_scale 400 }
- assert_raise(ArgumentError) { Axlsx.validate_page_scale 9 }
- assert_raise(ArgumentError) { Axlsx.validate_page_scale 10.0 }
- assert_raise(ArgumentError) { Axlsx.validate_page_scale 400.1 }
- assert_raise(ArgumentError) { Axlsx.validate_page_scale "99" }
-
+ #scale_10_400
+ assert_nothing_raised { Axlsx.validate_scale_10_400 10 }
+ assert_nothing_raised { Axlsx.validate_scale_10_400 100 }
+ assert_nothing_raised { Axlsx.validate_scale_10_400 400 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 9 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 10.0 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 400.1 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 "99" }
+
+ #scale_0_10_400
+ assert_nothing_raised { Axlsx.validate_scale_0_10_400 0 }
+ assert_nothing_raised { Axlsx.validate_scale_0_10_400 10 }
+ assert_nothing_raised { Axlsx.validate_scale_0_10_400 100 }
+ assert_nothing_raised { Axlsx.validate_scale_0_10_400 400 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 9 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 10.0 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 400.1 }
+ assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 "99" }
+
#page_orientation
assert_nothing_raised { Axlsx.validate_page_orientation :default }
assert_nothing_raised { Axlsx.validate_page_orientation :landscape }
@@ -99,6 +109,53 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_page_orientation nil }
assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 }
assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" }
+
+ #data_validation_error_style
+ [:information, :stop, :warning].each do |sym|
+ assert_nothing_raised { Axlsx.validate_data_validation_error_style sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'warning' }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
+
+ #data_validation_operator
+ [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].each do |sym|
+ assert_nothing_raised { Axlsx.validate_data_validation_operator sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'lessThan' }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
+
+ #data_validation_type
+ [:custom, :data, :decimal, :list, :none, :textLength, :time, :whole].each do |sym|
+ assert_nothing_raised { Axlsx.validate_data_validation_type sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'decimal' }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
+
+ #sheet_view_type
+ [:normal, :page_break_preview, :page_layout].each do |sym|
+ assert_nothing_raised { Axlsx.validate_sheet_view_type sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'page_layout' }
+ assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
+
+ #active_pane_type
+ [:bottom_left, :bottom_right, :top_left, :top_right].each do |sym|
+ assert_nothing_raised { Axlsx.validate_pane_type sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_pane_type :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_pane_type 'bottom_left' }
+ assert_raise(ArgumentError) { Axlsx.validate_pane_type 0 }
+
+ #split_state_type
+ [:frozen, :frozen_split, :split].each do |sym|
+ assert_nothing_raised { Axlsx.validate_split_state_type sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_split_state_type :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_split_state_type 'frozen_split' }
+ assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 }
end
-end
-
+end \ No newline at end of file
diff --git a/test/workbook/worksheet/tc_pane.rb b/test/workbook/worksheet/tc_pane.rb
new file mode 100644
index 00000000..e2bd1519
--- /dev/null
+++ b/test/workbook/worksheet/tc_pane.rb
@@ -0,0 +1,88 @@
+# encoding: UTF-8
+require 'tc_helper.rb'
+
+class TestPane < Test::Unit::TestCase
+ def setup
+ #inverse defaults for booleans
+ @nil_options = { :active_pane => :bottom_left, :state => :frozen, :top_left_cell => 'A2' }
+ @int_0_options = { :x_split => 2, :y_split => 2 }
+
+ @string_options = { :top_left_cell => 'A2' }
+ @integer_options = { :x_split => 2, :y_split => 2 }
+ @symbol_options = { :active_pane => :bottom_left, :state => :frozen }
+
+ @options = @nil_options.merge(@int_0_options)
+
+ @pane = Axlsx::Pane.new(@options)
+ end
+
+ def test_initialize
+ pane = Axlsx::Pane.new
+
+ @nil_options.each do |key, value|
+ assert_equal(nil, pane.send(key.to_sym), "initialized default #{key} should be nil")
+ assert_equal(value, @pane.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+
+ @int_0_options.each do |key, value|
+ assert_equal(0, pane.send(key.to_sym), "initialized default #{key} should be 0")
+ assert_equal(value, @pane.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+ end
+
+ def test_string_attribute_validation
+ @string_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be string") { @pane.send("#{key}=".to_sym, :symbol) }
+ assert_nothing_raised { @pane.send("#{key}=".to_sym, "foo") }
+ end
+ end
+
+ def test_symbol_attribute_validation
+ @symbol_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be symbol") { @pane.send("#{key}=".to_sym, "foo") }
+ assert_nothing_raised { @pane.send("#{key}=".to_sym, value) }
+ end
+ end
+
+ def test_integer_attribute_validation
+ @integer_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be integer") { @pane.send("#{key}=".to_sym, "foo") }
+ assert_nothing_raised { @pane.send("#{key}=".to_sym, value) }
+ end
+ end
+
+ def test_active_pane
+ assert_raise(ArgumentError) { @pane.active_pane = "10" }
+ assert_nothing_raised { @pane.active_pane = :top_left }
+ assert_equal(@pane.active_pane, :top_left)
+ end
+
+ def test_state
+ assert_raise(ArgumentError) { @pane.state = "foo" }
+ assert_nothing_raised { @pane.state = :frozen_split }
+ assert_equal(@pane.state, :frozen_split)
+ end
+
+ def test_x_split
+ assert_raise(ArgumentError) { @pane.x_split = "foo´" }
+ assert_nothing_raised { @pane.x_split = 200 }
+ assert_equal(@pane.x_split, 200)
+ end
+
+ def test_y_split
+ assert_raise(ArgumentError) { @pane.y_split = 'foo' }
+ assert_nothing_raised { @pane.y_split = 300 }
+ assert_equal(@pane.y_split, 300)
+ end
+
+ def test_top_left_cell
+ assert_raise(ArgumentError) { @pane.top_left_cell = :cell }
+ assert_nothing_raised { @pane.top_left_cell = "A2" }
+ assert_equal(@pane.top_left_cell, "A2")
+ end
+
+ def test_to_xml
+ doc = Nokogiri::XML.parse(@pane.to_xml_string)
+ assert_equal(1, doc.xpath("//pane[@ySplit=2][@xSplit='2'][@topLeftCell='A2'][@state='frozen'][@activePane='bottomLeft']").size)
+ end
+end
diff --git a/test/workbook/worksheet/tc_selection.rb b/test/workbook/worksheet/tc_selection.rb
new file mode 100644
index 00000000..941cae62
--- /dev/null
+++ b/test/workbook/worksheet/tc_selection.rb
@@ -0,0 +1,94 @@
+# encoding: UTF-8
+require 'tc_helper.rb'
+
+class TestSelection < Test::Unit::TestCase
+ def setup
+ @nil_options = { :active_cell => 'A2', :active_cell_id => 1, :pane => :top_left, :sqref => 'A2' }
+ @options = @nil_options
+
+ @string_options = { :active_cell => 'A2', :sqref => 'A2' }
+ @integer_options = { :active_cell_id => 1 }
+ @symbol_options = { :pane => :top_left }
+
+ @selection = Axlsx::Selection.new(@options)
+ end
+
+ def test_initialize
+ selection = Axlsx::Selection.new
+
+ @nil_options.each do |key, value|
+ assert_equal(nil, selection.send(key.to_sym), "initialized default #{key} should be nil")
+ assert_equal(value, @selection.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+ end
+
+ def test_string_attribute_validation
+ @string_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be string") { @selection.send("#{key}=".to_sym, :symbol) }
+ assert_nothing_raised { @selection.send("#{key}=".to_sym, "foo") }
+ end
+ end
+
+ def test_symbol_attribute_validation
+ @symbol_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be symbol") { @selection.send("#{key}=".to_sym, "foo") }
+ assert_nothing_raised { @selection.send("#{key}=".to_sym, value) }
+ end
+ end
+
+ def test_integer_attribute_validation
+ @integer_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be integer") { @selection.send("#{key}=".to_sym, "foo") }
+ assert_nothing_raised { @selection.send("#{key}=".to_sym, value) }
+ end
+ end
+
+ def test_active_cell
+ assert_raise(ArgumentError) { @selection.active_cell = :active_cell }
+ assert_nothing_raised { @selection.active_cell = "F5" }
+ assert_equal(@selection.active_cell, "F5")
+ end
+
+ def test_active_cell_id
+ assert_raise(ArgumentError) { @selection.active_cell_id = "foo" }
+ assert_nothing_raised { @selection.active_cell_id = 11 }
+ assert_equal(@selection.active_cell_id, 11)
+ end
+
+ def test_pane
+ assert_raise(ArgumentError) { @selection.pane = "foo´" }
+ assert_nothing_raised { @selection.pane = :bottom_right }
+ assert_equal(@selection.pane, :bottom_right)
+ end
+
+ def test_sqref
+ assert_raise(ArgumentError) { @selection.sqref = :sqref }
+ assert_nothing_raised { @selection.sqref = "G32" }
+ assert_equal(@selection.sqref, "G32")
+ end
+
+ def test_to_xml
+ p = Axlsx::Package.new
+ @ws = p.workbook.add_worksheet :name => "sheetview"
+ @ws.sheet_view do |vs|
+ vs.add_selection(:top_left, { :active_cell => 'B2', :sqref => 'B2' })
+ vs.add_selection(:top_right, { :active_cell => 'I10', :sqref => 'I10' })
+ vs.add_selection(:bottom_left, { :active_cell => 'E55', :sqref => 'E55' })
+ vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' })
+ end
+
+ doc = Nokogiri::XML.parse(@ws.to_xml_string)
+
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='B2'][@pane='topLeft'][@activeCell='B2']").size)
+ assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='B2'][@pane='topLeft'][@activeCell='B2']")
+
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I10'][@pane='topRight'][@activeCell='I10']").size)
+ assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I10'][@pane='topRight'][@activeCell='I10']")
+
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='E55'][@pane='bottomLeft'][@activeCell='E55']").size)
+ assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='E55'][@pane='bottomLeft'][@activeCell='E55']")
+
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I57'][@pane='bottomRight'][@activeCell='I57']").size)
+ assert doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref='I57'][@pane='bottomRight'][@activeCell='I57']")
+ end
+end \ No newline at end of file
diff --git a/test/workbook/worksheet/tc_sheet_view.rb b/test/workbook/worksheet/tc_sheet_view.rb
new file mode 100644
index 00000000..12b18c7e
--- /dev/null
+++ b/test/workbook/worksheet/tc_sheet_view.rb
@@ -0,0 +1,223 @@
+# encoding: UTF-8
+require 'tc_helper.rb'
+
+class TestSheetView < Test::Unit::TestCase
+ def setup
+ #inverse defaults for booleans
+ @boolean_options = { :right_to_left => true, :show_formulas => true, :show_outline_symbols => true,
+ :show_white_space => true, :tab_selected => true, :default_grid_color => false, :show_grid_lines => false,
+ :show_row_col_headers => false, :show_ruler => false, :show_zeros => false, :window_protection => true }
+ @symbol_options = { :view => :page_break_preview }
+ @nil_options = { :color_id => 2, :top_left_cell => 'A2' }
+ @int_0 = { :zoom_scale_normal => 100, :zoom_scale_page_layout_view => 100, :zoom_scale_sheet_layout_view => 100, :workbook_view_id => 2 }
+ @int_100 = { :zoom_scale => 10 }
+
+ @integer_options = { :color_id => 2, :workbook_view_id => 2 }.merge(@int_0).merge(@int_100)
+ @string_options = { :top_left_cell => 'A2' }
+
+
+ @options = @boolean_options.merge(@boolean_options).merge(@symbol_options).merge(@nil_options).merge(@int_0).merge(@int_100)
+
+ @sv = Axlsx::SheetView.new(@options)
+ end
+
+ def test_initialize
+ sv = Axlsx::SheetView.new
+
+ @boolean_options.each do |key, value|
+ assert_equal(!value, sv.send(key.to_sym), "initialized default #{key} should be #{!value}")
+ assert_equal(value, @sv.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+
+ @nil_options.each do |key, value|
+ assert_equal(nil, sv.send(key.to_sym), "initialized default #{key} should be nil")
+ assert_equal(value, @sv.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+
+ @int_0.each do |key, value|
+ assert_equal(0, sv.send(key.to_sym), "initialized default #{key} should be 0")
+ assert_equal(value, @sv.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+
+ @int_100.each do |key, value|
+ assert_equal(100, sv.send(key.to_sym), "initialized default #{key} should be 100")
+ assert_equal(value, @sv.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+ end
+
+ def test_boolean_attribute_validation
+ @boolean_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be boolean") { @sv.send("#{key}=".to_sym, 'A') }
+ assert_nothing_raised { @sv.send("#{key}=".to_sym, true) }
+ end
+ end
+
+ def test_string_attribute_validation
+ @string_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be string") { @sv.send("#{key}=".to_sym, :symbol) }
+ assert_nothing_raised { @sv.send("#{key}=".to_sym, "foo") }
+ end
+ end
+
+ def test_symbol_attribute_validation
+ @symbol_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be symbol") { @sv.send("#{key}=".to_sym, "foo") }
+ assert_nothing_raised { @sv.send("#{key}=".to_sym, value) }
+ end
+ end
+
+ def test_integer_attribute_validation
+ @integer_options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be integer") { @sv.send("#{key}=".to_sym, "foo") }
+ assert_nothing_raised { @sv.send("#{key}=".to_sym, value) }
+ end
+ end
+
+ def test_color_id
+ assert_raise(ArgumentError) { @sv.color_id = "10" }
+ assert_nothing_raised { @sv.color_id = 2 }
+ assert_equal(@sv.color_id, 2)
+ end
+
+ def test_default_grid_color
+ assert_raise(ArgumentError) { @sv.default_grid_color = "foo" }
+ assert_nothing_raised { @sv.default_grid_color = false }
+ assert_equal(@sv.default_grid_color, false)
+ end
+
+ def test_right_to_left
+ assert_raise(ArgumentError) { @sv.right_to_left = "foo´" }
+ assert_nothing_raised { @sv.right_to_left = true }
+ assert_equal(@sv.right_to_left, true)
+ end
+
+ def test_show_formulas
+ assert_raise(ArgumentError) { @sv.show_formulas = 'foo' }
+ assert_nothing_raised { @sv.show_formulas = false }
+ assert_equal(@sv.show_formulas, false)
+ end
+
+ def test_show_grid_lines
+ assert_raise(ArgumentError) { @sv.show_grid_lines = "foo" }
+ assert_nothing_raised { @sv.show_grid_lines = false }
+ assert_equal(@sv.show_grid_lines, false)
+ end
+
+ def test_show_outline_symbols
+ assert_raise(ArgumentError) { @sv.show_outline_symbols = 'foo' }
+ assert_nothing_raised { @sv.show_outline_symbols = false }
+ assert_equal(@sv.show_outline_symbols, false)
+ end
+
+ def test_show_row_col_headers
+ assert_raise(ArgumentError) { @sv.show_row_col_headers = "foo" }
+ assert_nothing_raised { @sv.show_row_col_headers = false }
+ assert_equal(@sv.show_row_col_headers, false)
+ end
+
+ def test_show_ruler
+ assert_raise(ArgumentError) { @sv.show_ruler = 'foo' }
+ assert_nothing_raised { @sv.show_ruler = false }
+ assert_equal(@sv.show_ruler, false)
+ end
+
+ def test_show_white_space
+ assert_raise(ArgumentError) { @sv.show_white_space = 'foo' }
+ assert_nothing_raised { @sv.show_white_space = false }
+ assert_equal(@sv.show_white_space, false)
+ end
+
+ def test_show_zeros
+ assert_raise(ArgumentError) { @sv.show_zeros = "foo" }
+ assert_nothing_raised { @sv.show_zeros = false }
+ assert_equal(@sv.show_zeros, false)
+ end
+
+ def test_tab_selected
+ assert_raise(ArgumentError) { @sv.tab_selected = "foo" }
+ assert_nothing_raised { @sv.tab_selected = false }
+ assert_equal(@sv.tab_selected, false)
+ end
+
+ def test_top_left_cell
+ assert_raise(ArgumentError) { @sv.top_left_cell = :cell_adress }
+ assert_nothing_raised { @sv.top_left_cell = "A2" }
+ assert_equal(@sv.top_left_cell, "A2")
+ end
+
+ def test_view
+ assert_raise(ArgumentError) { @sv.view = 'view' }
+ assert_nothing_raised { @sv.view = :page_break_preview }
+ assert_equal(@sv.view, :page_break_preview)
+ end
+
+ def test_window_protection
+ assert_raise(ArgumentError) { @sv.window_protection = "foo" }
+ assert_nothing_raised { @sv.window_protection = false }
+ assert_equal(@sv.window_protection, false)
+ end
+
+ def test_workbook_view_id
+ assert_raise(ArgumentError) { @sv.workbook_view_id = "1" }
+ assert_nothing_raised { @sv.workbook_view_id = 1 }
+ assert_equal(@sv.workbook_view_id, 1)
+ end
+
+ def test_zoom_scale
+ assert_raise(ArgumentError) { @sv.zoom_scale = "50" }
+ assert_nothing_raised { @sv.zoom_scale = 50 }
+ assert_equal(@sv.zoom_scale, 50)
+ end
+
+ def test_zoom_scale_normal
+ assert_raise(ArgumentError) { @sv.zoom_scale_normal = "50" }
+ assert_nothing_raised { @sv.zoom_scale_normal = 50 }
+ assert_equal(@sv.zoom_scale_normal, 50)
+ end
+
+ def test_zoom_scale_page_layout_view
+ assert_raise(ArgumentError) { @sv.zoom_scale_page_layout_view = "50" }
+ assert_nothing_raised { @sv.zoom_scale_page_layout_view = 50 }
+ assert_equal(@sv.zoom_scale_page_layout_view, 50)
+ end
+
+ def test_zoom_scale_sheet_layout_view
+ assert_raise(ArgumentError) { @sv.zoom_scale_sheet_layout_view = "50" }
+ assert_nothing_raised { @sv.zoom_scale_sheet_layout_view = 50 }
+ assert_equal(@sv.zoom_scale_sheet_layout_view, 50)
+ end
+
+ def test_to_xml
+ p = Axlsx::Package.new
+ @ws = p.workbook.add_worksheet :name => "sheetview"
+ @ws.sheet_view do |vs|
+ vs.view = :page_break_preview
+ end
+
+ doc = Nokogiri::XML.parse(@ws.to_xml_string)
+
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@topLeftCell=''][@colorId='']
+ [@tabSelected='false'][@showWhiteSpace='false'][@showOutlineSymbols='false'][@showFormulas='false']
+ [@rightToLeft='false'][@windowProtection='false'][@showZeros='true'][@showRuler='true']
+ [@showRowColHeaders='true'][@showGridLines='true'][@defaultGridColor='true']
+ [@zoomScale='100'][@workbookViewId='0'][@zoomScaleSheetLayoutView='0'][@zoomScalePageLayoutView='0']
+ [@zoomScaleNormal='0'][@view='page_break_preview']").size)
+
+ assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@topLeftCell=''][@colorId='']
+ [@tabSelected='false'][@showWhiteSpace='false'][@showOutlineSymbols='false'][@showFormulas='false']
+ [@rightToLeft='false'][@windowProtection='false'][@showZeros='true'][@showRuler='true']
+ [@showRowColHeaders='true'][@showGridLines='true'][@defaultGridColor='true']
+ [@zoomScale='100'][@workbookViewId='0'][@zoomScaleSheetLayoutView='0'][@zoomScalePageLayoutView='0']
+ [@zoomScaleNormal='0'][@view='page_break_preview']").size)
+ end
+
+ def test_to_xml_string_show_selection
+ p = Axlsx::Package.new
+ sheet_view = p.workbook.add_worksheet(:name => "sheetview") do |ws|
+ ws.sheet_view { |sv| sv.view = :page_break_preview }
+ end.sheet_view
+ doc = Nokogiri::XML(sheet_view.to_xml_string)
+ assert_equal(1, doc.xpath('//selection[@activeCell="A1"]').size)
+ assert_equal(1, doc.xpath('//selection[@sqref="A1"]').size)
+ end
+end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 8a9d0adb..ce2873ab 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -217,13 +217,6 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@showGridLines="false"]').size, 1)
end
-
- def test_to_xml_string_show_selection
- doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@activeCell="A1"]').size, 1)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref="A1"]').size, 1)
- end
-
def test_to_xml_string_auto_fit_data
@ws.add_row [1, "two"]
doc = Nokogiri::XML(@ws.to_xml_string)