lib/axlsx/workbook/workbook.rb in axlsx-1.3.6 vs lib/axlsx/workbook/workbook.rb in axlsx-2.0.0

- old
+ new

@@ -32,10 +32,16 @@ require 'axlsx/workbook/worksheet/sheet_data.rb' require 'axlsx/workbook/worksheet/worksheet_drawing.rb' require 'axlsx/workbook/worksheet/worksheet_comments.rb' require 'axlsx/workbook/worksheet/worksheet_hyperlink' require 'axlsx/workbook/worksheet/worksheet_hyperlinks' +require 'axlsx/workbook/worksheet/break' +require 'axlsx/workbook/worksheet/row_breaks' +require 'axlsx/workbook/worksheet/col_breaks' + + + require 'axlsx/workbook/worksheet/worksheet.rb' require 'axlsx/workbook/shared_strings_table.rb' require 'axlsx/workbook/defined_name.rb' require 'axlsx/workbook/defined_names.rb' require 'axlsx/workbook/worksheet/table_style_info.rb' @@ -268,28 +274,46 @@ # The workbook relationships. This is managed automatically by the workbook # @return [Relationships] def relationships r = Relationships.new @worksheets.each do |sheet| - r << Relationship.new(WORKSHEET_R, WORKSHEET_PN % (r.size+1)) + r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN % (r.size+1)) end pivot_tables.each_with_index do |pivot_table, index| - r << Relationship.new(PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN % (index+1)) + r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN % (index+1)) end - r << Relationship.new(STYLES_R, STYLES_PN) + r << Relationship.new(self, STYLES_R, STYLES_PN) if use_shared_strings - r << Relationship.new(SHARED_STRINGS_R, SHARED_STRINGS_PN) + r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN) end r end # generates a shared string object against all cells in all worksheets. # @return [SharedStringTable] def shared_strings - SharedStringsTable.new(worksheets.collect { |ws| ws.cells }) + SharedStringsTable.new(worksheets.collect { |ws| ws.cells }, xml_space) end + # The xml:space attribute for the worksheet. + # This determines how whitespace is handled withing the document. + # The most relevant part being whitespace in the cell text. + # allowed values are :preserve and :default. Axlsx uses :preserve unless + # you explicily set this to :default. + # @return Symbol + def xml_space + @xml_space ||= :preserve + end + + # Sets the xml:space attribute for the worksheet + # @see Worksheet#xml_space + # @param [Symbol] space must be one of :preserve or :default + def xml_space=(space) + Axlsx::RestrictionValidator.validate(:xml_space, [:preserve, :default], space) + @xml_space = space; + 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) @@ -316,12 +340,11 @@ end str << '</sheets>' defined_names.to_xml_string(str) unless pivot_tables.empty? str << '<pivotCaches>' - pivot_tables.each_with_index do |pivot_table, index| - rId = "rId#{@worksheets.size + index + 1 }" - str << '<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << rId << '"/>' + pivot_tables.each do |pivot_table| + str << '<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << pivot_table.cache_definition.rId << '"/>' end str << '</pivotCaches>' end str << '</workbook>' end