diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/drawing/chart.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/rels/relationships.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx/util/constants.rb | 11 | ||||
| -rw-r--r-- | lib/axlsx/util/validators.rb | 9 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook_view.rb | 8 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cfvos.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cols.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/outline_pr.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/protected_ranges.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/tables.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet_drawing.rb | 20 |
14 files changed, 59 insertions, 31 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index de87b91a..d3a7e9ff 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -56,7 +56,7 @@ module Axlsx # Indicates that colors should be varied by datum # @return [Boolean] attr_reader :vary_colors - + # Configures the vary_colors options for this chart # @param [Boolean] v The value to set def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end @@ -129,6 +129,8 @@ module Axlsx end # The size of the Title object of the chart. + # @param [String] v The size for the title object + # @see Title def title_size=(v) @title.text_size = v unless v.to_s.empty? end diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 5a418df0..e8d0ebd7 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -115,7 +115,6 @@ module Axlsx end # providing access to the anchor's width attribute - # @param [Integer] v # @see OneCellAnchor.width def width return unless @anchor.is_a?(OneCellAnchor) @@ -129,7 +128,6 @@ module Axlsx end # providing access to update the anchor's height attribute - # @param [Integer] v # @see OneCellAnchor.width # @note this is a noop if you are using a TwoCellAnchor def height diff --git a/lib/axlsx/rels/relationships.rb b/lib/axlsx/rels/relationships.rb index b855abcd..5d07f612 100644 --- a/lib/axlsx/rels/relationships.rb +++ b/lib/axlsx/rels/relationships.rb @@ -10,14 +10,17 @@ require 'axlsx/rels/relationship.rb' def initialize super Relationship end - + # The relationship instance for the given source object, or nil if none exists. # @see Relationship#source_obj # @return [Relationship] def for(source_obj) find{ |rel| rel.source_obj == source_obj } end - + + # serialize relationships + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<?xml version="1.0" encoding="UTF-8"?>' str << ('<Relationships xmlns="' << RELS_R << '">') diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index 64bae270..aa8eb626 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -385,13 +385,16 @@ module Axlsx # @see http://www.codetable.net/asciikeycodes pattern = "\x0-\x08\x0B\x0C\x0E-\x1F" pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern - + # The regular expression used to remove control characters from worksheets CONTROL_CHARS = pattern.freeze - + + # ISO 8601 date recognition ISO_8601_REGEX = /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/.freeze - + + # FLOAT recognition FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/.freeze - + + # Numeric recognition NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 2b4afd8d..71652ef2 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -56,13 +56,13 @@ module Axlsx raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v) end v_class = v.is_a?(Class) ? v : v.class - Array(types).each do |t| + Array(types).each do |t| return if v_class <= t end raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) end end - + # Requires that the value can be converted to an integer # @para, [Any] v the value to validate @@ -78,7 +78,8 @@ module Axlsx def self.validate_angle(v) raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000) end - + + # Validates an unsigned intger UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 } # Requires that the value is a Integer and is greater or equal to 0 @@ -148,7 +149,7 @@ module Axlsx RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v end - # validates cell style family which must be between 1 and 5 + # validates cell style family which must be between 1 and 5 def self.validate_family(v) RestrictionValidator.validate "cell run style family", 1..5, v end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 4ba44adb..7572e51f 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -280,6 +280,10 @@ require 'axlsx/workbook/worksheet/selection.rb' worksheet end + # Adds a new WorkbookView + # @return WorkbookViews + # @option options [Hash] options passed into the added WorkbookView + # @see WorkbookView#initialize def add_view(options={}) views << WorkbookView.new(options) end diff --git a/lib/axlsx/workbook/workbook_view.rb b/lib/axlsx/workbook/workbook_view.rb index 11eae571..e0d38cae 100644 --- a/lib/axlsx/workbook/workbook_view.rb +++ b/lib/axlsx/workbook/workbook_view.rb @@ -33,7 +33,7 @@ module Axlsx # Creates a new BookView object - # @params [Hash] options A hash of key/value pairs that will be mapped to this instances attributes. + # @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes. # @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible. # @option [Boolean] minimized Specifies a boolean value that indicates whether the workbook window is minimized. # @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface. @@ -41,7 +41,7 @@ module Axlsx # @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface. # @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar. # @option [Integer] first_sheet Specifies the index to the first sheet in this book view. - # @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view. + # @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view. # @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips. # @option [Integer] y_window Specifies the Y coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips. # @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips. @@ -68,7 +68,9 @@ module Axlsx :show_sheet_tabs, :auto_filter_date_grouping - + # Serialize the WorkbookView + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<workbookView ' serialized_attributes str diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 777b7812..fb10ad36 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -65,6 +65,7 @@ module Axlsx :shadow, :condense, :extend, :u, :vertAlign, :sz, :color, :scheme].freeze + # An array of valid cell types CELL_TYPES = [:date, :time, :float, :integer, :richtext, :string, :boolean, :iso_8601, :text].freeze @@ -79,7 +80,7 @@ module Axlsx # @return [Row] attr_reader :row - # The cell's data type. Currently only six types are supported, :date, :time, :float, :integer, :string and :boolean. + # The cell's data type. # Changing the type for a cell will recast the value into that type. If no type option is specified in the constructor, the type is # automatically determed. # @see Cell#cell_type_from_value @@ -348,6 +349,8 @@ module Axlsx # returns the name of the cell attr_reader :name + # Attempts to determine the correct width for this cell's content + # @return [Float] def autowidth return if is_formula? || value.nil? if contains_rich_text? diff --git a/lib/axlsx/workbook/worksheet/cfvos.rb b/lib/axlsx/workbook/worksheet/cfvos.rb index 0b5a21b3..eb44f9d8 100644 --- a/lib/axlsx/workbook/worksheet/cfvos.rb +++ b/lib/axlsx/workbook/worksheet/cfvos.rb @@ -8,6 +8,9 @@ module Axlsx super(Cfvo) end + # Serialize the Cfvo object + # @param [String] str + # @return [String] def to_xml_string(str='') each { |cfvo| cfvo.to_xml_string(str) } end diff --git a/lib/axlsx/workbook/worksheet/cols.rb b/lib/axlsx/workbook/worksheet/cols.rb index d4595f29..c0704343 100644 --- a/lib/axlsx/workbook/worksheet/cols.rb +++ b/lib/axlsx/workbook/worksheet/cols.rb @@ -1,6 +1,6 @@ module Axlsx - # The cols class manages the col object used to manage column widths. + # The cols class manages the col object used to manage column widths. # This is where the magic happens with autowidth class Cols < SimpleTypedList @@ -10,11 +10,14 @@ module Axlsx @worksheet = worksheet end + # Serialize the Cols object + # @param [String] str + # @return [String] def to_xml_string(str = '') return if empty? str << '<cols>' each { |item| item.to_xml_string(str) } - str << '</cols>' + str << '</cols>' end end end diff --git a/lib/axlsx/workbook/worksheet/outline_pr.rb b/lib/axlsx/workbook/worksheet/outline_pr.rb index ae9ccf38..f25ef4fa 100644 --- a/lib/axlsx/workbook/worksheet/outline_pr.rb +++ b/lib/axlsx/workbook/worksheet/outline_pr.rb @@ -18,7 +18,7 @@ module Axlsx :apply_styles # Creates a new OutlinePr object - # @param [Worksheet] worksheet The worksheet that owns this OutlinePr object + # @param [Hash] options used to create the outline_pr def initialize(options = {}) parse_options options end diff --git a/lib/axlsx/workbook/worksheet/protected_ranges.rb b/lib/axlsx/workbook/worksheet/protected_ranges.rb index 46a2546b..d274cf80 100644 --- a/lib/axlsx/workbook/worksheet/protected_ranges.rb +++ b/lib/axlsx/workbook/worksheet/protected_ranges.rb @@ -24,11 +24,14 @@ module Axlsx last end + # Serializes the protected ranges + # @param [String] str + # @return [String] def to_xml_string(str = '') return if empty? str << '<protectedRanges>' each { |range| range.to_xml_string(str) } - str << '</protectedRanges>' + str << '</protectedRanges>' end end end diff --git a/lib/axlsx/workbook/worksheet/tables.rb b/lib/axlsx/workbook/worksheet/tables.rb index 624c96c4..d033212c 100644 --- a/lib/axlsx/workbook/worksheet/tables.rb +++ b/lib/axlsx/workbook/worksheet/tables.rb @@ -20,6 +20,9 @@ module Axlsx map{ |table| Relationship.new(table, TABLE_R, "../#{table.pn}") } end + # renders the tables xml + # @param [String] str + # @return [String] def to_xml_string(str = "") return if empty? str << "<tableParts count='#{size}'>" diff --git a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb index 08cad1f7..ae03ac0f 100644 --- a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +++ b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb @@ -1,5 +1,5 @@ module Axlsx - + # This is a utility class for serialing the drawing node in a # worksheet. Drawing objects have their own serialization that exports # a drawing document. This is only for the single node in the @@ -17,7 +17,7 @@ module Axlsx attr_reader :worksheet attr_reader :drawing - + # adds a chart to the drawing object # @param [Class] chart_type The type of chart to add # @param [Hash] options Options to pass on to the drawing and chart @@ -26,17 +26,17 @@ module Axlsx @drawing ||= Drawing.new worksheet drawing.add_chart(chart_type, options) end - + # adds an image to the drawing object - # @param [Hash] options Options to pass on to the drawing and image + # @param [Hash] options Options to pass on to the drawing and image # @see Worksheet#add_image def add_image(options) - @drawing ||= Drawing.new worksheet + @drawing ||= Drawing.new(worksheet) drawing.add_image(options) - end - + end + # helper method to tell us if the drawing has something in it or not - # @return [Boolean] + # @return [Boolean] def has_drawing? @drawing.is_a? Drawing end @@ -45,13 +45,13 @@ module Axlsx # @return [Relationship] def relationship return unless has_drawing? - Relationship.new(self, DRAWING_R, "../#{drawing.pn}") + Relationship.new(self, DRAWING_R, "../#{drawing.pn}") end # Serialize the drawing for the worksheet # @param [String] str def to_xml_string(str = '') - return unless has_drawing? + return unless has_drawing? str << "<drawing r:id='#{relationship.Id}'/>" end end |
