lib/axlsx/workbook/workbook.rb in axlsx-1.0.16 vs lib/axlsx/workbook/workbook.rb in axlsx-1.0.17

- old
+ new

@@ -2,10 +2,11 @@ module Axlsx require 'axlsx/workbook/worksheet/cell.rb' require 'axlsx/workbook/worksheet/row.rb' require 'axlsx/workbook/worksheet/worksheet.rb' +require 'axlsx/workbook/shared_strings_table.rb' # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles. # The following parts of the Office Open XML spreadsheet specification are not implimented in this version. # # bookViews @@ -28,10 +29,23 @@ # workbookPr* # # *workbookPr is only supported to the extend of date1904 class Workbook + # When true, the Package will be generated with a shared string table. This may be required by some OOXML processors that do not + # adhere to the ECMA specification that dictates string may be inline in the sheet. + # Using this option will increase the time required to serialize the document as every string in every cell must be analzed and referenced. + # @return [Boolean] + attr_reader :use_shared_strings + + # @see use_shared_strings + def use_shared_strings=(v) + Axlsx::validate_boolean(v) + @use_shared_strings = v + end + + # A collection of worksheets associated with this workbook. # @note The recommended way to manage worksheets is add_worksheet # @see Workbook#add_worksheet # @see Worksheet # @return [SimpleTypedList] @@ -80,13 +94,12 @@ # w.parse_string :date1904, "//xmlns:workbookPr/@date1904" # w #end # Creates a new Workbook - # - # @option options [Boolean] date1904. If this is not specified, we try to determine if the platform is bsd/darwin and set date1904 to true automatically. - # + # The recomended way to work with workbooks is via Package#workbook + # @option options [Boolean] date1904. If this is not specified, we try to determine if the platform is bsd/darwin and set date1904 to true automatically. def initialize(options={}) @styles = Styles.new @worksheets = SimpleTypedList.new Worksheet @drawings = SimpleTypedList.new Drawing @charts = SimpleTypedList.new Chart @@ -134,10 +147,19 @@ r = Relationships.new @worksheets.each do |sheet| r << Relationship.new(WORKSHEET_R, WORKSHEET_PN % (r.size+1)) end r << Relationship.new(STYLES_R, STYLES_PN) + if use_shared_strings + r << Relationship.new(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 }) 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.