summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/stylesheet/dxf.rb
diff options
context:
space:
mode:
authorStephen Pike <[email protected]>2012-04-20 15:05:01 -0400
committerStephen Pike <[email protected]>2012-04-20 15:05:01 -0400
commitf96205df2b10c68d10a2a6882fe77928358ed362 (patch)
treeba6539559d00ae055ece38427d22ad8f64da5e07 /lib/axlsx/stylesheet/dxf.rb
parent6b0c1e3c59e581525161491d85a153a537711370 (diff)
downloadcaxlsx-f96205df2b10c68d10a2a6882fe77928358ed362.tar.gz
caxlsx-f96205df2b10c68d10a2a6882fe77928358ed362.zip
[#33] Add support for Dxf elements to enable conditional formatting
New Dxf class implements 18.8.14. Conditional formatting now "works". Add :type option to add_styles, defaults to :xf when add_styles is called with :dxf type, new styles are not added to the global @styles set. Dxf child elements only exist inside the `<dxf>` chunk. Added tests and an example.
Diffstat (limited to 'lib/axlsx/stylesheet/dxf.rb')
-rw-r--r--lib/axlsx/stylesheet/dxf.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/axlsx/stylesheet/dxf.rb b/lib/axlsx/stylesheet/dxf.rb
new file mode 100644
index 00000000..ccd4cd95
--- /dev/null
+++ b/lib/axlsx/stylesheet/dxf.rb
@@ -0,0 +1,77 @@
+# encoding: UTF-8
+module Axlsx
+ # The Dxf class defines an incremental formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
+ # @see Styles#add_style
+ class Dxf
+ # The order in which the child elements is put in the XML seems to
+ # be important for Excel
+ CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
+ #does not support extList (ExtensionList)
+
+ # The cell alignment for this style
+ # @return [CellAlignment]
+ # @see CellAlignment
+ attr_reader :alignment
+
+ # The cell protection for this style
+ # @return [CellProtection]
+ # @see CellProtection
+ attr_reader :protection
+
+ # the child NumFmt to be used to this style
+ # @return [NumFmt]
+ attr_reader :numFmt
+
+ # the child font to be used for this style
+ # @return [Font]
+ attr_reader :font
+
+ # the child fill to be used in this style
+ # @return [Fill]
+ attr_reader :fill
+
+ # the border to be used in this style
+ # @return [Border]
+ attr_reader :border
+
+ # Creates a new Xf object
+ # @option options [Border] border
+ # @option options [NumFmt] numFmt
+ # @option options [Fill] fill
+ # @option options [Font] font
+ # @option options [CellAlignment] alignment
+ # @option options [CellProtection] protection
+ def initialize(options={})
+ options.each do |o|
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
+ end
+ end
+
+ # @see Dxf#alignment
+ def alignment=(v) DataTypeValidator.validate "Dxf.alignment", CellAlignment, v; @alignment = v end
+ # @see protection
+ def protection=(v) DataTypeValidator.validate "Dxf.protection", CellProtection, v; @protection = v end
+ # @see numFmt
+ def numFmt=(v) DataTypeValidator.validate "Dxf.numFmt", NumFmt, v; @numFmt = v end
+ # @see font
+ def font=(v) DataTypeValidator.validate "Dxf.font", Font, v; @font = v end
+ # @see border
+ def border=(v) DataTypeValidator.validate "Dxf.border", Border, v; @border = v end
+ # @see fill
+ def fill=(v) DataTypeValidator.validate "Dxf.fill", Fill, v; @fill = v end
+
+ # Serializes the object
+ # @param [String] str
+ # @return [String]
+ def to_xml_string(str = '')
+ str << '<dxf>'
+ # Dxf elements have no attributes. All of the instance variables
+ # are child elements.
+ CHILD_ELEMENTS.each do |element|
+ self.send(element).to_xml_string(str) if self.send(element)
+ end
+ str << '</dxf>'
+ end
+
+ end
+end