diff options
| author | Randy Morgan <[email protected]> | 2011-11-27 21:34:48 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-27 21:34:48 +0900 |
| commit | 407b884ef349d6dec12f50006ea6268c96205a83 (patch) | |
| tree | 907f0345127370a69b3c9626d13d72853a679c3a /lib | |
| parent | 4d16bfc43780e5d3f7368625700b583e3e98217a (diff) | |
| download | caxlsx-407b884ef349d6dec12f50006ea6268c96205a83.tar.gz caxlsx-407b884ef349d6dec12f50006ea6268c96205a83.zip | |
adding yields for package workbook, workbook styles and cols collection on worksheet to make charting easier.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/package.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/util/simple_typed_list.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/version.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/row.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 28 |
6 files changed, 39 insertions, 9 deletions
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 921646da..5c46776c 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -36,6 +36,8 @@ module Axlsx # wb = Package.new().workbook = Workbook.new def workbook @workbook || @workbook = Workbook.new + yield @workbook if block_given? + @workbook end # @see workbook diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index 53b7b994..78d31dc7 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -38,6 +38,10 @@ module Axlsx @locked_at = @list.size self end + + def to_ary + @list + end # Unlock the list # @return [self] @@ -152,4 +156,5 @@ module Axlsx end end + end diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index 92993f79..b0681d8c 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,4 +1,4 @@ module Axlsx # version - VERSION="1.0.10" + VERSION="1.0.10a" end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 68f9f8b8..65020e71 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -63,8 +63,10 @@ require 'axlsx/workbook/worksheet/worksheet.rb' # @see Style#add_style # @see Style # @return [Styles] - attr_reader :styles - + def styles + yield @styles if block_given? + @styles + end # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used. diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb index 442dcf7b..0e5333b9 100644 --- a/lib/axlsx/workbook/worksheet/row.rb +++ b/lib/axlsx/workbook/worksheet/row.rb @@ -62,6 +62,10 @@ module Axlsx end end + def to_ary + @cells.to_ary + end + private # assigns the owning worksheet for this row @@ -73,6 +77,7 @@ module Axlsx worksheet.send(:update_auto_fit_data, self.cells) end + # Converts values, types, and style options into cells and associates them with this row. # A new cell is created for each item in the values array. # If value option is defined and is a symbol it is applied to all the cells created. diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 65f620e4..285e4307 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -39,6 +39,7 @@ module Axlsx @auto_fit_data = [] self.name = options[:name] || "Sheet" + (index+1).to_s @magick_draw = Magick::Draw.new + @cols = SimpleTypedList.new Cell end # The name of the worksheet @@ -90,16 +91,25 @@ module Axlsx end # Set the style for cells in a specific row - # @param [Integer] index the index of the row + # @param [Integer] index or range of indexes in the table # @param [Integer] the cellXfs index # @option options [Integer] col_offset only cells after this column will be updated. # @note You can also specify the style in the add_row call # @see Worksheet#add_row # @see README.md for an example def row_style(index, style, options={}) - raise ArgumentError, "Invalid Row Index" unless index < @rows.size offset = options.delete(:col_offset) || 0 - @rows[index].cells[(offset..-1)].each { |c| c.style = style } + rs = @rows[index] + if rs.is_a?(Array) + rs.each { |r| r.cells[(offset..-1)].each { |c| c.style = style } } + else + rs.cells[(offset..-1)].each { |c| c.style = style } + end + end + + # returns the sheet data as columnw + def cols + @rows.transpose end @@ -111,11 +121,17 @@ module Axlsx # @see Worksheet#add_row # @see README.md for an example def col_style(index, style, options={}) - raise ArgumentError, "Invalid Column Index" unless index < @rows.first.cells.size offset = options.delete(:row_offset) || 0 - @rows[(offset..-1)].each { |r| r.cells[index].style = style } + @rows[(offset..-1)].each do |r| + cells = r.cells[index] + if cells.is_a?(Array) + cells.each { |c| c.style = style } + else + cells.style = style + end + end end - + # Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details. # @param [Class] chart_type # @option options [Array] start_at |
