lib/axlsx/workbook/workbook.rb in axlsx-1.0.10 vs lib/axlsx/workbook/workbook.rb in axlsx-1.0.11

- old
+ new

@@ -69,11 +69,20 @@ end # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used. @@date1904 = false - + + # 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 # @option options [Boolean] date1904 def initialize(options={}) @styles = Styles.new @worksheets = SimpleTypedList.new Worksheet @@ -116,9 +125,20 @@ @worksheets.each do |sheet| r << Relationship.new(WORKSHEET_R, WORKSHEET_PN % (r.size+1)) end r << Relationship.new(STYLES_R, STYLES_PN) r + end + + # returns a range of cells in a worksheet + # @param [String] cell_def The excel style reference defining the worksheet and cells. The range must specify the sheet to + # retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell. + # @return [Cell, Array] + def [](cell_def) + sheet_name = cell_def.split('!')[0] if cell_def.match('!') + worksheet = self.worksheets.select { |s| s.name == sheet_name }.first + raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet) + worksheet[cell_def.gsub(/.+!/,"")] end # Serializes the workbook document # @return [String] def to_xml()