summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/stylesheet
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 /lib/axlsx/stylesheet
parent22a341841f191a5aa00e87b1f166b4f25cc67f0a (diff)
downloadcaxlsx-1529fce32449a8454208fded20d83c9ceca810e0.tar.gz
caxlsx-1529fce32449a8454208fded20d83c9ceca810e0.zip
rebuild all serialization to use string concatenation instead of nokogiri.
Diffstat (limited to 'lib/axlsx/stylesheet')
-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
17 files changed, 227 insertions, 89 deletions
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.