lib/axlsx/workbook/workbook.rb in axlsx-1.3.1 vs lib/axlsx/workbook/workbook.rb in axlsx-1.3.2

- old
+ new

@@ -9,10 +9,11 @@ require 'axlsx/workbook/worksheet/page_margins.rb' require 'axlsx/workbook/worksheet/page_set_up_pr.rb' require 'axlsx/workbook/worksheet/page_setup.rb' require 'axlsx/workbook/worksheet/print_options.rb' require 'axlsx/workbook/worksheet/cfvo.rb' +require 'axlsx/workbook/worksheet/cfvos.rb' require 'axlsx/workbook/worksheet/color_scale.rb' require 'axlsx/workbook/worksheet/data_bar.rb' require 'axlsx/workbook/worksheet/icon_set.rb' require 'axlsx/workbook/worksheet/conditional_formatting.rb' require 'axlsx/workbook/worksheet/conditional_formatting_rule.rb' @@ -150,19 +151,27 @@ # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used. @@date1904 = false + # A quick helper to retrive a worksheet by name + # @param [String] name The name of the sheet you are looking for + # @return [Worksheet] The sheet found, or nil + def sheet_by_name(name) + index = @worksheets.index { |sheet| sheet.name == name } + @worksheets[index] if index + end + # lets come back to this later when we are ready for parsing. #def self.parse entry # io = entry.get_input_stream # w = self.new # w.parser_xml = Nokogiri::XML(io.read) # w.parse_string :date1904, "//xmlns:workbookPr/@date1904" # w #end - + # Creates a new Workbook # The recomended way to work with workbooks is via Package#workbook # @option options [Boolean] date1904. If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false. def initialize(options={}) @styles = Styles.new @@ -204,9 +213,26 @@ def use_autowidth() @use_autowidth; end # 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. # @option options [Hash] page_margins The page margins for the worksheet. # @see Worksheet#initialize