summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-01 11:58:09 +0900
committerRandy Morgan <[email protected]>2012-04-01 11:58:09 +0900
commit1529fce32449a8454208fded20d83c9ceca810e0 (patch)
tree02f722182fea58a51b8c0a5433221b3a677e80e4
parent22a341841f191a5aa00e87b1f166b4f25cc67f0a (diff)
downloadcaxlsx-1529fce32449a8454208fded20d83c9ceca810e0.tar.gz
caxlsx-1529fce32449a8454208fded20d83c9ceca810e0.zip
rebuild all serialization to use string concatenation instead of nokogiri.
-rw-r--r--lib/axlsx/doc_props/core.rb1
-rw-r--r--lib/axlsx/drawing/axis.rb50
-rw-r--r--lib/axlsx/drawing/bar_3D_chart.rb74
-rw-r--r--lib/axlsx/drawing/bar_series.rb20
-rw-r--r--lib/axlsx/drawing/cat_axis.rb19
-rw-r--r--lib/axlsx/drawing/cat_axis_data.rb38
-rw-r--r--lib/axlsx/drawing/chart.rb67
-rw-r--r--lib/axlsx/drawing/drawing.rb10
-rw-r--r--lib/axlsx/drawing/graphic_frame.rb41
-rw-r--r--lib/axlsx/drawing/hyperlink.rb10
-rw-r--r--lib/axlsx/drawing/line_3D_chart.rb68
-rw-r--r--lib/axlsx/drawing/line_series.rb10
-rw-r--r--lib/axlsx/drawing/marker.rb10
-rw-r--r--lib/axlsx/drawing/named_axis_data.rb38
-rw-r--r--lib/axlsx/drawing/one_cell_anchor.rb22
-rw-r--r--lib/axlsx/drawing/pic.rb44
-rw-r--r--lib/axlsx/drawing/picture_locking.rb38
-rw-r--r--lib/axlsx/drawing/pie_3D_chart.rb17
-rw-r--r--lib/axlsx/drawing/pie_series.rb25
-rw-r--r--lib/axlsx/drawing/scaling.rb20
-rw-r--r--lib/axlsx/drawing/scatter_chart.rb43
-rw-r--r--lib/axlsx/drawing/scatter_series.rb13
-rw-r--r--lib/axlsx/drawing/ser_axis.rb10
-rw-r--r--lib/axlsx/drawing/series.rb22
-rw-r--r--lib/axlsx/drawing/series_title.rb27
-rw-r--r--lib/axlsx/drawing/title.rb25
-rw-r--r--lib/axlsx/drawing/two_cell_anchor.rb35
-rw-r--r--lib/axlsx/drawing/val_axis.rb15
-rw-r--r--lib/axlsx/drawing/val_axis_data.rb39
-rw-r--r--lib/axlsx/drawing/view_3D.rb25
-rw-r--r--lib/axlsx/package.rb11
-rw-r--r--lib/axlsx/rels/relationship.rb2
-rw-r--r--lib/axlsx/rels/relationships.rb2
-rw-r--r--lib/axlsx/stylesheet/border.rb13
-rw-r--r--lib/axlsx/stylesheet/border_pr.rb26
-rw-r--r--lib/axlsx/stylesheet/cell_alignment.rb41
-rw-r--r--lib/axlsx/stylesheet/cell_protection.rb12
-rw-r--r--lib/axlsx/stylesheet/cell_style.rb9
-rw-r--r--lib/axlsx/stylesheet/color.rb6
-rw-r--r--lib/axlsx/stylesheet/fill.rb8
-rw-r--r--lib/axlsx/stylesheet/font.rb23
-rw-r--r--lib/axlsx/stylesheet/gradient_fill.rb29
-rw-r--r--lib/axlsx/stylesheet/gradient_stop.rb9
-rw-r--r--lib/axlsx/stylesheet/num_fmt.rb14
-rw-r--r--lib/axlsx/stylesheet/pattern_fill.rb34
-rw-r--r--lib/axlsx/stylesheet/styles.rb8
-rw-r--r--lib/axlsx/stylesheet/table_style.rb11
-rw-r--r--lib/axlsx/stylesheet/table_style_element.rb12
-rw-r--r--lib/axlsx/stylesheet/table_styles.rb15
-rw-r--r--lib/axlsx/stylesheet/xf.rb46
-rw-r--r--lib/axlsx/util/simple_typed_list.rb27
-rw-r--r--lib/schema/dc.xsd10
-rw-r--r--lib/schema/dcmitype.xsd8
-rw-r--r--lib/schema/dcterms.xsd30
-rw-r--r--lib/schema/opc-coreProperties.xsd8
-rw-r--r--lib/schema/xml.xsd15
-rw-r--r--test/drawing/tc_axis.rb5
-rw-r--r--test/drawing/tc_bar_3D_chart.rb4
-rw-r--r--test/drawing/tc_chart.rb4
-rw-r--r--test/drawing/tc_drawing.rb2
-rw-r--r--test/drawing/tc_line_3d_chart.rb2
-rw-r--r--test/drawing/tc_pic.rb2
-rw-r--r--test/drawing/tc_pie_3D_chart.rb2
-rw-r--r--test/drawing/tc_scatter_chart.rb21
-rw-r--r--test/stylesheet/tc_styles.rb2
65 files changed, 571 insertions, 778 deletions
diff --git a/lib/axlsx/doc_props/core.rb b/lib/axlsx/doc_props/core.rb
index 7d9ba291..b3c80991 100644
--- a/lib/axlsx/doc_props/core.rb
+++ b/lib/axlsx/doc_props/core.rb
@@ -24,6 +24,7 @@ module Axlsx
str << '<dc:creator>' << self.creator << '</dc:creator>'
str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << '</dcterms:created>'
str << '<cp:revision>0</cp:revision>'
+ str << '</cp:coreProperties>'
end
end
end
diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb
index 8fbc3612..e686314c 100644
--- a/lib/axlsx/drawing/axis.rb
+++ b/lib/axlsx/drawing/axis.rb
@@ -85,50 +85,26 @@ module Axlsx
def to_xml_string(str = '')
- str << '<axId val="' << @axId.to_s << '"/>'
+ str << '<c:axId val="' << @axId.to_s << '"/>'
@scaling.to_xml_string str
- str << '<delete val="0"/>'
- str << '<axPos val="' << @axPos.to_s << '"/>'
- str << '<majorGridlines>'
+ str << '<c:delete val="0"/>'
+ str << '<c:axPos val="' << @axPos.to_s << '"/>'
+ str << '<c:majorGridlines>'
if self.gridlines == false
- str << '<spPr>'
+ str << '<c:spPr>'
str << '<a:ln>'
str << '<a:noFill/>'
str << '</a:ln>'
- str << '</spPr>'
+ str << '</c:spPr>'
end
- str << '</majorGridlines>'
- str << '<numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
- str << '<majorTickMark val="none"/>'
- str << '<minorTickMark val="none"/>'
- str << '<tickLblPos val="' << @tickLblPos.to_s << '"/>'
- str << '<crossAx val="' << @crossAx.to_s << '"/>'
- str << '<crosses val="' << @crosses.to_s << '"/>'
+ str << '</c:majorGridlines>'
+ str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
+ str << '<c:majorTickMark val="none"/>'
+ str << '<c:minorTickMark val="none"/>'
+ str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
+ str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
+ str << '<c:crosses val="' << @crosses.to_s << '"/>'
end
- # Serializes the common axis
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.axId :val=>@axId
- @scaling.to_xml(xml)
- xml.delete :val=>0
- xml.axPos :val=>@axPos
- xml.majorGridlines {
- if self.gridlines == false
- xml.spPr {
- xml[:a].ln {
- xml[:a].noFill
- }
- }
- end
- }
- xml.numFmt :formatCode => @format_code, :sourceLinked=>"1"
- xml.majorTickMark :val=>"none"
- xml.minorTickMark :val=>"none"
- xml.tickLblPos :val=>@tickLblPos
- xml.crossAx :val=>@crossAx
- xml.crosses :val=>@crosses
- end
end
end
diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb
index dbed026a..f623ab9f 100644
--- a/lib/axlsx/drawing/bar_3D_chart.rb
+++ b/lib/axlsx/drawing/bar_3D_chart.rb
@@ -106,57 +106,29 @@ module Axlsx
end
def to_xml_string(str = '')
- super do |str|
- str << '<bar3DChart>'
- str << '<barDir val="' << barDir.to_s << '"/>'
- str << '<grouping val="' << grouping.to_s << '"/>'
- str << '<varyColors val="1"/>'
- @series.each { |ser| ser.to_xml_str(str) }
- str << '<dLbls>'
- str << '<showLegendKey val="0"/>'
- str << '<showVal val="0"/>'
- str << '<showCatName val="0"/>'
- str << '<showSerName val="0"/>'
- str << '<showPercent val="0"/>'
- str << '<showBubbleSize val="0"/>'
- str << '</dLbls>'
- str << '<gapWidth val="' << @gapWidth.to_s << '"/>' unless @gapWidth.nil?
- str << '<gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
- str << '<shape val="' << @shape.to_s << '"/>'
- str << '<axId val="' << @catAxId.to_s << '"/>'
- str << '<axId val="' << @valAxId.to_s << '"/>'
- str << '<axId val="0"/>'
- str << '</bar3DChart>'
- @catAxis.to_xml_str str
- @valAxis.to_xml_str str
- end
- end
- # Serializes the bar chart
- # @return [String]
- def to_xml
- super() do |xml|
- xml.bar3DChart {
- xml.barDir :val => barDir
- xml.grouping :val=>grouping
- xml.varyColors :val=>1
- @series.each { |ser| ser.to_xml(xml) }
- xml.dLbls {
- xml.showLegendKey :val=>0
- xml.showVal :val=>0
- xml.showCatName :val=>0
- xml.showSerName :val=>0
- xml.showPercent :val=>0
- xml.showBubbleSize :val=>0
- }
- xml.gapWidth :val=>@gapWidth unless @gapWidth.nil?
- xml.gapDepth :val=>@gapDepth unless @gapDepth.nil?
- xml.shape :val=>@shape unless @shape.nil?
- xml.axId :val=>@catAxId
- xml.axId :val=>@valAxId
- xml.axId :val=>0
- }
- @catAxis.to_xml(xml)
- @valAxis.to_xml(xml)
+ super(str) do |str_inner|
+ str_inner << '<c:bar3DChart>'
+ str_inner << '<c:barDir val="' << barDir.to_s << '"/>'
+ str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
+ str_inner << '<c:varyColors val="1"/>'
+ @series.each { |ser| ser.to_xml_string(str_inner) }
+ str_inner << '<c:dLbls>'
+ str_inner << '<c:showLegendKey val="0"/>'
+ str_inner << '<c:showVal val="0"/>'
+ str_inner << '<c:showCatName val="0"/>'
+ str_inner << '<c:showSerName val="0"/>'
+ str_inner << '<c:showPercent val="0"/>'
+ str_inner << '<c:showBubbleSize val="0"/>'
+ str_inner << '</c:dLbls>'
+ str_inner << '<c:gapWidth val="' << @gapWidth.to_s << '"/>' unless @gapWidth.nil?
+ str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
+ str_inner << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
+ str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
+ str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
+ str_inner << '<c:axId val="0"/>'
+ str_inner << '</c:bar3DChart>'
+ @catAxis.to_xml_string str_inner
+ @valAxis.to_xml_string str_inner
end
end
end
diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb
index 3a3ea6fa..65cd87d9 100644
--- a/lib/axlsx/drawing/bar_series.rb
+++ b/lib/axlsx/drawing/bar_series.rb
@@ -41,25 +41,13 @@ module Axlsx
end
def to_xml_string(str = '')
- super(str) do
- @labels.to_xml_string(str) unless @labels.nil?
- @data.to_xml_string(str) unless @data.nil?
- str << '<shape val="' << @shape.to_s << '"/>'
+ super(str) do |str_inner|
+ @labels.to_xml_string(str_inner) unless @labels.nil?
+ @data.to_xml_string(str_inner) unless @data.nil?
+ str_inner << '<shape val="' << @shape.to_s << '"/>'
end
end
- # Serializes the series
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- super(xml) do |xml_inner|
- @labels.to_xml(xml_inner) unless @labels.nil?
- @data.to_xml(xml_inner) unless @data.nil?
- xml_inner.shape :val=>@shape
- end
- end
-
-
private
# assigns the data for this series
diff --git a/lib/axlsx/drawing/cat_axis.rb b/lib/axlsx/drawing/cat_axis.rb
index 242ae698..66f21943 100644
--- a/lib/axlsx/drawing/cat_axis.rb
+++ b/lib/axlsx/drawing/cat_axis.rb
@@ -49,23 +49,14 @@ module Axlsx
def to_xml_string(str = '')
- str << '<catAx>'
+ str << '<c:catAx>'
super(str)
- str << '<auto val="' << @auto.to_s << '</auto>'
- str << '</catAx>'
+ str << '<c:auto val="' << @auto.to_s << '"/>'
+ str << '<c:lblAlgn val="' << @lblAlgn.to_s << '"/>'
+ str << '<c:lblOffset val="' << @lblOffset.to_s << '"/>'
+ str << '</c:catAx>'
end
- # Serializes the category axis
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.catAx {
- super(xml)
- xml.auto :val=>@auto
- xml.lblAlgn :val=>@lblAlgn
- xml.lblOffset :val=>@lblOffset
- }
- end
end
diff --git a/lib/axlsx/drawing/cat_axis_data.rb b/lib/axlsx/drawing/cat_axis_data.rb
index a119282e..ced5a305 100644
--- a/lib/axlsx/drawing/cat_axis_data.rb
+++ b/lib/axlsx/drawing/cat_axis_data.rb
@@ -13,38 +13,18 @@ module Axlsx
def to_xml_string(str = '')
- str << '<cat>'
- str << '<strRef>'
- str << '<f>' << Axlsx::cell_range(@list) << '</f>'
- str << '<strCache>'
- str << '<ptCount val="' << size.to_s << '"/>'
+ str << '<c:cat>'
+ str << '<c:strRef>'
+ str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
+ str << '<c:strCache>'
+ str << '<c:ptCount val="' << size.to_s << '"/>'
each_with_index do |item, index|
v = item.is_a?(Cell) ? item.value.to_s : item
- str << '<pt idx="' << index.to_s << '"><v>' << v << '</v></pt>'
+ str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
end
- str << '</strCache>'
- str << '</strRef>'
- str << '</cat>'
- end
-
- # Serializes the category axis data
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.cat {
- xml.strRef {
- xml.f Axlsx::cell_range(@list)
- xml.strCache {
- xml.ptCount :val=>size
- each_with_index do |item, index|
- v = item.is_a?(Cell) ? item.value : item
- xml.pt(:idx=>index) {
- xml.v v
- }
- end
- }
- }
- }
+ str << '</c:strCache>'
+ str << '</c:strRef>'
+ str << '</c:cat>'
end
end
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index a0bc75ba..65140d66 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -114,7 +114,7 @@ module Axlsx
end
- def to_xml_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 << '">'
str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
@@ -122,63 +122,28 @@ module Axlsx
str << '<c:chart>'
@title.to_xml_string str
# do these need the c: namespace as well???
- str << '<autoTitleDeleted val="0"/>'
+ str << '<c:autoTitleDeleted val="0"/>'
@view3D.to_xml_string(str) if @view3D
- str << '<floor thickness="0"/>'
- str << '<sideWall thickness="0"/>'
- str << '<backWall thickness="0"/>'
- str << '<plotArea>'
- str << '<layout/>'
+ str << '<c:floor><c:thickness val="0"/></c:floor>'
+ str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
+ str << '<c:backWall><c:thickness val="0"/></c:backWall>'
+ str << '<c:plotArea>'
+ str << '<c:layout/>'
yield str if block_given?
- str << '</plotArea>'
+ str << '</c:plotArea>'
if @show_legend
- str << '<legend>'
- str << '<legendPos val="r"/>'
- str << '<layout/>'
- str << '<overlay val="0"/>'
- str << '</legend>'
+ str << '<c:legend>'
+ str << '<c:legendPos val="r"/>'
+ str << '<c:layout/>'
+ str << '<c:overlay val="0"/>'
+ str << '</c:legend>'
end
- str << '<plotVisOnly val="1"/>'
- str << '<dispBlanksAs val="zero"/>'
- str << '<showDLblsOverMax val="1"/>'
+ str << '<c:plotVisOnly val="1"/>'
+ str << '<c:dispBlanksAs val="zero"/>'
+ str << '<c:showDLblsOverMax val="1"/>'
str << '</c:chart>'
str << '</c:chartSpace>'
end
- # Chart Serialization
- # serializes the chart
- def to_xml
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
- xml.send('c:chartSpace', :'xmlns:c' => XML_NS_C, :'xmlns:a' => XML_NS_A) {
- xml[:c].date1904 :val => Axlsx::Workbook.date1904
- xml[:c].style :val=>style
- xml[:c].chart {
- @title.to_xml(xml)
- xml.autoTitleDeleted :val=>0
- @view3D.to_xml(xml) if @view3D
-
- xml.floor { xml.thickness(:val=>0) }
- xml.sideWall { xml.thickness(:val=>0) }
- xml.backWall { xml.thickness(:val=>0) }
- xml.plotArea {
- xml.layout
- yield xml if block_given?
- }
- if @show_legend
- xml.legend {
- xml.legendPos :val => "r"
- xml.layout
- xml.overlay :val => 0
- }
- end
- xml.plotVisOnly :val => 1
- xml.dispBlanksAs :val => :zero
- xml.showDLblsOverMax :val => 1
- }
-
- }
- end
- builder.to_xml(:save_with => 0)
- end
# This is a short cut method to set the start anchor position
# If you need finer granularity in positioning use
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb
index 08b8531a..d9241f29 100644
--- a/lib/axlsx/drawing/drawing.rb
+++ b/lib/axlsx/drawing/drawing.rb
@@ -145,15 +145,5 @@ module Axlsx
str << '</xdr:wsDr>'
end
- # Serializes the drawing
- # @return [String]
- def to_xml
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
- xml.send('xdr:wsDr', :'xmlns:xdr'=>XML_NS_XDR, :'xmlns:a'=>XML_NS_A, :'xmlns:c'=>XML_NS_C) {
- anchors.each {|anchor| anchor.to_xml(xml) }
- }
- end
- builder.to_xml(:save_with => 0)
- end
end
end
diff --git a/lib/axlsx/drawing/graphic_frame.rb b/lib/axlsx/drawing/graphic_frame.rb
index 7502dfba..d123e58a 100644
--- a/lib/axlsx/drawing/graphic_frame.rb
+++ b/lib/axlsx/drawing/graphic_frame.rb
@@ -29,43 +29,22 @@ module Axlsx
end
def to_xml_string(str = '')
- str << '<graphicFrame>'
- str << '<nvGraphicFramePr>'
- str << '<cNvPr id="2" name="' << chart.title.text << '"/>'
- str << '<cNvGraphicFramePr/>'
- str << '</nvGraphicFramePr>'
- str << '<xfrm>'
+ str << '<xdr:graphicFrame>'
+ str << '<xdr:nvGraphicFramePr>'
+ str << '<xdr:cNvPr id="2" name="' << chart.title.text << '"/>'
+ str << '<xdr:cNvGraphicFramePr/>'
+ str << '</xdr:nvGraphicFramePr>'
+ str << '<xdr:xfrm>'
str << '<a:off x="0" y="0"/>'
str << '<a:ext cx="0" cy="0"/>'
- str << '</xfrm>'
+ str << '</xdr:xfrm>'
str << '<a:graphic>'
- str << '<graphicData uri="' << XML_NS_C << '">'
+ str << '<a:graphicData uri="' << XML_NS_C << '">'
str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId.to_s << '"/>'
- str << '</graphicData>'
+ str << '</a:graphicData>'
str << '</a:graphic>'
- str << '</graphicFrame>'
+ str << '</xdr:graphicFrame>'
end
- # Serializes the graphic frame
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.graphicFrame {
- xml.nvGraphicFramePr {
- xml.cNvPr :id=>2, :name=>chart.title.text
- xml.cNvGraphicFramePr
- }
- xml.xfrm {
- xml[:a].off(:x=>0, :y=>0)
- xml[:a].ext :cx=>0, :cy=>0
- }
- xml[:a].graphic {
- xml.graphicData(:uri=>XML_NS_C) {
- xml[:c].chart :'xmlns:c'=>XML_NS_C, :'xmlns:r'=>XML_NS_R, :'r:id'=>rId
- }
- }
- }
-
- end
end
end
diff --git a/lib/axlsx/drawing/hyperlink.rb b/lib/axlsx/drawing/hyperlink.rb
index 9cfdf705..ae217f31 100644
--- a/lib/axlsx/drawing/hyperlink.rb
+++ b/lib/axlsx/drawing/hyperlink.rb
@@ -82,16 +82,6 @@ module Axlsx
str << '/>'
end
- # Serializes the hyperlink
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
- h.delete('href')
- h.delete('parent')
- xml[:a].hlinkClick h
- end
-
private
# The relational ID for this hyperlink
# @return [Integer]
diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb
index bd587d1b..74c10850 100644
--- a/lib/axlsx/drawing/line_3D_chart.rb
+++ b/lib/axlsx/drawing/line_3D_chart.rb
@@ -86,55 +86,29 @@ module Axlsx
end
def to_xml_string(str = '')
- super do |str|
- str << '<line3DChart>'
- str << '<grouping val="' << grouping.to_s << '"/>'
- str << '<varyColors val="1"/>'
- @series.each { |ser| ser.to_xml_str(str) }
- str << '<dLbls>'
- str << '<showLegendKey val="0"/>'
- str << '<showVal val="0"/>'
- str << '<showCatName val="0"/>'
- str << '<showSerName val="0"/>'
- str << '<showPercent val="0"/>'
- str << '<showBubbleSize val="0"/>'
- str << '</dLbls>'
- str << '<gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
- str << '<axId val="' << @catAxId.to_s << '"/>'
- str << '<axId val="' << @valAxId.to_s << '"/>'
- str << '<axId val="' << @serAxId.to_s << '"/>'
- str << '</line3DChart>'
- @catAxis.to_xml_str str
- @valAxis.to_xml_str str
- @serAxis.to_xml_str str
+ super(str) do |str_inner|
+ str_inner << '<c:line3DChart>'
+ str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
+ str_inner << '<c:varyColors val="1"/>'
+ @series.each { |ser| ser.to_xml_string(str_inner) }
+ str_inner << '<c:dLbls>'
+ str_inner << '<c:showLegendKey val="0"/>'
+ str_inner << '<c:showVal val="0"/>'
+ str_inner << '<c:showCatName val="0"/>'
+ str_inner << '<c:showSerName val="0"/>'
+ str_inner << '<c:showPercent val="0"/>'
+ str_inner << '<c:showBubbleSize val="0"/>'
+ str_inner << '</c:dLbls>'
+ str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
+ str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
+ str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
+ str_inner << '<c:axId val="' << @serAxId.to_s << '"/>'
+ str_inner << '</c:line3DChart>'
+ @catAxis.to_xml_string str_inner
+ @valAxis.to_xml_string str_inner
+ @serAxis.to_xml_string str_inner
end
end
- # Serializes the bar chart
- # @return [String]
- def to_xml
- super() do |xml|
- xml.line3DChart {
- xml.grouping :val=>grouping
- xml.varyColors :val=>1
- @series.each { |ser| ser.to_xml(xml) }
- xml.dLbls {
- xml.showLegendKey :val=>0
- xml.showVal :val=>0
- xml.showCatName :val=>0
- xml.showSerName :val=>0
- xml.showPercent :val=>0
- xml.showBubbleSize :val=>0
- }
- xml.gapDepth :val=>@gapDepth unless @gapDepth.nil?
- xml.axId :val=>@catAxId
- xml.axId :val=>@valAxId
- xml.axId :val=>@serAxId
- }
- @catAxis.to_xml(xml)
- @valAxis.to_xml(xml)
- @serAxis.to_xml(xml)
- end
- end
end
end
diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb
index c5908f64..136408dd 100644
--- a/lib/axlsx/drawing/line_series.rb
+++ b/lib/axlsx/drawing/line_series.rb
@@ -32,16 +32,6 @@ module Axlsx
end
end
- # Serializes the series
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- super(xml) do |xml_inner|
- @labels.to_xml(xml_inner) unless @labels.nil?
- @data.to_xml(xml_inner) unless @data.nil?
- end
- end
-
private
# assigns the data for this series
diff --git a/lib/axlsx/drawing/marker.rb b/lib/axlsx/drawing/marker.rb
index a2ce4312..985cf321 100644
--- a/lib/axlsx/drawing/marker.rb
+++ b/lib/axlsx/drawing/marker.rb
@@ -52,18 +52,10 @@ module Axlsx
def to_xml_string(str = '')
[:col, :colOff, :row, :rowOff].each do |k|
- str << '<' << k.to_s << '>' << self.send(k).to_s << '</' << k.to_s << '>'
+ str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
end
end
- # Serializes the marker
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- [:col, :colOff, :row, :rowOff].each do |k|
- xml.send(k.to_sym, self.send(k))
- end
- end
end
end
diff --git a/lib/axlsx/drawing/named_axis_data.rb b/lib/axlsx/drawing/named_axis_data.rb
index 2ec58e8b..952dc10e 100644
--- a/lib/axlsx/drawing/named_axis_data.rb
+++ b/lib/axlsx/drawing/named_axis_data.rb
@@ -10,39 +10,21 @@ module Axlsx
def to_xml_string(str = '')
- str << '<' << @name << '>'
- str << '<numRef>'
- str << '<f>' << Axlsx::cell_range(@list) << '</f>'
- str << '<numCache>'
- str << '<formatCode>General</formatCode>'
- str << '<ptCount val="' << size.to_s << '"/>'
+ str << '<c:' << @name.to_s << '>'
+ str << '<c:numRef>'
+ str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
+ str << '<c:numCache>'
+ str << '<c:formatCode>General</c:formatCode>'
+ str << '<c:ptCount val="' << size.to_s << '"/>'
each_with_index do |item, index|
v = item.is_a?(Cell) ? item.value.to_s : item
- str << '<pt idx="' << index.to_s << '"><v>' << v << '</v></pt>'
+ str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
end
- str << '</numCache>'
- str << '</numRef>'
- str << '</' << @name << '>'
+ str << '</c:numCache>'
+ str << '</c:numRef>'
+ str << '</c:' << @name.to_s << '>'
end
- # Serializes the value axis data
- # @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) {
- xml.numRef {
- xml.f Axlsx::cell_range(@list)
- xml.numCache {
- xml.formatCode 'General'
- xml.ptCount :val=>size
- each_with_index do |item, index|
- v = item.is_a?(Cell) ? item.value : item
- xml.pt(:idx=>index) { xml.v v }
- end
- }
- }
- }
- end
end
end
diff --git a/lib/axlsx/drawing/one_cell_anchor.rb b/lib/axlsx/drawing/one_cell_anchor.rb
index e0574172..fd33892c 100644
--- a/lib/axlsx/drawing/one_cell_anchor.rb
+++ b/lib/axlsx/drawing/one_cell_anchor.rb
@@ -64,29 +64,15 @@ module Axlsx
def to_xml_string(str = '')
str << '<xdr:oneCellAnchor>'
- str << '<from>'
+ str << '<xdr:from>'
from.to_xml_string(str)
- str << '</from>'
- str << '<ext>' << ext.to_s << '</ext>'
+ str << '</xdr:from>'
+ str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
@object.to_xml_string(str)
- str << '<clientData/>'
+ str << '<xdr:clientData/>'
str << '</xdr:oneCellAnchor>'
end
- # Serializes the anchor
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:xdr].oneCellAnchor {
- xml.from {
- from.to_xml(xml)
- }
- xml.ext ext
- @object.to_xml(xml)
- xml.clientData
- }
- end
-
private
# converts the pixel width and height to EMU units and returns a hash of
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index 1783005a..733dc1df 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -145,40 +145,20 @@ module Axlsx
end
def to_xml_string(str = '')
+ str << '<xdr:pic>'
+ str << '<xdr:nvPicPr>'
+ str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
+ @hyperlink.to_xml_string(str) if @hyperlink.is_a?(Hyperlink)
+ str << '</xdr:cNvPr><xdr:cNvPicPr>'
+ picture_locking.to_xml_string(str)
+ str << '</xdr:cNvPicPr></xdr:nvPicPr>'
+ str << '<xdr:blipFill>'
+ str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="rId' << id.to_s << '"/>'
+ str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'
+ str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>'
+ str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
end
- # Serializes the picture
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.pic {
- xml.nvPicPr {
- xml.cNvPr(:id=>"2", :name=>name, :descr=>descr) {
- if @hyperlink.is_a?(Hyperlink)
- @hyperlink.to_xml(xml)
- end
- }
- xml.cNvPicPr {
- picture_locking.to_xml(xml)
- }
- }
- xml.blipFill {
- xml[:a].blip :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId#{id}"
- xml[:a].stretch {
- xml.fillRect
- }
- }
- xml.spPr {
- xml[:a].xfrm {
- xml.off :x=>0, :y=>0
- xml.ext :cx=>2336800, :cy=>2161540
- }
- xml[:a].prstGeom(:prst=>:rect) {
- xml.avLst
- }
- }
- }
- end
end
end
diff --git a/lib/axlsx/drawing/picture_locking.rb b/lib/axlsx/drawing/picture_locking.rb
index c05f1641..867e32b4 100644
--- a/lib/axlsx/drawing/picture_locking.rb
+++ b/lib/axlsx/drawing/picture_locking.rb
@@ -1,9 +1,9 @@
# encoding: UTF-8
module Axlsx
- # The picture locking class defines the locking properties for pictures in your workbook.
+ # The picture locking class defines the locking properties for pictures in your workbook.
class PictureLocking
-
-
+
+
attr_reader :noGrp
attr_reader :noSelect
attr_reader :noRot
@@ -31,43 +31,43 @@ module Axlsx
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
- end
+ end
# @see noGrp
- def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
+ def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
# @see noSelect
- def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
+ def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
# @see noRot
- def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
+ def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
# @see noChangeAspect
- def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
+ def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
# @see noMove
- def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
+ def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
# @see noResize
- def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
+ def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
# @see noEditPoints
- def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
+ def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
# @see noAdjustHandles
- def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
+ def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
# @see noChangeArrowheads
- def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
+ def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
# @see noChangeShapeType
- def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
+ def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
- # Serializes the picture locking
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:a].picLocks(self.instance_values)
+ def to_xml_string(str = '')
+ str << '<a:picLocks '
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '/>'
end
+
end
end
diff --git a/lib/axlsx/drawing/pie_3D_chart.rb b/lib/axlsx/drawing/pie_3D_chart.rb
index cb36e4f5..67ae791b 100644
--- a/lib/axlsx/drawing/pie_3D_chart.rb
+++ b/lib/axlsx/drawing/pie_3D_chart.rb
@@ -11,7 +11,7 @@ module Axlsx
# Creates a new pie chart object
# @param [GraphicFrame] frame The workbook that owns this chart.
# @option options [Cell, String] title
- # @option options [Boolean] show_legend
+ # @option options [Boolean] show_legend
# @option options [Symbol] grouping
# @option options [String] gapDepth
# @option options [Integer] rotX
@@ -28,15 +28,14 @@ module Axlsx
@view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
end
- # Serializes the pie chart
- # @return [String]
- def to_xml
- super() do |xml|
- xml[:c].pie3DChart {
- xml[:c].varyColors :val=>1
- @series.each { |ser| ser.to_xml(xml) }
- }
+ def to_xml_string(str = '')
+ super(str) do |str_inner|
+ str_inner << '<c:pie3DChart>'
+ str_inner << '<c:varyColors val="1"/>'
+ @series.each { |ser| ser.to_xml_string(str_inner) }
+ str_inner << '</c:pie3DChart>'
end
end
+
end
end
diff --git a/lib/axlsx/drawing/pie_series.rb b/lib/axlsx/drawing/pie_series.rb
index 8e583806..bf61c9ab 100644
--- a/lib/axlsx/drawing/pie_series.rb
+++ b/lib/axlsx/drawing/pie_series.rb
@@ -6,7 +6,7 @@ module Axlsx
# @see Chart#add_series
class PieSeries < Series
- # The data for this series.
+ # The data for this series.
# @return [SimpleTypedList]
attr_reader :data
@@ -29,22 +29,21 @@ module Axlsx
super(chart, options)
self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
- end
-
+ end
+
# @see explosion
def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
- # Serializes the series
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- super(xml) do |xml_inner|
- xml_inner.explosion :val=>@explosion unless @explosion.nil?
- @labels.to_xml(xml_inner) unless @labels.nil?
- @data.to_xml(xml_inner) unless @data.nil?
- end
+ def to_xml_string(str = '')
+ super(str) do |str_inner|
+ str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil?
+ @labels.to_xml_string str_inner unless @labels.nil?
+ @data.to_xml_string str_inner unless @data.nil?
+ end
+ str
end
- private
+
+ private
# assigns the data for this series
def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
diff --git a/lib/axlsx/drawing/scaling.rb b/lib/axlsx/drawing/scaling.rb
index c90d0377..af9cf2aa 100644
--- a/lib/axlsx/drawing/scaling.rb
+++ b/lib/axlsx/drawing/scaling.rb
@@ -46,24 +46,12 @@ module Axlsx
def to_xml_string(str = '')
str << '<c:scaling>'
- str << '<c:logBase val="' << @logBase.to_s << '"/>'
- str << '<c:orientation val="' << @orientation.to_s << '"/>'
- str << '<c:min val="' << @min.to_s << '"/>'
- str << '<c:max val="' << @max.to_s << '"/>'
+ str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil?
+ str << '<c:orientation val="' << @orientation.to_s << '"/>' unless @orientation.nil?
+ str << '<c:min val="' << @min.to_s << '"/>' unless @min.nil?
+ str << '<c:max val="' << @max.to_s << '"/>' unless @max.nil?
str << '</c:scaling>'
end
- # Serializes the axId
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:c].scaling {
- xml[:c].logBase :val=> @logBase unless @logBase.nil?
- xml[:c].orientation :val=> @orientation unless @orientation.nil?
- xml[:c].min :val => @min unless @min.nil?
- xml[:c].max :val => @max unless @max.nil?
- }
- end
-
end
end
diff --git a/lib/axlsx/drawing/scatter_chart.rb b/lib/axlsx/drawing/scatter_chart.rb
index f257303a..d8d7bb6d 100644
--- a/lib/axlsx/drawing/scatter_chart.rb
+++ b/lib/axlsx/drawing/scatter_chart.rb
@@ -21,30 +21,27 @@ module Axlsx
@series_type = ScatterSeries
end
- # Serializes the bar chart
- # @return [String]
- def to_xml
- super() do |xml|
- xml.scatterChart {
- xml.scatterStyle :val=>scatterStyle
-
- # This is all repeated from line_3D_chart.rb!
- xml.varyColors :val=>1
- @series.each { |ser| ser.to_xml(xml) }
- xml.dLbls {
- xml.showLegendKey :val=>0
- xml.showVal :val=>0
- xml.showCatName :val=>0
- xml.showSerName :val=>0
- xml.showPercent :val=>0
- xml.showBubbleSize :val=>0
- }
- xml.axId :val=>@xValAxId
- xml.axId :val=>@yValAxId
- }
- @xValAxis.to_xml(xml)
- @yValAxis.to_xml(xml)
+ def to_xml_string(str = '')
+ super do |str|
+ str << '<c:scatterChart>'
+ str << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
+ str << '<c:varyColors val="1"/>'
+ @series.each { |ser| ser.to_xml_string(str) }
+ str << '<c:dLbls>'
+ str << '<c:showLegendKey val="0"/>'
+ str << '<c:showVal val="0"/>'
+ str << '<c:showCatName val="0"/>'
+ str << '<c:showSerName val="0"/>'
+ str << '<c:showPercent val="0"/>'
+ str << '<c:showBubbleSize val="0"/>'
+ str << '</c:dLbls>'
+ str << '<c:axId val="' << @xValAxId.to_s << '"/>'
+ str << '<c:axId val="' << @yValAxId.to_s << '"/>'
+ str << '</c:scatterChart>'
+ @xValAxis.to_xml_string str
+ @yValAxis.to_xml_string str
end
+ str
end
end
end
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb
index 52145cd1..03b2cbdd 100644
--- a/lib/axlsx/drawing/scatter_series.rb
+++ b/lib/axlsx/drawing/scatter_series.rb
@@ -17,15 +17,12 @@ module Axlsx
@yData = NamedAxisData.new("yVal", options[:yData]) unless options[:yData].nil?
end
- # Serializes the series
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- super(xml) do |xml_inner|
- @xData.to_xml(xml_inner) unless @xData.nil?
- @yData.to_xml(xml_inner) unless @yData.nil?
+ def to_xml_string(str = '')
+ super(str) do |inner_str|
+ @xData.to_xml_string(inner_str) unless @xData.nil?
+ @yData.to_xml_string(inner_str) unless @yData.nil?
end
+ str
end
-
end
end
diff --git a/lib/axlsx/drawing/ser_axis.rb b/lib/axlsx/drawing/ser_axis.rb
index 54dde640..fdc0d43d 100644
--- a/lib/axlsx/drawing/ser_axis.rb
+++ b/lib/axlsx/drawing/ser_axis.rb
@@ -37,16 +37,6 @@ module Axlsx
str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>' unless @tickMarkSkip.nil?
str << '</c:serAx>'
end
- # Serializes the series axis
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:c].serAx {
- super(xml)
- xml[:c].tickLblSkip :val=>@tickLblSkip unless @tickLblSkip.nil?
- xml[:c].tickMarkSkip :val=>@tickMarkSkip unless @tickMarkSkip.nil?
- }
- end
end
diff --git a/lib/axlsx/drawing/series.rb b/lib/axlsx/drawing/series.rb
index 5960f508..9ab2db13 100644
--- a/lib/axlsx/drawing/series.rb
+++ b/lib/axlsx/drawing/series.rb
@@ -56,24 +56,12 @@ module Axlsx
def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
def to_xml_string(str = '')
- str << '<ser>'
- str << '<idx val="' << index.to_s << '"/>'
- str << '<order val="' << (order || index).to_s << '"/>'
+ str << '<c:ser>'
+ str << '<c:idx val="' << index.to_s << '"/>'
+ str << '<c:order val="' << (order || index).to_s << '"/>'
title.to_xml_string(str) unless title.nil?
- yeild str if block_given?
- str << '</ser>'
- end
-
- # Serializes the series
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.ser {
- xml.idx :val=>index
- xml.order :val=>order || index
- title.to_xml(xml) unless title.nil?
- yield xml if block_given?
- }
+ yield str if block_given?
+ str << '</c:ser>'
end
end
diff --git a/lib/axlsx/drawing/series_title.rb b/lib/axlsx/drawing/series_title.rb
index b13cec89..39ec10d5 100644
--- a/lib/axlsx/drawing/series_title.rb
+++ b/lib/axlsx/drawing/series_title.rb
@@ -3,21 +3,18 @@ module Axlsx
# A series title is a Title with a slightly different serialization than chart titles.
class SeriesTitle < Title
- # Serializes the series title
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:c].tx {
- xml[:c].strRef {
- xml[:c].f Axlsx::cell_range([@cell])
- xml[:c].strCache {
- xml[:c].ptCount :val=>1
- xml[:c].pt(:idx=>0) {
- xml[:c].v @text
- }
- }
- }
- }
+ def to_xml_string(str = '')
+ str << '<c:tx>'
+ str << '<c:strRef>'
+ str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
+ str << '<c:strCache>'
+ str << '<c:ptCount val="1"/>'
+ str << '<c:pt idx="0">'
+ str << '<c:v>' << @text << '</c:v>'
+ str << '</c:pt>'
+ str << '</c:strCache>'
+ str << '</c:strRef>'
+ str << '</c:tx>'
end
end
end
diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb
index a7b8e715..a9c253c8 100644
--- a/lib/axlsx/drawing/title.rb
+++ b/lib/axlsx/drawing/title.rb
@@ -54,31 +54,10 @@ module Axlsx
str << '</c:strRef>'
str << '</c:tx>'
end
+ str << '<c:layout/>'
+ str << '<c:overlay val="0"/>'
str << '</c:title>'
end
- # Serializes the chart title
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:c].title {
- unless @text.empty?
- xml[:c].tx {
- xml[:c].strRef {
- xml[:c].f Axlsx::cell_range([@cell])
- xml[:c].strCache {
- xml[:c].ptCount :val=>1
- xml[:c].pt(:idx=>0) {
- xml[:c].v @text
- }
- }
- }
- }
- end
- xml[:c].layout
- xml[:c].overlay :val=>0
- }
- end
-
end
end
diff --git a/lib/axlsx/drawing/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb
index 436f2e7a..cfa102ae 100644
--- a/lib/axlsx/drawing/two_cell_anchor.rb
+++ b/lib/axlsx/drawing/two_cell_anchor.rb
@@ -26,7 +26,7 @@ module Axlsx
attr_reader :drawing
- # Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the
+ # Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the
# graphic_frame's chart. That means that you can do stuff like
# c = worksheet.add_chart Axlsx::Chart
# c.start_at 5, 9
@@ -38,13 +38,13 @@ module Axlsx
# @option options [Array] end_at the col, row to end at
def initialize(drawing, options={})
@drawing = drawing
- drawing.anchors << self
+ drawing.anchors << self
@from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
end
# Creates a graphic frame and chart object associated with this anchor
# @return [Chart]
- def add_chart(chart_type, options)
+ def add_chart(chart_type, options)
@object = GraphicFrame.new(self, chart_type, options)
@object.chart
end
@@ -54,24 +54,19 @@ module Axlsx
def index
@drawing.anchors.index(self)
end
- # Serializes the two cell anchor
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- #build it for now, break it down later!
- xml[:xdr].twoCellAnchor {
- xml.from {
- from.to_xml(xml)
- }
- xml.to {
- to.to_xml(xml)
- }
- @object.to_xml(xml)
- xml.clientData
- }
- end
- private
+ def to_xml_string(str = '')
+ str << '<xdr:twoCellAnchor>'
+ str << '<xdr:from>'
+ from.to_xml_string str
+ str << '</xdr:from>'
+ str << '<xdr:to>'
+ to.to_xml_string str
+ str << '</xdr:to>'
+ object.to_xml_string(str)
+ str << '<xdr:clientData/>'
+ str << '</xdr:twoCellAnchor>'
+ end
end
end
diff --git a/lib/axlsx/drawing/val_axis.rb b/lib/axlsx/drawing/val_axis.rb
index 51adc31a..f2675733 100644
--- a/lib/axlsx/drawing/val_axis.rb
+++ b/lib/axlsx/drawing/val_axis.rb
@@ -23,20 +23,11 @@ module Axlsx
def crossBetween=(v) RestrictionValidator.validate "ValAxis.crossBetween", [:between, :midCat], v; @crossBetween = v; end
def to_xml_string(str = '')
- str << '<valAx>'
+ str << '<c:valAx>'
super(str)
- str << '<crossBetween val="' << @crossBetween.to_s << '"/>'
- str << '</valAx>'
+ str << '<c:crossBetween val="' << @crossBetween.to_s << '"/>'
+ str << '</c:valAx>'
end
- # Serializes the value axis
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.valAx {
- super(xml)
- xml.crossBetween :val=>@crossBetween
- }
- end
end
end
diff --git a/lib/axlsx/drawing/val_axis_data.rb b/lib/axlsx/drawing/val_axis_data.rb
index b974b5d1..c28e8a58 100644
--- a/lib/axlsx/drawing/val_axis_data.rb
+++ b/lib/axlsx/drawing/val_axis_data.rb
@@ -4,38 +4,19 @@ module Axlsx
class ValAxisData < CatAxisData
def to_xml_string(str = '')
- str << '<val>'
- str << '<numRef>'
- str << '<f>' << Axlsx::cell_range(@list) << '</f>'
- str << '<numCache>'
- str << '<formatCode>General</formatCode>'
- str << '<ptCount val="' << size.to_s << '"/>'
+ str << '<c:val>'
+ str << '<c:numRef>'
+ str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
+ str << '<c:numCache>'
+ str << '<c:formatCode>General</c:formatCode>'
+ str << '<c:ptCount val="' << size.to_s << '"/>'
each_with_index do |item, index|
v = item.is_a?(Cell) ? item.value.to_s : item
- str << '<pt idx="' << index.to_s << '"><v>' << v << '</v></pt>'
+ str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
end
- str << '</numCache>'
- str << '</numRef>'
- str << '</val>'
- end
-
- # Serializes the value axis data
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml.val {
- xml.numRef {
- xml.f Axlsx::cell_range(@list)
- xml.numCache {
- xml.formatCode 'General'
- xml.ptCount :val=>size
- each_with_index do |item, index|
- v = item.is_a?(Cell) ? item.value : item
- xml.pt(:idx=>index) { xml.v v }
- end
- }
- }
- }
+ str << '</c:numCache>'
+ str << '</c:numRef>'
+ str << '</c:val>'
end
end
diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb
index ee2739b4..c2af0953 100644
--- a/lib/axlsx/drawing/view_3D.rb
+++ b/lib/axlsx/drawing/view_3D.rb
@@ -72,27 +72,14 @@ module Axlsx
def to_xml_string(str = '')
str << '<c:view3D>'
- str << '<c:rotX val="' << @rotX << '"/>' unless @rotX.nil?
- str << '<c:hPercent val="' << @hPercent << '"/>' unless @hPercent.nil?
- str << '<c:rotY val="' << @rotY << '"/>' unless @rotY.nil?
- str << '<c:depthPercent val="' << @depthPercent << '"/>' unless @depthPercent.nil?
- str << '<c:rAngAx val="' << @rAngAx << '"/>' unless @rAngAx.nil?
- str << '<c:perspective val="' << @perspective << '"/>' unless @perspective.nil?
+ str << '<c:rotX val="' << @rotX.to_s << '"/>' unless @rotX.nil?
+ str << '<c:hPercent val="' << @hPercent.to_s << '"/>' unless @hPercent.nil?
+ str << '<c:rotY val="' << @rotY.to_s << '"/>' unless @rotY.nil?
+ str << '<c:depthPercent val="' << @depthPercent.to_s << '"/>' unless @depthPercent.nil?
+ str << '<c:rAngAx val="' << @rAngAx.to_s << '"/>' unless @rAngAx.nil?
+ str << '<c:perspective val="' << @perspective.to_s << '"/>' unless @perspective.nil?
str << '</c:view3D>'
end
- # Serializes the view3D properties
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
- # @return [String]
- def to_xml(xml)
- xml[:c].view3D {
- xml[:c].rotX :val=>@rotX unless @rotX.nil?
- xml[:c].hPercent :val=>@hPercent unless @hPercent.nil?
- xml[:c].rotY :val=>@rotY unless @rotY.nil?
- xml[:c].depthPercent :val=>@depthPercent unless @depthPercent.nil?
- xml[:c].rAngAx :val=>@rAngAx unless @rAngAx.nil?
- xml[:c].perspective :val=>@perspective unless @perspective.nil?
- }
- end
end
end
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 9bab4269..3ab7b99a 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -139,7 +139,9 @@ module Axlsx
# p.validate.each { |error| puts error.message }
def validate
errors = []
- parts.each { |part| errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil? }
+ parts.each do |part|
+ errors.concat validate_single_doc(part[:schema], part[:doc]) unless part[:schema].nil?
+ end
errors
end
@@ -171,7 +173,7 @@ module Axlsx
def parts
@parts = [
{:entry => RELS_PN, :doc => relationships.to_xml_string, :schema => RELS_XSD},
- {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml, :schema => SML_XSD},
+ {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml_string, :schema => SML_XSD},
{:entry => CORE_PN, :doc => @core.to_xml_string, :schema => CORE_XSD},
{:entry => APP_PN, :doc => @app.to_xml_string, :schema => APP_XSD},
{:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships.to_xml_string, :schema => RELS_XSD},
@@ -180,7 +182,7 @@ module Axlsx
]
workbook.drawings.each do |drawing|
@parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD}
- @parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml, :schema => DRAWING_XSD}
+ @parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD}
end
workbook.tables.each do |table|
@@ -188,7 +190,7 @@ module Axlsx
end
workbook.charts.each do |chart|
- @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml, :schema => DRAWING_XSD}
+ @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD}
end
workbook.images.each do |image|
@@ -215,7 +217,6 @@ module Axlsx
def validate_single_doc(schema, doc)
schema = Nokogiri::XML::Schema(File.open(schema))
doc = Nokogiri::XML(doc)
-
errors = []
schema.validate(doc).each do |error|
errors << error
diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb
index 4321c7e1..89a09ce1 100644
--- a/lib/axlsx/rels/relationship.rb
+++ b/lib/axlsx/rels/relationship.rb
@@ -51,7 +51,7 @@ module Axlsx
# @param [String] str
# @param [Integer] rId the id for this relationship
# @return [String]
- def to_xml_string(str = '', rId)
+ def to_xml_string(rId, str = '')
h = self.instance_values
h[:Id] = 'rId' << rId.to_s
str << '<Relationship '
diff --git a/lib/axlsx/rels/relationships.rb b/lib/axlsx/rels/relationships.rb
index 06bd4934..e0d6ea13 100644
--- a/lib/axlsx/rels/relationships.rb
+++ b/lib/axlsx/rels/relationships.rb
@@ -14,7 +14,7 @@ require 'axlsx/rels/relationship.rb'
def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << '<Relationships xmlns="' << RELS_R << '">'
- each_with_index { |rel, index| rel.to_xml_string(str, index+1) }
+ each_with_index { |rel, index| rel.to_xml_string(index+1, str) }
str << '</Relationships>'
end
# Serializes the relationships document.
diff --git a/lib/axlsx/stylesheet/border.rb b/lib/axlsx/stylesheet/border.rb
index 43acbdca..99bd410a 100644
--- a/lib/axlsx/stylesheet/border.rb
+++ b/lib/axlsx/stylesheet/border.rb
@@ -42,6 +42,19 @@ module Axlsx
# @see outline
def outline=(v) Axlsx::validate_boolean v; @outline = v end
+ def to_xml_string(str = '')
+ str << '<border '
+ h = self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '>'
+ [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
+ @prs.select { |pr| pr.name == k }.each do |part|
+ part.to_xml_string(str)
+ end
+ end
+ 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)
diff --git a/lib/axlsx/stylesheet/border_pr.rb b/lib/axlsx/stylesheet/border_pr.rb
index 62fe3bab..b15e3918 100644
--- a/lib/axlsx/stylesheet/border_pr.rb
+++ b/lib/axlsx/stylesheet/border_pr.rb
@@ -1,22 +1,22 @@
# encoding: UTF-8
module Axlsx
- # A border part.
+ # A border part.
class BorderPr
-
+
# @return [Color] The color of this border part.
attr_reader :color
- # @return [Symbol] The syle of this border part.
- # @note
+ # @return [Symbol] The syle of this border part.
+ # @note
# The following are allowed
- # :none
+ # :none
# :thin
# :medium
# :dashed
# :dotted
# :thick
# :double
- # :hair
+ # :hair
# :mediumDashed
# :dashDot
# :mediumDashDot
@@ -26,7 +26,7 @@ module Axlsx
attr_reader :style
# @return [Symbol] The name of this border part
- # @note
+ # @note
# The following are allowed
# :start
# :end
@@ -38,7 +38,7 @@ module Axlsx
# :vertical
# :horizontal
attr_reader :name
-
+
# Creates a new Border Part Object
# @option options [Color] color
# @option options [Symbol] name
@@ -53,17 +53,23 @@ module Axlsx
# @see name
def name=(v) RestrictionValidator.validate "BorderPr.name", [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal], v; @name = v end
# @see color
- def color=(v) DataTypeValidator.validate(:color, Color, v); @color = v end
+ def color=(v) DataTypeValidator.validate(:color, Color, v); @color = v end
# @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
+ 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 0a1ce60a..50b0e2d4 100644
--- a/lib/axlsx/stylesheet/cell_alignment.rb
+++ b/lib/axlsx/stylesheet/cell_alignment.rb
@@ -1,11 +1,11 @@
# encoding: UTF-8
module Axlsx
# CellAlignment stores information about the cell alignment of a style Xf Object.
- # @note Using Styles#add_style is the recommended way to manage cell alignment.
+ # @note Using Styles#add_style is the recommended way to manage cell alignment.
# @see Styles#add_style
class CellAlignment
# The horizontal alignment of the cell.
- # @note
+ # @note
# The horizontal cell alignement style must be one of
# :general
# :left
@@ -36,7 +36,7 @@ module Axlsx
# Indicate if the text of the cell should wrap
# @return [Boolean]
attr_reader :wrapText
-
+
# The amount of indent
# @return [Integer]
attr_reader :indent
@@ -54,12 +54,12 @@ module Axlsx
attr_reader :shrinkToFit
# The reading order of the text
- # 0 Context Dependent
+ # 0 Context Dependent
# 1 Left-to-Right
# 2 Right-to-Left
# @return [Integer]
attr_reader :readingOrder
-
+
# Create a new cell_alignment object
# @option options [Symbol] horizontal
# @option options [Symbol] vertical
@@ -74,33 +74,38 @@ module Axlsx
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
- end
-
+ end
+
# @see horizontal
- def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
+ def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
# @see vertical
- def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
+ def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
# @see textRotation
- def textRotation=(v) Axlsx::validate_unsigned_int v; @textRotation = v end
+ def textRotation=(v) Axlsx::validate_unsigned_int v; @textRotation = v end
# @see wrapText
- def wrapText=(v) Axlsx::validate_boolean v; @wrapText = v end
+ def wrapText=(v) Axlsx::validate_boolean v; @wrapText = v end
# @see indent
- def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
+ def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
# @see relativeIndent
- def relativeIndent=(v) Axlsx::validate_int v; @relativeIndent = v end
+ def relativeIndent=(v) Axlsx::validate_int v; @relativeIndent = v end
# @see justifyLastLine
- def justifyLastLine=(v) Axlsx::validate_boolean v; @justifyLastLine = v end
+ def justifyLastLine=(v) Axlsx::validate_boolean v; @justifyLastLine = v end
# @see shrinkToFit
- def shrinkToFit=(v) Axlsx::validate_boolean v; @shrinkToFit = v end
+ def shrinkToFit=(v) Axlsx::validate_boolean v; @shrinkToFit = v end
# @see readingOrder
- def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end
+ def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end
+ 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)
+ 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 89d85289..b874b214 100644
--- a/lib/axlsx/stylesheet/cell_protection.rb
+++ b/lib/axlsx/stylesheet/cell_protection.rb
@@ -4,7 +4,7 @@ module Axlsx
# @note Using Styles#add_style is the recommended way to manage cell protection.
# @see Styles#add_style
class CellProtection
-
+
# specifies locking for cells that have the style containing this protection
# @return [Boolean]
attr_reader :hidden
@@ -23,9 +23,15 @@ module Axlsx
end
# @see hidden
- def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
+ def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
# @see locked
- def locked=(v) Axlsx::validate_boolean v; @locked = v end
+ def locked=(v) Axlsx::validate_boolean v; @locked = v end
+
+ 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.
diff --git a/lib/axlsx/stylesheet/cell_style.rb b/lib/axlsx/stylesheet/cell_style.rb
index 0a40ab13..22694ae1 100644
--- a/lib/axlsx/stylesheet/cell_style.rb
+++ b/lib/axlsx/stylesheet/cell_style.rb
@@ -7,7 +7,7 @@ module Axlsx
# The name of this cell style
# @return [String]
attr_reader :name
-
+
# The formatting record id this named style utilizes
# @return [Integer]
# @see Axlsx::Xf
@@ -55,6 +55,13 @@ module Axlsx
# @see customBuiltin
def customBuiltin=(v) Axlsx::validate_boolean v; @customBuiltin = v end
+
+ 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]
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb
index 2a08fd3c..daedc9ed 100644
--- a/lib/axlsx/stylesheet/color.rb
+++ b/lib/axlsx/stylesheet/color.rb
@@ -61,10 +61,10 @@ 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
- def to_xml_string
- str = "<color "
+ def to_xml_string(str = '')
+ str << "<color "
self.instance_values.each do |key, value|
- str << key << '="' << value.to_s << '" '
+ str << key.to_s << '="' << value.to_s << '" '
end
str << "/>"
end
diff --git a/lib/axlsx/stylesheet/fill.rb b/lib/axlsx/stylesheet/fill.rb
index 4dccaa8a..d6fde1c7 100644
--- a/lib/axlsx/stylesheet/fill.rb
+++ b/lib/axlsx/stylesheet/fill.rb
@@ -12,12 +12,18 @@ module Axlsx
attr_reader :fill_type
# Creates a new Fill object
- # @param [PatternFill, GradientFill] fill_type
+ # @param [PatternFill, GradientFill] fill_type
# @raise [ArgumentError] if the fill_type parameter is not a PatternFill or a GradientFill instance
def initialize(fill_type)
self.fill_type = fill_type
end
+
+ 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]
diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb
index 1d9bc5d4..4bbcb487 100644
--- a/lib/axlsx/stylesheet/font.rb
+++ b/lib/axlsx/stylesheet/font.rb
@@ -7,7 +7,7 @@ module Axlsx
# The name of the font
# @return [String]
attr_reader :name
-
+
# The charset of the font
# @return [Integer]
# @note
@@ -32,9 +32,9 @@ module Axlsx
# 238 EASTEUROPE_CHARSET
# 255 OEM_CHARSET
attr_reader :charset
-
+
# The font's family
- # @note
+ # @note
# The following are defined OOXML specification
# 0 Not applicable.
# 1 Roman
@@ -107,13 +107,13 @@ module Axlsx
end
end
# @see name
- def name=(v) Axlsx::validate_string v; @name = v end
+ def name=(v) Axlsx::validate_string v; @name = v end
# @see charset
def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
# @see family
def family=(v) Axlsx::validate_unsigned_int v; @family = v end
# @see b
- def b=(v) Axlsx::validate_boolean v; @b = v end
+ def b=(v) Axlsx::validate_boolean v; @b = v end
# @see i
def i=(v) Axlsx::validate_boolean v; @i = v end
# @see u
@@ -123,7 +123,7 @@ module Axlsx
# @see outline
def outline=(v) Axlsx::validate_boolean v; @outline = v end
# @see shadow
- def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
+ def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
# @see condense
def condense=(v) Axlsx::validate_boolean v; @condense = v end
# @see extend
@@ -133,13 +133,22 @@ module Axlsx
# @see sz
def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end
+
+ def to_xml_string(str = '')
+ str << '<font>'
+ instance_values.each do |k, v|
+ v.is_a?(Color) ? v.to_xml_string(str) : (str << '<' << k.to_s << ' val="' << v.to_s << '"/>')
+ 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})
+ v.is_a?(Color) ? v.to_xml(xml) : xml.send(k, {:val => v})
end
}
end
diff --git a/lib/axlsx/stylesheet/gradient_fill.rb b/lib/axlsx/stylesheet/gradient_fill.rb
index 6090b570..2a789c6f 100644
--- a/lib/axlsx/stylesheet/gradient_fill.rb
+++ b/lib/axlsx/stylesheet/gradient_fill.rb
@@ -1,11 +1,11 @@
# encoding: UTF-8
module Axlsx
# A GradientFill defines the color and positioning for gradiant cell fill.
- # @see Open Office XML Part 1 §18.8.24
+ # @see Open Office XML Part 1 §18.8.24
class GradientFill
# The type of gradient.
- # @note
+ # @note
# valid options are
# :linear
# :path
@@ -26,7 +26,7 @@ module Axlsx
# Percentage format top
# @return [Float]
- attr_reader :top
+ attr_reader :top
# Percentage format bottom
# @return [Float]
@@ -35,7 +35,7 @@ module Axlsx
# Collection of stop objects
# @return [SimpleTypedList]
attr_reader :stop
-
+
# Creates a new GradientFill object
# @option options [Symbol] type
# @option options [Float] degree
@@ -52,18 +52,27 @@ module Axlsx
end
# @see type
- def type=(v) Axlsx::validate_gradient_type v; @type = v end
+ def type=(v) Axlsx::validate_gradient_type v; @type = v end
# @see degree
- def degree=(v) Axlsx::validate_float v; @degree = v end
+ def degree=(v) Axlsx::validate_float v; @degree = v end
# @see left
- def left=(v) DataTypeValidator.validate "GradientFill.left", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @left = v end
+ def left=(v) DataTypeValidator.validate "GradientFill.left", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @left = v end
# @see right
- def right=(v) DataTypeValidator.validate "GradientFill.right", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @right = v end
+ def right=(v) DataTypeValidator.validate "GradientFill.right", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @right = v end
# @see top
- def top=(v) DataTypeValidator.validate "GradientFill.top", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @top = v end
+ def top=(v) DataTypeValidator.validate "GradientFill.top", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @top = v end
# @see bottom
- def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end
+ def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end
+
+ def to_xml_string(str = '')
+ str << '<gradientFill'
+ h = self.instance_values.reject { |k,v| k.to_sym == :stop }
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '>'
+ @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]
diff --git a/lib/axlsx/stylesheet/gradient_stop.rb b/lib/axlsx/stylesheet/gradient_stop.rb
index a05e6d33..aca26b79 100644
--- a/lib/axlsx/stylesheet/gradient_stop.rb
+++ b/lib/axlsx/stylesheet/gradient_stop.rb
@@ -1,7 +1,7 @@
# encoding: UTF-8
module Axlsx
# The GradientStop object represents a color point in a gradient.
- # @see Open Office XML Part 1 §18.8.24
+ # @see Open Office XML Part 1 §18.8.24
class GradientStop
# The color for this gradient stop
# @return [Color]
@@ -23,8 +23,13 @@ module Axlsx
# @see color
def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color=v end
# @see position
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
+ def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
+ 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]
diff --git a/lib/axlsx/stylesheet/num_fmt.rb b/lib/axlsx/stylesheet/num_fmt.rb
index 261d5bb3..8c74382f 100644
--- a/lib/axlsx/stylesheet/num_fmt.rb
+++ b/lib/axlsx/stylesheet/num_fmt.rb
@@ -1,11 +1,11 @@
# encoding: UTF-8
module Axlsx
- # A NumFmt object defines an identifier and formatting code for data in cells.
+ # A NumFmt object defines an identifier and formatting code for data in cells.
# @note The recommended way to manage styles is Styles#add_style
class NumFmt
# @return [Integer] An unsinged integer referencing a standard or custom number format.
# @note
- # These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
+ # These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
# 1 0
# 2 0.00
# 3 #,##0
@@ -40,7 +40,7 @@ module Axlsx
# @see Axlsx
attr_reader :numFmtId
- # @return [String] The formatting to use for this number format.
+ # @return [String] The formatting to use for this number format.
# @see http://support.microsoft.com/kb/264372
attr_reader :formatCode
def initialize(options={})
@@ -56,9 +56,15 @@ module Axlsx
# @see formatCode
def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
+ 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
+ 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 79910ede..32d54d83 100644
--- a/lib/axlsx/stylesheet/pattern_fill.rb
+++ b/lib/axlsx/stylesheet/pattern_fill.rb
@@ -7,15 +7,15 @@ module Axlsx
# The color to use for the the background in solid fills.
# @return [Color]
- attr_reader :fgColor
+ attr_reader :fgColor
# The color to use for the background of the fill when the type is not solid.
# @return [Color]
attr_reader :bgColor
# The pattern type to use
- # @note
- # patternType must be one of
+ # @note
+ # patternType must be one of
# :none
# :solid
# :mediumGray
@@ -53,14 +53,34 @@ module Axlsx
# @see bgColor
def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
# @see patternType
- def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
+ def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
+
+ def to_xml_string(str = '')
+ str << '<patternFill patternType="' << patternType.to_s << '">'
+ if fgColor.is_a?(Color)
+ str << "<fgColor "
+ fgColor.instance_values.each do |key, value|
+ str << key.to_s << '="' << value.to_s << '" '
+ end
+ str << "/>"
+ end
+
+ if bgColor.is_a?(Color)
+ str << "<bgColor "
+ bgColor.instance_values.each do |key, value|
+ str << key.to_s << '="' << value.to_s << '" '
+ end
+ str << "/>"
+ end
+ 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) }
+ 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
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb
index a05067cd..d8d33fa1 100644
--- a/lib/axlsx/stylesheet/styles.rb
+++ b/lib/axlsx/stylesheet/styles.rb
@@ -250,6 +250,14 @@ module Axlsx
cellXfs << xf
end
+ def to_xml_string(str = '')
+ str << '<styleSheet xmlns="' << XML_NS << '">'
+ [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
+ self.instance_values[key.to_s].to_xml_string(str) unless self.instance_values[key.to_s].nil?
+ end
+ str << '</styleSheet>'
+ end
+
# Serializes the styles document
# @return [String]
def to_xml()
diff --git a/lib/axlsx/stylesheet/table_style.rb b/lib/axlsx/stylesheet/table_style.rb
index 4397cffb..3184c042 100644
--- a/lib/axlsx/stylesheet/table_style.rb
+++ b/lib/axlsx/stylesheet/table_style.rb
@@ -36,6 +36,17 @@ module Axlsx
# @see table
def table=(v) Axlsx::validate_boolean v; @table=v end
+
+ def to_xml_string(str = '')
+ attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
+ attr[:count] = self.size
+ str << '<tableStyle '
+ str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '>'
+ each { |table_style_el| table_style_el.to_xml_string(str) }
+ 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]
diff --git a/lib/axlsx/stylesheet/table_style_element.rb b/lib/axlsx/stylesheet/table_style_element.rb
index a8901f0b..a5cf4c48 100644
--- a/lib/axlsx/stylesheet/table_style_element.rb
+++ b/lib/axlsx/stylesheet/table_style_element.rb
@@ -1,7 +1,7 @@
# encoding: UTF-8
module Axlsx
- # an element of style that belongs to a table style.
- # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
+ # an element of style that belongs to a table style.
+ # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
class TableStyleElement
# The type of style element. The following type are allowed
# :wholeTable
@@ -39,7 +39,7 @@ module Axlsx
# @return [Integer]
attr_reader :size
- # The dxfId this style element points to
+ # The dxfId this style element points to
# @return [Integer]
attr_reader :dxfId
@@ -62,6 +62,12 @@ module Axlsx
# @see dxfId
def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
+ 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]
diff --git a/lib/axlsx/stylesheet/table_styles.rb b/lib/axlsx/stylesheet/table_styles.rb
index f0e9c904..5474c165 100644
--- a/lib/axlsx/stylesheet/table_styles.rb
+++ b/lib/axlsx/stylesheet/table_styles.rb
@@ -11,13 +11,13 @@ module Axlsx
# The default pivot table style. The default value is 'PivotStyleLight6'
# @return [String]
attr_reader :defaultPivotStyle
-
+
# Creates a new TableStyles object that is a container for TableStyle objects
# @option options [String] defaultTableStyle
# @option options [String] defaultPivotStyle
def initialize(options={})
@defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
- @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
+ @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
super TableStyle
end
# @see defaultTableStyle
@@ -25,6 +25,17 @@ module Axlsx
# @see defaultPivotStyle
def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
+
+ def to_xml_string(str = '')
+ attr = self.instance_values.reject {|k, v| ![:defaultTableStyle, :defaultPivotStyle].include?(k.to_sym) }
+ attr[:count] = self.size
+ str << '<tableStyles '
+ str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '>'
+ each { |table_style| table_style.to_xml_string(str) }
+ 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]
diff --git a/lib/axlsx/stylesheet/xf.rb b/lib/axlsx/stylesheet/xf.rb
index 7b55336b..e8e36301 100644
--- a/lib/axlsx/stylesheet/xf.rb
+++ b/lib/axlsx/stylesheet/xf.rb
@@ -22,7 +22,7 @@ module Axlsx
# index (0 based) of the font to be used in this style
# @return [Integer]
attr_reader :fontId
-
+
# index (0 based) of the fill to be used in this style
# @return [Integer]
attr_reader :fillId
@@ -50,7 +50,7 @@ module Axlsx
# indicates if the fontId should be applied
# @return [Boolean]
attr_reader :applyFont
-
+
# indicates if the fillId should be applied
# @return [Boolean]
attr_reader :applyFill
@@ -75,7 +75,7 @@ module Axlsx
# @option options [Integer] xfId
# @option options [Boolean] quotePrefix
# @option options [Boolean] pivotButton
- # @option options [Boolean] applyNumberFormat
+ # @option options [Boolean] applyNumberFormat
# @option options [Boolean] applyFont
# @option options [Boolean] applyFill
# @option options [Boolean] applyBorder
@@ -87,8 +87,8 @@ module Axlsx
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
- end
-
+ end
+
# @see Xf#alignment
def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
@@ -96,35 +96,45 @@ module Axlsx
def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
# @see numFmtId
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
+ def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
# @see fontId
- def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
+ def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
# @see fillId
- def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
+ def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
# @see borderId
- def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
+ def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
# @see xfId
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
+ def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
# @see quotePrefix
- def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
+ def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
# @see pivotButton
- def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
+ def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
# @see applyNumberFormat
- def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
+ def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
# @see applyFont
- def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
+ def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
# @see applyFill
- def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
+ def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
# @see applyBorder
- def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
+ def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
# @see applyAlignment
- def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
+ def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
# @see applyProtection
- def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
+ def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
+
+ def to_xml_string(str = '')
+ str << '<xf '
+ h = instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ str << '>'
+ alignment.to_xml_string(str) if self.alignment
+ protection.to_xml_string(str) if self.protection
+ str << '</xf>'
+ end
# Serializes the xf elemen
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb
index ce34a9bb..8fc4795a 100644
--- a/lib/axlsx/util/simple_typed_list.rb
+++ b/lib/axlsx/util/simple_typed_list.rb
@@ -1,6 +1,6 @@
# encoding: UTF-8
module Axlsx
- # A SimpleTypedList is a type restrictive collection that allows some of the methods from Array and supports basic xml serialization.
+ # A SimpleTypedList is a type restrictive collection that allows some of the methods from Array and supports basic xml serialization.
# @private
class SimpleTypedList
# The class constants of allowed types
@@ -12,14 +12,14 @@ module Axlsx
attr_reader :locked_at
# The tag name to use when serializing this object
- # by default the parent node for all items in the list is the classname of the first allowed type with the first letter in lowercase.
+ # by default the parent node for all items in the list is the classname of the first allowed type with the first letter in lowercase.
# @return [String]
attr_reader :serialize_as
# Creats a new typed list
# @param [Array, Class] type An array of Class objects or a single Class object
# @param [String] serialize The tag name to use in serialization
- # @raise [ArgumentError] if all members of type are not Class objects
+ # @raise [ArgumentError] if all members of type are not Class objects
def initialize type, serialize_as=nil
if type.is_a? Array
type.each { |item| raise ArgumentError, "All members of type must be Class objects" unless item.is_a? Class }
@@ -39,7 +39,7 @@ module Axlsx
@locked_at = @list.size
self
end
-
+
def to_ary
@list
end
@@ -58,7 +58,7 @@ module Axlsx
def <<(v)
DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
@list << v
- @list.size - 1
+ @list.size - 1
end
# alternate of << method
@@ -104,14 +104,14 @@ module Axlsx
return false unless @locked_at.is_a? Fixnum
index < @locked_at
end
-
+
# override the equality method so that this object can be compared to a simple array.
# if this object's list is equal to the specifiec array, we return true.
def ==(v)
v == @list
end
# method_mission override to pass allowed methods to the list.
- # @note
+ # @note
# the following methods are not allowed
# :replace
# :insert
@@ -140,15 +140,23 @@ module Axlsx
DELEGATES = Array.instance_methods - self.instance_methods - DESTRUCTIVE
DELEGATES.each do |method|
- class_eval %{
+ class_eval %{
def #{method}(*args, &block)
@list.send(:#{method}, *args, &block)
end
}
end
+ def to_xml_string(str = '')
+ classname = @allowed_types[0].name.split('::').last
+ el_name = serialize_as || (classname[0,1].downcase + classname[1..-1])
+ str << '<' << el_name << ' count="' << @list.size.to_s << '">'
+ @list.each { |item| item.to_xml_string(str) }
+ str << '</' << el_name << '>'
+ end
+
# Serializes the list
- # If the serialize_as property is set, it is used as the parent node name.
+ # If the serialize_as property is set, it is used as the parent node name.
# If the serialize_as property is nil, the first item in the list of allowed_types will be used, having the first letter of the class changed to lower case.
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
# @return [String]
@@ -159,6 +167,7 @@ module Axlsx
@list.each { |item| item.to_xml(xml) }
}
end
+
end
diff --git a/lib/schema/dc.xsd b/lib/schema/dc.xsd
index b8315e7e..fffd1522 100644
--- a/lib/schema/dc.xsd
+++ b/lib/schema/dc.xsd
@@ -12,7 +12,7 @@
Created 2003-04-02
- Created by
+ Created by
Tim Cole ([email protected])
Tom Habing ([email protected])
@@ -23,14 +23,14 @@
This schema declares XML elements for the 15 DC elements from the
http://purl.org/dc/elements/1.1/ namespace.
- It defines a complexType SimpleLiteral which permits mixed content
+ It defines a complexType SimpleLiteral which permits mixed content
and makes the xml:lang attribute available. It disallows child elements by
use of minOcccurs/maxOccurs.
However, this complexType does permit the derivation of other complexTypes
which would permit child elements.
- All elements are declared as substitutable for the abstract element any,
+ All elements are declared as substitutable for the abstract element any,
which means that the default type for all elements is dc:SimpleLiteral.
</xs:documentation>
@@ -49,7 +49,7 @@
It permits text content only with optional
xml:lang attribute.
Text is allowed because mixed="true", but sub-elements
- are disallowed because minOccurs="0" and maxOccurs="0"
+ are disallowed because minOccurs="0" and maxOccurs="0"
are on the xs:any tag.
This complexType allows for restriction or extension permitting
@@ -89,7 +89,7 @@
<xs:annotation>
<xs:documentation xml:lang="en">
This group is included as a convenience for schema authors
- who need to refer to all the elements in the
+ who need to refer to all the elements in the
http://purl.org/dc/elements/1.1/ namespace.
</xs:documentation>
</xs:annotation>
diff --git a/lib/schema/dcmitype.xsd b/lib/schema/dcmitype.xsd
index 54d9da00..69fcb5bd 100644
--- a/lib/schema/dcmitype.xsd
+++ b/lib/schema/dcmitype.xsd
@@ -5,6 +5,8 @@
elementFormDefault="qualified"
attributeFormDefault="unqualified">
+ <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>
+
<xs:annotation>
<xs:documentation xml:lang="en">
DCMI Type Vocabulary XML Schema
@@ -12,7 +14,7 @@
Created 2003-04-02
- Created by
+ Created by
Tim Cole ([email protected])
Tom Habing ([email protected])
@@ -24,7 +26,7 @@
the allowable values for the DCMI Type Vocabulary.
</xs:documentation>
-
+
</xs:annotation>
@@ -43,7 +45,7 @@
<xs:enumeration value="Text"/>
<xs:enumeration value="PhysicalObject"/>
</xs:restriction>
- </xs:simpleType>
+ </xs:simpleType>
</xs:union>
</xs:simpleType>
diff --git a/lib/schema/dcterms.xsd b/lib/schema/dcterms.xsd
index 055a6edf..da22580e 100644
--- a/lib/schema/dcterms.xsd
+++ b/lib/schema/dcterms.xsd
@@ -14,7 +14,7 @@
Created 2003-04-02
- Created by
+ Created by
Tim Cole ([email protected])
Tom Habing ([email protected])
@@ -24,7 +24,7 @@
This schema declares XML elements for the DC elements and
DC element refinements from the http://purl.org/dc/terms/ namespace.
-
+
It reuses the complexType dc:SimpleLiteral, imported from the dc.xsd
schema, which permits simple element content, and makes the xml:lang
attribute available.
@@ -32,22 +32,22 @@
This complexType permits the derivation of other complexTypes
which would permit child elements.
- DC elements are declared as substitutable for the abstract element dc:any, and
- DC element refinements are defined as substitutable for the base elements
+ DC elements are declared as substitutable for the abstract element dc:any, and
+ DC element refinements are defined as substitutable for the base elements
which they refine.
- This means that the default type for all XML elements (i.e. all DC elements and
+ This means that the default type for all XML elements (i.e. all DC elements and
element refinements) is dc:SimpleLiteral.
Encoding schemes are defined as complexTypes which are restrictions
- of the dc:SimpleLiteral complexType. These complexTypes restrict
+ of the dc:SimpleLiteral complexType. These complexTypes restrict
values to an appropriates syntax or format using data typing,
regular expressions, or enumerated lists.
-
- In order to specify one of these encodings an xsi:type attribute must
+
+ In order to specify one of these encodings an xsi:type attribute must
be used in the instance document.
- Also, note that one shortcoming of this approach is that any type can be
+ Also, note that one shortcoming of this approach is that any type can be
applied to any of the elements or refinements. There is no convenient way
to restrict types to specific elements using this approach.
@@ -184,7 +184,7 @@
<xs:attribute ref="xml:lang" use="prohibited"/>
</xs:restriction>
</xs:simpleContent>
- </xs:complexType>
+ </xs:complexType>
<xs:complexType name="DCMIType">
<xs:simpleContent>
@@ -217,7 +217,7 @@
<xs:attribute ref="xml:lang" use="prohibited"/>
</xs:restriction>
</xs:simpleContent>
- </xs:complexType>
+ </xs:complexType>
<xs:complexType name="ISO639-2">
<xs:simpleContent>
@@ -300,9 +300,9 @@
<xs:annotation>
<xs:documentation xml:lang="en">
This group is included as a convenience for schema authors
- who need to refer to all the DC elements and element refinements
- in the http://purl.org/dc/elements/1.1/ and
- http://purl.org/dc/terms namespaces.
+ who need to refer to all the DC elements and element refinements
+ in the http://purl.org/dc/elements/1.1/ and
+ http://purl.org/dc/terms namespaces.
N.B. Refinements available via substitution groups.
</xs:documentation>
</xs:annotation>
@@ -312,7 +312,7 @@
<xs:element ref="dc:any" />
</xs:choice>
</xs:sequence>
- </xs:group>
+ </xs:group>
<xs:complexType name="elementOrRefinementContainer">
<xs:annotation>
diff --git a/lib/schema/opc-coreProperties.xsd b/lib/schema/opc-coreProperties.xsd
index a2d6cdac..2b7d5c1c 100644
--- a/lib/schema/opc-coreProperties.xsd
+++ b/lib/schema/opc-coreProperties.xsd
@@ -2,13 +2,17 @@
<xs:schema targetNamespace="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:dcterms="http://purl.org/dc/terms/" elementFormDefault="qualified" blockDefault="#all">
+ xmlns:dcterms="http://purl.org/dc/terms/"
+ elementFormDefault="qualified" blockDefault="#all">
<xs:import namespace="http://purl.org/dc/elements/1.1/"
schemaLocation="dc.xsd"/>
+
<xs:import namespace="http://purl.org/dc/terms/"
schemaLocation="dcterms.xsd"/>
- <xs:import id="xml" namespace="http://www.w3.org/XML/1998/namespace"/>
+
+ <xs:import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="xml.xsd"/>
<xs:element name="coreProperties" type="CT_CoreProperties"/>
diff --git a/lib/schema/xml.xsd b/lib/schema/xml.xsd
index d662b423..4f5ecc8b 100644
--- a/lib/schema/xml.xsd
+++ b/lib/schema/xml.xsd
@@ -1,6 +1,5 @@
<?xml version='1.0'?>
-<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" >
-<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
+<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation>
@@ -8,7 +7,7 @@
http://www.w3.org/TR/REC-xml for information about this namespace.
This schema document describes the XML namespace, in a form
- suitable for import by other schema documents.
+ suitable for import by other schema documents.
Note that local names in this namespace are intended to be defined
only by the World Wide Web Consortium or its subgroups. The
@@ -26,16 +25,16 @@
is a language code for the natural language of the content of
any element; its value is inherited. This name is reserved
by virtue of its definition in the XML specification.
-
+
space (as an attribute name): denotes an attribute whose
value is a keyword indicating what whitespace processing
discipline is intended for the content of the element; its
value is inherited. This name is reserved by virtue of its
definition in the XML specification.
- Father (in any context at all): denotes Jon Bosak, the chair of
- the original XML Working Group. This name is reserved by
- the following decision of the W3C XML Plenary and
+ Father (in any context at all): denotes Jon Bosak, the chair of
+ the original XML Working Group. This name is reserved by
+ the following decision of the W3C XML Plenary and
XML Coordination groups:
In appreciation for his vision, leadership and dedication
@@ -64,7 +63,7 @@
&lt;type . . .>
. . .
&lt;attributeGroup ref="xml:specialAttrs"/>
-
+
will define a type which will schema-validate an instance
element with any of those attributes</xs:documentation>
</xs:annotation>
diff --git a/test/drawing/tc_axis.rb b/test/drawing/tc_axis.rb
index 234eba9c..c627b4d1 100644
--- a/test/drawing/tc_axis.rb
+++ b/test/drawing/tc_axis.rb
@@ -36,4 +36,9 @@ class TestAxis < Test::Unit::TestCase
assert_nothing_raised("accepts valid crosses") { @axis.crosses = :min }
end
+ def test_gridlines
+ assert_raise(ArgumentError, "requires valid gridlines") { @axis.gridlines = 'alice' }
+ assert_nothing_raised("accepts valid crosses") { @axis.gridlines = false }
+ end
+
end
diff --git a/test/drawing/tc_bar_3D_chart.rb b/test/drawing/tc_bar_3D_chart.rb
index 93997730..1f78fa0b 100644
--- a/test/drawing/tc_bar_3D_chart.rb
+++ b/test/drawing/tc_bar_3D_chart.rb
@@ -51,9 +51,9 @@ class TestBar3DChart < Test::Unit::TestCase
assert(@chart.shape == :cone)
end
- def test_to_xml
+ def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@chart.to_xml)
+ doc = Nokogiri::XML(@chart.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb
index c0e938cd..8047c018 100644
--- a/test/drawing/tc_chart.rb
+++ b/test/drawing/tc_chart.rb
@@ -58,9 +58,9 @@ class TestChart < Test::Unit::TestCase
assert_equal(@chart.pn, "charts/chart1.xml")
end
- def test_to_xml
+ def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@chart.to_xml)
+ doc = Nokogiri::XML(@chart.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb
index ac2dddbe..ce77ef9b 100644
--- a/test/drawing/tc_drawing.rb
+++ b/test/drawing/tc_drawing.rb
@@ -67,7 +67,7 @@ class TestDrawing < Test::Unit::TestCase
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@ws.drawing.to_xml)
+ doc = Nokogiri::XML(@ws.drawing.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/drawing/tc_line_3d_chart.rb b/test/drawing/tc_line_3d_chart.rb
index 22dd6158..b419e00a 100644
--- a/test/drawing/tc_line_3d_chart.rb
+++ b/test/drawing/tc_line_3d_chart.rb
@@ -35,7 +35,7 @@ class TestLine3DChart < Test::Unit::TestCase
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@chart.to_xml)
+ doc = Nokogiri::XML(@chart.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb
index 83ed4e1d..78750cbd 100644
--- a/test/drawing/tc_pic.rb
+++ b/test/drawing/tc_pic.rb
@@ -64,7 +64,7 @@ class TestPic < Test::Unit::TestCase
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@image.anchor.drawing.to_xml)
+ doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/drawing/tc_pie_3D_chart.rb b/test/drawing/tc_pie_3D_chart.rb
index 76bf49c5..5ac16e68 100644
--- a/test/drawing/tc_pie_3D_chart.rb
+++ b/test/drawing/tc_pie_3D_chart.rb
@@ -20,7 +20,7 @@ class TestPie3DChart < Test::Unit::TestCase
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@chart.to_xml)
+ doc = Nokogiri::XML(@chart.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/drawing/tc_scatter_chart.rb b/test/drawing/tc_scatter_chart.rb
index 367cf56d..30178649 100644
--- a/test/drawing/tc_scatter_chart.rb
+++ b/test/drawing/tc_scatter_chart.rb
@@ -3,9 +3,20 @@ require 'tc_helper.rb'
class TestScatterChart < Test::Unit::TestCase
def setup
@p = Axlsx::Package.new
- ws = @p.workbook.add_worksheet
- @row = ws.add_row ["one", 1, Time.now]
- @chart = ws.add_chart Axlsx::ScatterChart, :title => "A Title"
+ @chart = nil
+ ws = @p.workbook.add_worksheet do |sheet|
+ sheet.add_row ["First", 1, 5, 7, 9]
+ sheet.add_row ["", 1, 25, 49, 81]
+ sheet.add_row ["Second", 5, 2, 14, 9]
+ sheet.add_row ["", 5, 10, 15, 20]
+ sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart|
+ chart.start_at 0, 4
+ chart.end_at 10, 19
+ chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"]
+ chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"]
+ @chart = chart
+ end
+ end
end
def teardown
@@ -18,9 +29,9 @@ class TestScatterChart < Test::Unit::TestCase
assert(@chart.yValAxis.is_a?(Axlsx::ValAxis), "dependant value axis not created")
end
- def test_to_xml
+ def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
- doc = Nokogiri::XML(@chart.to_xml)
+ doc = Nokogiri::XML(@chart.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb
index 9db37157..ef14e151 100644
--- a/test/stylesheet/tc_styles.rb
+++ b/test/stylesheet/tc_styles.rb
@@ -9,7 +9,7 @@ class TestStyles < Test::Unit::TestCase
def test_valid_document
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(@styles.to_xml)
+ doc = Nokogiri::XML(@styles.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error