diff options
| author | Randy Morgan <[email protected]> | 2012-10-21 08:10:38 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-21 08:10:38 +0900 |
| commit | 4db2f94bb9f68b70aa27ee0b685b01cae9c3b54b (patch) | |
| tree | 781aec35320cb3ab46b9633233dbe8cb92262bdf /lib | |
| parent | 51dcfe0c141096da1bc513aef8c901f3872778c7 (diff) | |
| download | caxlsx-4db2f94bb9f68b70aa27ee0b685b01cae9c3b54b.tar.gz caxlsx-4db2f94bb9f68b70aa27ee0b685b01cae9c3b54b.zip | |
Added insert_worksheet to Workbook so we can add worksheets at a specific position
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/util/simple_typed_list.rb | 20 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 17 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/col.rb | 10 |
3 files changed, 39 insertions, 8 deletions
diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index a6c11a5d..4d188ffd 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -43,16 +43,16 @@ module Axlsx def to_ary @list end - + alias :to_a :to_ary - + # Unlock the list # @return [self] def unlock @locked_at = nil self end - + # join operator # @param [Array] v the array to join # @raise [ArgumentError] if any of the values being joined are not @@ -62,7 +62,7 @@ module Axlsx v.each do |item| DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item @list << item - end + end end # Concat operator @@ -107,6 +107,18 @@ module Axlsx v end + # inserts an item at the index specfied + # @param [Integer] index + # @param [Any] v + # @raise [ArgumentError] if the index is protected by locking + # @raise [ArgumentError] if the index is not one of the allowed types + def insert(index, v) + DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v + raise ArgumentError, "Item is protected and cannot be changed" if protected? index + @list.insert(index, v) + v + end + # determines if the index is protected # @param [Integer] index def protected? index diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index a1964883..0941f0d1 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -214,6 +214,23 @@ require 'axlsx/workbook/worksheet/selection.rb' # see @use_autowidth def use_autowidth=(v=true) Axlsx::validate_boolean v; @use_autowidth = v; end + # inserts a worksheet into this workbook at the position specified. + # It the index specified is out of range, the worksheet will be added to the end of the + # worksheets collection + # @return [Worksheet] + # @param index The zero based position to insert the newly created worksheet + # @param [Hash] options Options to pass into the worksheed during initialization. + # @option options [String] name The name of the worksheet + # @option options [Hash] page_margins The page margins for the worksheet + def insert_worksheet(index=0, options={}) + worksheet = Worksheet.new(self, options) + @worksheets.delete_at(@worksheets.size - 1) + @worksheets.insert(index, worksheet) + yield worksheet if block_given? + worksheet + end + + # # Adds a worksheet to this workbook # @return [Worksheet] # @option options [String] name The name of the worksheet. diff --git a/lib/axlsx/workbook/worksheet/col.rb b/lib/axlsx/workbook/worksheet/col.rb index 596531ab..a2658724 100644 --- a/lib/axlsx/workbook/worksheet/col.rb +++ b/lib/axlsx/workbook/worksheet/col.rb @@ -23,7 +23,7 @@ module Axlsx parse_options options end - serializable_attributes :collapsed, :hidden, :outline_level, :phonetic, :style, :width, :min, :max + serializable_attributes :collapsed, :hidden, :outline_level, :phonetic, :style, :width, :min, :max, :best_fit, :custom_width # First column affected by this 'column info' record. # @return [Integer] @@ -38,7 +38,8 @@ module Axlsx # 'Best fit' means that when numbers are typed into a cell contained in a 'best fit' column, the column width should # automatically resize to display the number. [Note: In best fit cases, column width must not be made smaller, only larger. end note] # @return [Boolean] - attr_reader :bestFit + attr_reader :best_fit + alias :bestFit :best_fit # Flag indicating if the outlining of the affected column(s) is in the collapsed state. # @return [Boolean] @@ -66,7 +67,8 @@ module Axlsx attr_reader :width # @return [Boolean] - attr_reader :customWidth + attr_reader :custom_width + alias :customWidth :custom_width # @see Col#collapsed def collapsed=(v) @@ -103,7 +105,7 @@ module Axlsx # @see Col#width def width=(v) Axlsx.validate_unsigned_numeric(v) unless v == nil - @customWidth = @bestFit = v != nil + @custom_width = @best_fit = v != nil @width = v end |
