diff options
| author | Randy Morgan <[email protected]> | 2012-04-03 08:38:37 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-03 08:38:37 +0900 |
| commit | 7df172a8f3815e1291f41098705650afd5a2b41d (patch) | |
| tree | 35f25742e09201a50c595ac0250c000a3c272c65 /lib | |
| parent | 6f998ecb098c2a3a5eabc6f8ef44a0f25632f2c8 (diff) | |
| download | caxlsx-7df172a8f3815e1291f41098705650afd5a2b41d.tar.gz caxlsx-7df172a8f3815e1291f41098705650afd5a2b41d.zip | |
pre-release cleanup
Diffstat (limited to 'lib')
57 files changed, 202 insertions, 213 deletions
diff --git a/lib/axlsx/content_type/content_type.rb b/lib/axlsx/content_type/content_type.rb index 6b4facd0..003991c7 100644 --- a/lib/axlsx/content_type/content_type.rb +++ b/lib/axlsx/content_type/content_type.rb @@ -10,8 +10,9 @@ module Axlsx super [Override, Default] end - # serialize the content types - # @return [String] str + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<Types xmlns="' << XML_NS_T << '">' diff --git a/lib/axlsx/content_type/default.rb b/lib/axlsx/content_type/default.rb index 2ff24527..c7cedd14 100644 --- a/lib/axlsx/content_type/default.rb +++ b/lib/axlsx/content_type/default.rb @@ -28,6 +28,9 @@ module Axlsx # @see Axlsx#validate_content_type def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<Default ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') diff --git a/lib/axlsx/content_type/override.rb b/lib/axlsx/content_type/override.rb index 665a538a..eadf8e78 100644 --- a/lib/axlsx/content_type/override.rb +++ b/lib/axlsx/content_type/override.rb @@ -29,7 +29,9 @@ module Axlsx # @see Axlsx#validate_content_type def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end - # Serialize the Override + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<Override ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb index e686314c..9206e848 100644 --- a/lib/axlsx/drawing/axis.rb +++ b/lib/axlsx/drawing/axis.rb @@ -84,6 +84,9 @@ module Axlsx def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:axId val="' << @axId.to_s << '"/>' @scaling.to_xml_string str diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb index f623ab9f..abed702b 100644 --- a/lib/axlsx/drawing/bar_3D_chart.rb +++ b/lib/axlsx/drawing/bar_3D_chart.rb @@ -105,6 +105,9 @@ module Axlsx @shape = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do |str_inner| str_inner << '<c:bar3DChart>' diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb index 65cd87d9..86ae6367 100644 --- a/lib/axlsx/drawing/bar_series.rb +++ b/lib/axlsx/drawing/bar_series.rb @@ -40,6 +40,9 @@ module Axlsx @shape = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do |str_inner| @labels.to_xml_string(str_inner) unless @labels.nil? diff --git a/lib/axlsx/drawing/cat_axis.rb b/lib/axlsx/drawing/cat_axis.rb index 66f21943..a961d736 100644 --- a/lib/axlsx/drawing/cat_axis.rb +++ b/lib/axlsx/drawing/cat_axis.rb @@ -47,7 +47,9 @@ module Axlsx # must be between a string between 0 and 1000 def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:catAx>' super(str) diff --git a/lib/axlsx/drawing/cat_axis_data.rb b/lib/axlsx/drawing/cat_axis_data.rb index ced5a305..30df1132 100644 --- a/lib/axlsx/drawing/cat_axis_data.rb +++ b/lib/axlsx/drawing/cat_axis_data.rb @@ -11,7 +11,9 @@ module Axlsx data.each { |i| @list << i } if data.is_a?(SimpleTypedList) end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:cat>' str << '<c:strRef>' diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 65140d66..62bff861 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -113,7 +113,9 @@ module Axlsx @series.last end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '">' diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb index d9241f29..1267d22e 100644 --- a/lib/axlsx/drawing/drawing.rb +++ b/lib/axlsx/drawing/drawing.rb @@ -138,6 +138,9 @@ module Axlsx r end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '" xmlns:c="' << XML_NS_C << '">' diff --git a/lib/axlsx/drawing/graphic_frame.rb b/lib/axlsx/drawing/graphic_frame.rb index d123e58a..6466a656 100644 --- a/lib/axlsx/drawing/graphic_frame.rb +++ b/lib/axlsx/drawing/graphic_frame.rb @@ -28,6 +28,9 @@ module Axlsx "rId#{@anchor.index+1}" end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<xdr:graphicFrame>' str << '<xdr:nvGraphicFramePr>' diff --git a/lib/axlsx/drawing/hyperlink.rb b/lib/axlsx/drawing/hyperlink.rb index ae217f31..6caebb6e 100644 --- a/lib/axlsx/drawing/hyperlink.rb +++ b/lib/axlsx/drawing/hyperlink.rb @@ -73,6 +73,9 @@ module Axlsx end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R }) h.delete('href') diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb index 74c10850..0f8a07f8 100644 --- a/lib/axlsx/drawing/line_3D_chart.rb +++ b/lib/axlsx/drawing/line_3D_chart.rb @@ -85,6 +85,9 @@ module Axlsx @gapDepth=(v) end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do |str_inner| str_inner << '<c:line3DChart>' diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index 136408dd..ac3840f1 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -25,6 +25,9 @@ module Axlsx @data = ValAxisData.new(options[:data]) unless options[:data].nil? end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do @labels.to_xml_string(str) unless @labels.nil? diff --git a/lib/axlsx/drawing/marker.rb b/lib/axlsx/drawing/marker.rb index 985cf321..8da9477e 100644 --- a/lib/axlsx/drawing/marker.rb +++ b/lib/axlsx/drawing/marker.rb @@ -50,6 +50,9 @@ module Axlsx self.row = row end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') [:col, :colOff, :row, :rowOff].each do |k| str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>' diff --git a/lib/axlsx/drawing/named_axis_data.rb b/lib/axlsx/drawing/named_axis_data.rb index 952dc10e..218057ed 100644 --- a/lib/axlsx/drawing/named_axis_data.rb +++ b/lib/axlsx/drawing/named_axis_data.rb @@ -1,14 +1,20 @@ # encoding: UTF-8 +# TODO: review cat, val and named access data to extend this and reduce replicated code. module Axlsx # The ValAxisData class manages the values for a chart value series. class NamedAxisData < CatAxisData + # creates a new NamedAxisData Object + # @param [String] name The serialized node name for the axis data object + # @param [Array] The data to associate with the axis data object def initialize(name, data=[]) super(data) @name = name end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:' << @name.to_s << '>' str << '<c:numRef>' diff --git a/lib/axlsx/drawing/one_cell_anchor.rb b/lib/axlsx/drawing/one_cell_anchor.rb index fd33892c..9a202cc1 100644 --- a/lib/axlsx/drawing/one_cell_anchor.rb +++ b/lib/axlsx/drawing/one_cell_anchor.rb @@ -62,6 +62,9 @@ module Axlsx end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<xdr:oneCellAnchor>' str << '<xdr:from>' diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 733dc1df..e5e005fa 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -144,6 +144,9 @@ module Axlsx @anchor.from.row = y end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<xdr:pic>' str << '<xdr:nvPicPr>' diff --git a/lib/axlsx/drawing/picture_locking.rb b/lib/axlsx/drawing/picture_locking.rb index 867e32b4..0d6f4e54 100644 --- a/lib/axlsx/drawing/picture_locking.rb +++ b/lib/axlsx/drawing/picture_locking.rb @@ -63,6 +63,9 @@ module Axlsx # @see noChangeShapeType def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<a:picLocks ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') diff --git a/lib/axlsx/drawing/pie_3D_chart.rb b/lib/axlsx/drawing/pie_3D_chart.rb index 67ae791b..fea89d0e 100644 --- a/lib/axlsx/drawing/pie_3D_chart.rb +++ b/lib/axlsx/drawing/pie_3D_chart.rb @@ -28,6 +28,9 @@ module Axlsx @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options)) end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do |str_inner| str_inner << '<c:pie3DChart>' diff --git a/lib/axlsx/drawing/pie_series.rb b/lib/axlsx/drawing/pie_series.rb index bf61c9ab..0deac1be 100644 --- a/lib/axlsx/drawing/pie_series.rb +++ b/lib/axlsx/drawing/pie_series.rb @@ -1,5 +1,6 @@ # encoding: UTF-8 module Axlsx + # A PieSeries defines the data and labels and explosion for pie charts series. # @note The recommended way to manage series is to use Chart#add_series # @see Worksheet#add_chart @@ -34,6 +35,9 @@ module Axlsx # @see explosion def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do |str_inner| str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil? diff --git a/lib/axlsx/drawing/scaling.rb b/lib/axlsx/drawing/scaling.rb index af9cf2aa..29333bc7 100644 --- a/lib/axlsx/drawing/scaling.rb +++ b/lib/axlsx/drawing/scaling.rb @@ -44,6 +44,9 @@ module Axlsx # @see min def min=(v) DataTypeValidator.validate "Scaling.min", Float, v; @min = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:scaling>' str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil? diff --git a/lib/axlsx/drawing/scatter_chart.rb b/lib/axlsx/drawing/scatter_chart.rb index d8d7bb6d..1495a907 100644 --- a/lib/axlsx/drawing/scatter_chart.rb +++ b/lib/axlsx/drawing/scatter_chart.rb @@ -1,6 +1,15 @@ # encoding: UTF-8 module Axlsx + + # The ScatterChart allows you to insert a scatter chart into your worksheet + # @see Worksheet#add_chart + # @see Chart#add_series + # @see README for an example class ScatterChart < Chart + + # The Style for the scatter chart + # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker + # return [Symbol] attr_reader :scatterStyle # the x value axis @@ -11,6 +20,7 @@ module Axlsx # @return [ValAxis] attr_reader :yValAxis + # Creates a new scatter chart def initialize(frame, options={}) @scatterStyle = :lineMarker @xValAxId = rand(8 ** 8) @@ -19,8 +29,20 @@ module Axlsx @yValAxis = ValAxis.new(@yValAxId, @xValAxId) super(frame, options) @series_type = ScatterSeries + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + end + + # see #scatterStyle + def scatterStyle=(v) + Axlsx.validate_scatter_style(v) + @scatterStyle = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super do |str| str << '<c:scatterChart>' diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb index 03b2cbdd..2469e0bf 100644 --- a/lib/axlsx/drawing/scatter_series.rb +++ b/lib/axlsx/drawing/scatter_series.rb @@ -1,6 +1,13 @@ # encoding: UTF-8 module Axlsx + + # A ScatterSeries defines the x and y position of data in the chart + # @note The recommended way to manage series is to use Chart#add_series + # @see Worksheet#add_chart + # @see Chart#add_series + # @see examples/example.rb class ScatterSeries < Series + # The x data for this series. # @return [NamedAxisData] attr_reader :xData @@ -9,6 +16,7 @@ module Axlsx # @return [NamedAxisData] attr_reader :yData + # Creates a new ScatterSeries def initialize(chart, options={}) @xData, @yData = nil super(chart, options) @@ -17,6 +25,9 @@ module Axlsx @yData = NamedAxisData.new("yVal", options[:yData]) unless options[:yData].nil? end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') super(str) do |inner_str| @xData.to_xml_string(inner_str) unless @xData.nil? diff --git a/lib/axlsx/drawing/ser_axis.rb b/lib/axlsx/drawing/ser_axis.rb index fdc0d43d..703786e5 100644 --- a/lib/axlsx/drawing/ser_axis.rb +++ b/lib/axlsx/drawing/ser_axis.rb @@ -30,6 +30,9 @@ module Axlsx # @see tickMarkSkip def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:serAx>' super(str) diff --git a/lib/axlsx/drawing/series.rb b/lib/axlsx/drawing/series.rb index 9ab2db13..798919b5 100644 --- a/lib/axlsx/drawing/series.rb +++ b/lib/axlsx/drawing/series.rb @@ -55,6 +55,9 @@ module Axlsx # assigns the chart for this series def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:ser>' str << '<c:idx val="' << index.to_s << '"/>' diff --git a/lib/axlsx/drawing/series_title.rb b/lib/axlsx/drawing/series_title.rb index 39ec10d5..658be425 100644 --- a/lib/axlsx/drawing/series_title.rb +++ b/lib/axlsx/drawing/series_title.rb @@ -3,6 +3,9 @@ module Axlsx # A series title is a Title with a slightly different serialization than chart titles. class SeriesTitle < Title + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:tx>' str << '<c:strRef>' diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb index a9c253c8..a85d8e11 100644 --- a/lib/axlsx/drawing/title.rb +++ b/lib/axlsx/drawing/title.rb @@ -39,6 +39,9 @@ module Axlsx #def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end #def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:title>' unless @text.empty? diff --git a/lib/axlsx/drawing/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb index cfa102ae..b496bd8a 100644 --- a/lib/axlsx/drawing/two_cell_anchor.rb +++ b/lib/axlsx/drawing/two_cell_anchor.rb @@ -55,6 +55,9 @@ module Axlsx @drawing.anchors.index(self) end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<xdr:twoCellAnchor>' str << '<xdr:from>' diff --git a/lib/axlsx/drawing/val_axis.rb b/lib/axlsx/drawing/val_axis.rb index f2675733..6e55c8ea 100644 --- a/lib/axlsx/drawing/val_axis.rb +++ b/lib/axlsx/drawing/val_axis.rb @@ -22,6 +22,9 @@ module Axlsx # @see crossBetween def crossBetween=(v) RestrictionValidator.validate "ValAxis.crossBetween", [:between, :midCat], v; @crossBetween = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:valAx>' super(str) diff --git a/lib/axlsx/drawing/val_axis_data.rb b/lib/axlsx/drawing/val_axis_data.rb index c28e8a58..61044cd6 100644 --- a/lib/axlsx/drawing/val_axis_data.rb +++ b/lib/axlsx/drawing/val_axis_data.rb @@ -3,6 +3,9 @@ module Axlsx # The ValAxisData class manages the values for a chart value series. class ValAxisData < CatAxisData + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:val>' str << '<c:numRef>' diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb index c2af0953..1090f4a7 100644 --- a/lib/axlsx/drawing/view_3D.rb +++ b/lib/axlsx/drawing/view_3D.rb @@ -70,6 +70,9 @@ module Axlsx def perspective=(v) DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<c:view3D>' str << '<c:rotX val="' << @rotX.to_s << '"/>' unless @rotX.nil? diff --git a/lib/axlsx/stylesheet/border.rb b/lib/axlsx/stylesheet/border.rb index 99bd410a..d23e5476 100644 --- a/lib/axlsx/stylesheet/border.rb +++ b/lib/axlsx/stylesheet/border.rb @@ -42,6 +42,9 @@ module Axlsx # @see outline def outline=(v) Axlsx::validate_boolean v; @outline = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<border ' h = self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k } @@ -55,16 +58,5 @@ module Axlsx str << '</border>' end - # Serializes the border element - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - def to_xml(xml) - xml.border(self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }) { - [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k| - @prs.select { |pr| pr.name == k }.each do |part| - part.to_xml(xml) - end - end - } - end end end diff --git a/lib/axlsx/stylesheet/border_pr.rb b/lib/axlsx/stylesheet/border_pr.rb index b15e3918..eb1ecf4b 100644 --- a/lib/axlsx/stylesheet/border_pr.rb +++ b/lib/axlsx/stylesheet/border_pr.rb @@ -57,19 +57,14 @@ module Axlsx # @see style def style=(v) RestrictionValidator.validate "BorderPr.style", [:none, :thin, :medium, :dashed, :dotted, :thick, :double, :hair, :mediumDashed, :dashDot, :mediumDashDot, :dashDotDot, :mediumDashDotDot, :slantDashDot], v; @style = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<' << @name.to_s << ' style="' << @style.to_s << '">' @color.to_xml_string(str) if @color.is_a?(Color) str << '</' << @name.to_s << '>' end - # Serializes the border part - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.send(@name, :style => @style) { - @color.to_xml(xml) if @color.is_a? Color - } - end end end diff --git a/lib/axlsx/stylesheet/cell_alignment.rb b/lib/axlsx/stylesheet/cell_alignment.rb index 50b0e2d4..a38e3829 100644 --- a/lib/axlsx/stylesheet/cell_alignment.rb +++ b/lib/axlsx/stylesheet/cell_alignment.rb @@ -95,17 +95,14 @@ module Axlsx # @see readingOrder def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<alignment ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') str << '/>' end - # Serializes the cell alignment - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.alignment(self.instance_values) - end end end diff --git a/lib/axlsx/stylesheet/cell_protection.rb b/lib/axlsx/stylesheet/cell_protection.rb index b874b214..4309b0e8 100644 --- a/lib/axlsx/stylesheet/cell_protection.rb +++ b/lib/axlsx/stylesheet/cell_protection.rb @@ -27,17 +27,14 @@ module Axlsx # @see locked def locked=(v) Axlsx::validate_boolean v; @locked = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<protection ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') str << '/>' end - # Serializes the cell protection - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.protection(self.instance_values) - end end end diff --git a/lib/axlsx/stylesheet/cell_style.rb b/lib/axlsx/stylesheet/cell_style.rb index 22694ae1..ed3aeda9 100644 --- a/lib/axlsx/stylesheet/cell_style.rb +++ b/lib/axlsx/stylesheet/cell_style.rb @@ -55,19 +55,15 @@ module Axlsx # @see customBuiltin def customBuiltin=(v) Axlsx::validate_boolean v; @customBuiltin = v end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<cellStyle ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') str << '/>' end - # Serializes the cell style - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.cellStyle(self.instance_values) - end end end diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb index daedc9ed..78171607 100644 --- a/lib/axlsx/stylesheet/color.rb +++ b/lib/axlsx/stylesheet/color.rb @@ -61,6 +61,9 @@ module Axlsx # Indexed colors are for backward compatability which I am choosing not to support # def indexed=(v) Axlsx::validate_unsigned_integer v; @indexed = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << "<color " self.instance_values.each do |key, value| @@ -69,9 +72,5 @@ module Axlsx str << "/>" end - # Serializes the color - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) xml.color(self.instance_values) end end end diff --git a/lib/axlsx/stylesheet/fill.rb b/lib/axlsx/stylesheet/fill.rb index d6fde1c7..7bb5a437 100644 --- a/lib/axlsx/stylesheet/fill.rb +++ b/lib/axlsx/stylesheet/fill.rb @@ -18,18 +18,14 @@ module Axlsx self.fill_type = fill_type end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<fill>' @fill_type.to_xml_string(str) str << '</fill>' end - # Serializes the fill - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.fill { @fill_type.to_xml(xml) } - end # @see fill_type def fill_type=(v) DataTypeValidator.validate "Fill.fill_type", [PatternFill, GradientFill], v; @fill_type = v; end diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb index 4bbcb487..657c4c30 100644 --- a/lib/axlsx/stylesheet/font.rb +++ b/lib/axlsx/stylesheet/font.rb @@ -133,7 +133,9 @@ module Axlsx # @see sz def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<font>' instance_values.each do |k, v| @@ -141,16 +143,5 @@ module Axlsx end str << '</font>' end - - # Serializes the fill - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.font { - self.instance_values.each do |k, v| - v.is_a?(Color) ? v.to_xml(xml) : xml.send(k, {:val => v}) - end - } - end end end diff --git a/lib/axlsx/stylesheet/gradient_fill.rb b/lib/axlsx/stylesheet/gradient_fill.rb index 2a789c6f..514e0cfd 100644 --- a/lib/axlsx/stylesheet/gradient_fill.rb +++ b/lib/axlsx/stylesheet/gradient_fill.rb @@ -64,7 +64,9 @@ module Axlsx # @see bottom def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<gradientFill' h = self.instance_values.reject { |k,v| k.to_sym == :stop } @@ -73,13 +75,5 @@ module Axlsx @stop.each { |s| s.to_xml_string(str) } str << '</gradientFill>' end - # Serializes the gradientFill - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.gradientFill(self.instance_values.reject { |k,v| k.to_sym == :stop }) { - @stop.each { |s| s.to_xml(xml) } - } - end end end diff --git a/lib/axlsx/stylesheet/gradient_stop.rb b/lib/axlsx/stylesheet/gradient_stop.rb index aca26b79..94ca4795 100644 --- a/lib/axlsx/stylesheet/gradient_stop.rb +++ b/lib/axlsx/stylesheet/gradient_stop.rb @@ -25,14 +25,13 @@ module Axlsx # @see position def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<stop position="' << position.to_s << '">' self.color.to_xml_string(str) str << '</stop>' end - # Serializes the gradientStop - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) xml.stop(:position => self.position) {self.color.to_xml(xml)} end end end diff --git a/lib/axlsx/stylesheet/num_fmt.rb b/lib/axlsx/stylesheet/num_fmt.rb index 8c74382f..d5122f7e 100644 --- a/lib/axlsx/stylesheet/num_fmt.rb +++ b/lib/axlsx/stylesheet/num_fmt.rb @@ -56,15 +56,15 @@ module Axlsx # @see formatCode def formatCode=(v) Axlsx::validate_string v; @formatCode = v end + + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<numFmt ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') str << '/>' end - # Creates a numFmt element applying the instance values of this object as attributes. - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - def to_xml(xml) xml.numFmt(self.instance_values) end - end end diff --git a/lib/axlsx/stylesheet/pattern_fill.rb b/lib/axlsx/stylesheet/pattern_fill.rb index 32d54d83..0c0a51a6 100644 --- a/lib/axlsx/stylesheet/pattern_fill.rb +++ b/lib/axlsx/stylesheet/pattern_fill.rb @@ -55,6 +55,9 @@ module Axlsx # @see patternType def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<patternFill patternType="' << patternType.to_s << '">' if fgColor.is_a?(Color) @@ -75,13 +78,5 @@ module Axlsx str << '</patternFill>' end - # Serializes the pattern fill - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.patternFill(:patternType => self.patternType) { - self.instance_values.reject { |k,v| k.to_sym == :patternType }.each { |k,v| xml.send(k, v.instance_values) } - } - end end end diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index d8d33fa1..1fb2e9b3 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -133,7 +133,7 @@ module Axlsx # @option options [String] font_name The name of the font to use # @option options [Integer] num_fmt The number format to apply # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored. - # @option options [Integer] border The border style to use. This can be the index of an existing border or a hash like {:style => :thin, :color => "FFFF0000"} to create a new border style + # @option options [Integer] border The border style to use. # @option options [String] bg_color The background color to apply to the cell # @option options [Boolean] hidden Indicates if the cell should be hidden # @option options [Boolean] locked Indicates if the cell should be locked @@ -148,7 +148,7 @@ module Axlsx # ws = p.workbook.add_worksheet # # # black text on a white background at 14pt with thin borders! - # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>Axlsx::STYLE_THIN_BORDER + # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"} # # ws.add_row :values => ["Least Popular Pets"] # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title @@ -250,6 +250,9 @@ module Axlsx cellXfs << xf end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<styleSheet xmlns="' << XML_NS << '">' [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key| @@ -258,19 +261,6 @@ module Axlsx str << '</styleSheet>' end - # Serializes the styles document - # @return [String] - def to_xml() - builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| - xml.styleSheet(:xmlns => XML_NS) { - [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key| - self.instance_values[key.to_s].to_xml(xml) unless self.instance_values[key.to_s].nil? - end - } - end - builder.to_xml(:save_with => 0) - end - private # Creates the default set of styles the exel requires to be valid as well as setting up the # Axlsx::STYLE_THIN_BORDER diff --git a/lib/axlsx/stylesheet/table_style.rb b/lib/axlsx/stylesheet/table_style.rb index 3184c042..324f33d6 100644 --- a/lib/axlsx/stylesheet/table_style.rb +++ b/lib/axlsx/stylesheet/table_style.rb @@ -36,7 +36,9 @@ module Axlsx # @see table def table=(v) Axlsx::validate_boolean v; @table=v end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k } attr[:count] = self.size @@ -47,13 +49,5 @@ module Axlsx str << '</tableStyle>' end - # Serializes the table style - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k } - attr[:count] = self.size - xml.tableStyle(attr) { self.each { |table_style_el| table_style_el.to_xml(xml) } } - end end end diff --git a/lib/axlsx/stylesheet/table_style_element.rb b/lib/axlsx/stylesheet/table_style_element.rb index a5cf4c48..1a4c8803 100644 --- a/lib/axlsx/stylesheet/table_style_element.rb +++ b/lib/axlsx/stylesheet/table_style_element.rb @@ -62,17 +62,14 @@ module Axlsx # @see dxfId def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<tableStyleElement ' str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') str << '/>' end - # Serializes the table style element - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.tableStyleElement self.instance_values - end end end diff --git a/lib/axlsx/stylesheet/table_styles.rb b/lib/axlsx/stylesheet/table_styles.rb index 5474c165..a43e7ce5 100644 --- a/lib/axlsx/stylesheet/table_styles.rb +++ b/lib/axlsx/stylesheet/table_styles.rb @@ -25,7 +25,9 @@ module Axlsx # @see defaultPivotStyle def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end - + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') attr = self.instance_values.reject {|k, v| ![:defaultTableStyle, :defaultPivotStyle].include?(k.to_sym) } attr[:count] = self.size @@ -36,16 +38,6 @@ module Axlsx str << '</tableStyles>' end - # Serializes the table styles element - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - attr = self.instance_values.reject {|k, v| ![:defaultTableStyle, :defaultPivotStyle].include?(k.to_sym) } - attr[:count] = self.size - xml.tableStyles(attr) { - self.each { |table_style| table_style.to_xml(xml) } - } - end end end diff --git a/lib/axlsx/stylesheet/xf.rb b/lib/axlsx/stylesheet/xf.rb index e8e36301..59329a63 100644 --- a/lib/axlsx/stylesheet/xf.rb +++ b/lib/axlsx/stylesheet/xf.rb @@ -126,6 +126,9 @@ module Axlsx # @see applyProtection def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<xf ' h = instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym} @@ -136,14 +139,5 @@ module Axlsx str << '</xf>' end - # Serializes the xf elemen - # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. - # @return [String] - def to_xml(xml) - xml.xf(self.instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}) { - alignment.to_xml(xml) if self.alignment - protection.to_xml(xml) if self.protection - } - end end end diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index 588dada5..c37b596a 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -171,7 +171,7 @@ module Axlsx # drawing rels part DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels" - + # drawing part TABLE_PN = "tables/table%d.xml" @@ -232,5 +232,4 @@ module Axlsx # error message for duplicate sheet names ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name" - FIXED_COL_WIDTH = 8.43 end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index d4913074..54a0aeb4 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -103,6 +103,13 @@ module Axlsx RestrictionValidator.validate :gradient_type, [:linear, :path], v end + # Requires that the value is a valid scatterStyle + # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker + # must be one of "none" | "line" | "lineMarker" | "marker" | "smooth" | "smoothMarker" + # @param [Symbol|String] the value to validate + def self.validate_scatter_style(v) + Axlsx::RestrictionValidator.validate "ScatterChart.scatterStyle", [:none, :line, :lineMarker, :marker, :smooth, :smoothMarker], v.to_sym + end # Requires that the value is a valid horizontal_alignment # :general, :left, :center, :right, :fill, :justify, :centerContinuous, :distributed are allowed # @param [Any] v The value validated diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index 175371e8..3ffa1049 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -5,6 +5,6 @@ module Axlsx # When using bunle exec rake and referencing the gem on github or locally # it will use the gemspec, which preloads this constant for the gem's version. # We check to make sure that it has not already been loaded - VERSION="1.1.0" unless Axlsx.const_defined? :VERSION + VERSION="1.1.0" unless defined? VERSION end diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb index dac8221f..d9a22432 100644 --- a/lib/axlsx/workbook/shared_strings_table.rb +++ b/lib/axlsx/workbook/shared_strings_table.rb @@ -36,24 +36,13 @@ module Axlsx resolve(cells) end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string '<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '" count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '">' << @shared_xml_string << '</sst>' end - # Generate the xml document for the Shared Strings Table - # @return [String] - def to_xml - - builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| - xml.sst(:xmlns => Axlsx::XML_NS, :count => count, :uniqueCount => unique_count) { - @unique_cells.each do |cell| - xml.si { cell.run_xml(xml) } - end - } - end - builder.to_xml(:save_with => 0) - end - private # Interate over all of the cells in the array. diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 13140786..3557a89b 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -36,9 +36,6 @@ module Axlsx 'shadow', 'condense', 'extend', 'u', 'vertAlign', 'sz', 'color', 'scheme'] - INLINE_ATTR = [:font_name => { :validator=>:validate_string}] - - # The index of the cellXfs item to be applied to this cell. # @return [Integer] # @see Axlsx::Styles diff --git a/lib/axlsx/workbook/worksheet/page_margins.rb b/lib/axlsx/workbook/worksheet/page_margins.rb index 19402a6d..d2349f9e 100644 --- a/lib/axlsx/workbook/worksheet/page_margins.rb +++ b/lib/axlsx/workbook/worksheet/page_margins.rb @@ -84,10 +84,10 @@ module Axlsx def footer=(v); Axlsx::validate_unsigned_numeric(v); @footer = v end # Serializes the page margins element + # @param [String] str + # @return [String] # @note For compatibility, this is a noop unless custom margins have been specified. # @see #custom_margins_specified? - # @param [String] str - # @retrun [String] def to_xml_string(str = '') str << '<pageMargins ' str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ') diff --git a/lib/axlsx/workbook/worksheet/table.rb b/lib/axlsx/workbook/worksheet/table.rb index 0b1dc385..2fd15966 100644 --- a/lib/axlsx/workbook/worksheet/table.rb +++ b/lib/axlsx/workbook/worksheet/table.rb @@ -63,6 +63,9 @@ module Axlsx end end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string(str = '') str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<table xmlns="' << XML_NS << '" id="' << (index+1).to_s << '" name="' << @name << '" displayName="' << @name.gsub(/\s/,'_') << '" ' diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 200c8b80..4f26b568 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -384,6 +384,9 @@ module Axlsx image end + # Serializes the object + # @param [String] str + # @return [String] def to_xml_string str = '<?xml version="1.0" encoding="UTF-8"?>' str.concat "<worksheet xmlns=\"%s\" xmlns:r=\"%s\">" % [XML_NS, XML_NS_R] @@ -409,54 +412,6 @@ module Axlsx str + '</worksheet>' end - # Serializes the worksheet document - # @return [String] - def to_xml - builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| - xml.worksheet(:xmlns => XML_NS, - :'xmlns:r' => XML_NS_R) { - xml.sheetPr { - xml.pageSetUpPr :fitToPage => fit_to_page if fit_to_page - } - # another patch for the folks at rubyXL as thier parser depends on this optional element. - xml.dimension :ref=>dimension unless rows.size == 0 - # this is required by rubyXL, spec says who cares - but it seems they didnt notice - # grouping issue resolved by keeping tabSelected set to 0 - xml.sheetViews { - xml.sheetView(:tabSelected => @selected, :workbookViewId => 0, :showGridLines => show_gridlines) { - xml.selection :activeCell=>"A1", :sqref => "A1" - } - } - - if @auto_fit_data.size > 0 - xml.cols { - @auto_fit_data.each_with_index do |col, index| - min_max = index+1 - xml.col(:min=>min_max, :max=>min_max, :width => auto_width(col), :customWidth=>1) - end - } - end - xml.sheetData { - @rows.each do |row| - row.to_xml(xml) - end - } - xml.autoFilter :ref=>@auto_filter if @auto_filter - xml.mergeCells(:count=>@merged_cells.size) { @merged_cells.each { | mc | xml.mergeCell(:ref=>mc) } } unless @merged_cells.empty? - page_margins.to_xml(xml) if @page_margins - xml.drawing :"r:id"=>"rId1" if @drawing - unless @tables.empty? - xml.tableParts(:count => @tables.length) { - @tables.each do |table| - xml.tablePart :'r:id' => table.rId - end - } - end - } - end - builder.to_xml(:save_with => 0) - end - # The worksheet relationships. This is managed automatically by the worksheet # @return [Relationships] def relationships |
