lib/axlsx/workbook/workbook.rb in axlsx-1.1.8 vs lib/axlsx/workbook/workbook.rb in axlsx-1.2.0
- old
+ new
@@ -1,29 +1,42 @@
# -*- coding: utf-8 -*-
module Axlsx
-
+require 'axlsx/workbook/worksheet/auto_filter.rb'
require 'axlsx/workbook/worksheet/date_time_converter.rb'
require 'axlsx/workbook/worksheet/protected_range.rb'
+require 'axlsx/workbook/worksheet/protected_ranges.rb'
require 'axlsx/workbook/worksheet/cell.rb'
require 'axlsx/workbook/worksheet/page_margins.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/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'
+require 'axlsx/workbook/worksheet/conditional_formattings.rb'
require 'axlsx/workbook/worksheet/row.rb'
require 'axlsx/workbook/worksheet/col.rb'
+require 'axlsx/workbook/worksheet/cols.rb'
require 'axlsx/workbook/worksheet/comments.rb'
require 'axlsx/workbook/worksheet/comment.rb'
+require 'axlsx/workbook/worksheet/merged_cells.rb'
require 'axlsx/workbook/worksheet/sheet_protection.rb'
+require 'axlsx/workbook/worksheet/sheet_pr.rb'
+require 'axlsx/workbook/worksheet/dimension.rb'
+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.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.rb'
+require 'axlsx/workbook/worksheet/tables.rb'
require 'axlsx/workbook/worksheet/data_validation.rb'
+require 'axlsx/workbook/worksheet/data_validations.rb'
require 'axlsx/workbook/worksheet/sheet_view.rb'
require 'axlsx/workbook/worksheet/pane.rb'
require 'axlsx/workbook/worksheet/selection.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.
@@ -99,17 +112,26 @@
# @see Worksheet#add_table
# @see Table
# @return [SimpleTypedList]
attr_reader :tables
- # A colllection of comments associated with this workbook
- # @note The recommended way to manage comments is Worksheet#add_comment
+
+ # A collection of defined names for this workbook
+ # @note The recommended way to manage defined names is Workbook#add_defined_name
+ # @see DefinedName
+ # @return [DefinedNames]
+ def defined_names
+ @defined_names ||= DefinedNames.new
+ end
+
+ # A collection of comments associated with this workbook
+ # @note The recommended way to manage comments is WOrksheet#add_comment
# @see Worksheet#add_comment
# @see Comment
# @return [Comments]
def comments
- self.worksheets.map { |ws| ws.comments }.compact
+ worksheets.map { |sheet| sheet.comments }.compact
end
# The styles associated with this workbook
# @note The recommended way to manage styles is Styles#add_style
# @see Style#add_style
@@ -188,10 +210,18 @@
worksheet = Worksheet.new(self, options)
yield worksheet if block_given?
worksheet
end
+ # Adds a defined name to this workbook
+ # @return [DefinedName]
+ # @param [String] formula @see DefinedName
+ # @param [Hash] options @see DefinedName
+ def add_defined_name(formula, options)
+ defined_names << DefinedName.new(formula, options)
+ end
+
# The workbook relationships. This is managed automatically by the workbook
# @return [Relationships]
def relationships
r = Relationships.new
@worksheets.each do |sheet|
@@ -229,20 +259,16 @@
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << '<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">'
str << '<workbookPr date1904="' << @@date1904.to_s << '"/>'
str << '<sheets>'
@worksheets.each_with_index do |sheet, index|
- str << '<sheet name="' << sheet.name << '" sheetId="' << (index+1).to_s << '" r:id="' << sheet.rId << '"/>'
- end
- str << '</sheets>'
- str << '<definedNames>'
- @worksheets.each_with_index do |sheet, index|
- if sheet.auto_filter
- str << '<definedName name="_xlnm._FilterDatabase" localSheetId="' << index.to_s << '" hidden="1">'
- str << sheet.abs_auto_filter << '</definedName>'
+ str << '<sheet name="' << sheet.name << '" sheetId="' << (index+1).to_s << '" r:id="' << sheet.rId << '"/>'
+ if defined_name = sheet.auto_filter.defined_name
+ add_defined_name defined_name, :name => '_xlnm._FilterDatabase', :local_sheet_id => index, :hidden => 1
end
end
- str << '</definedNames>'
+ str << '</sheets>'
+ defined_names.to_xml_string(str)
str << '</workbook>'
end
end
end