summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-09-26 22:46:32 +0900
committerRandy Morgan <[email protected]>2012-09-26 22:46:32 +0900
commit37da8ab829c1161a9bacb1153bc3961e200adc59 (patch)
tree3d08f496f1fd4a49e841a89567c926ee32df7459
parent686d90aa265ed3072070a523d6f4c6922c941c05 (diff)
downloadcaxlsx-37da8ab829c1161a9bacb1153bc3961e200adc59.tar.gz
caxlsx-37da8ab829c1161a9bacb1153bc3961e200adc59.zip
implement serialized attributes for filter_column
This pattern feels much cleaner than doing crazy work in to_xml_string. Probably would be better to define serializable attributes as a constant of the class and extract this in to an includable, but for now.. this makes me happy!
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb13
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/filters.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb45
3 files changed, 47 insertions, 29 deletions
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb b/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
index b55ee884..6e8db16e 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
@@ -77,9 +77,20 @@ module Axlsx
# Serialize the object to xml
def to_xml_string(str='')
- str << "<filterColumn colId='#{@col_id}' hiddenButton='#{hidden_button}' showButton='#{show_button}'>"
+ str << "<filterColumn #{serialized_attributes}>"
@filter.to_xml_string(str)
str << "</filterColumn>"
end
+
+ private
+
+ def serialized_attributes(str='')
+ instance_values.each do |key, value|
+ if %(show_button hidden_button col_id).include? key.to_s
+ str << "#{Axlsx.camel(key, false)}='#{value}' "
+ end
+ end
+ str
+ end
end
end
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb
index a71e999c..5b46e087 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb
@@ -25,17 +25,13 @@ module Axlsx
# Flag indicating whether to filter by blank.
# @return [Boolean]
- def blank
- @blank ||= false
- end
+ attr_reader :blank
# Calendar type for date grouped items.
# Used to interpret the values in dateGroupItem.
# This is the calendar type used to evaluate all dates in the filter column,
# even when those dates are not using the same calendar system / date formatting.
- def calendar_type
- @calendar_type ||= CALENDAR_TYPES.first
- end
+ attr_reader :calendar_type
# The filter values in this filters object
def filter_items
@@ -62,7 +58,7 @@ module Axlsx
# Serialize the object to xml
def to_xml_string(str = '')
- str << "<filters blank='#{blank}' calendarType='#{calendar_type}'>"
+ str << "<filters #{serialized_attributes}>"
filter_items.each { |filter| filter.to_xml_string(str) }
date_group_items.each { |date_group_item| date_group_item.to_xml_string(str) }
str << '</filters>'
@@ -87,6 +83,14 @@ module Axlsx
private
+ def serialized_attributes(str='')
+ instance_values.each do |key, value|
+ if %(blank claendar_type).include? key.to_s
+ str << "#{Axlsx.camel(key, false)}='#{value}' "
+ end
+ end
+ str
+ end
# This class expresses a filter criteria value.
class Filter
diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb
index a8f60330..33239868 100644
--- a/lib/axlsx/workbook/worksheet/sheet_pr.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb
@@ -1,20 +1,20 @@
module Axlsx
-#<xsd:complexType name="CT_SheetPr">
-#<xsd:sequence>
-#<xsd:element name="tabColor" type="CT_Color" minOccurs="0" maxOccurs="1"/>
-#<xsd:element name="outlinePr" type="CT_OutlinePr" minOccurs="0" maxOccurs="1"/>
-#<xsd:element name="pageSetUpPr" type="CT_PageSetUpPr" minOccurs="0" maxOccurs="1"/>
-#</xsd:sequence>
-#<xsd:attribute name="syncHorizontal" type="xsd:boolean" use="optional" default="false"/>
-#<xsd:attribute name="syncVertical" type="xsd:boolean" use="optional" default="false"/>
-#<xsd:attribute name="syncRef" type="ST_Ref" use="optional"/>
-#<xsd:attribute name="transitionEvaluation" type="xsd:boolean" use="optional" default="false"/>
-#<xsd:attribute name="transitionEntry" type="xsd:boolean" use="optional" default="false"/>
-#<xsd:attribute name="published" type="xsd:boolean" use="optional" default="true"/>
-#<xsd:attribute name="codeName" type="xsd:string" use="optional"/>
-#<xsd:attribute name="filterMode" type="xsd:boolean" use="optional" default="false"/>
-#<xsd:attribute name="enableFormatConditionsCalculation" type="xsd:boolean" use="optional" default="true"/>
-#</xsd:complexType>
+ #<xsd:complexType name="CT_SheetPr">
+ #<xsd:sequence>
+ #<xsd:element name="tabColor" type="CT_Color" minOccurs="0" maxOccurs="1"/>
+ #<xsd:element name="outlinePr" type="CT_OutlinePr" minOccurs="0" maxOccurs="1"/>
+ #<xsd:element name="pageSetUpPr" type="CT_PageSetUpPr" minOccurs="0" maxOccurs="1"/>
+ #</xsd:sequence>
+ #<xsd:attribute name="syncHorizontal" type="xsd:boolean" use="optional" default="false"/>
+ #<xsd:attribute name="syncVertical" type="xsd:boolean" use="optional" default="false"/>
+ #<xsd:attribute name="syncRef" type="ST_Ref" use="optional"/>
+ #<xsd:attribute name="transitionEvaluation" type="xsd:boolean" use="optional" default="false"/>
+ #<xsd:attribute name="transitionEntry" type="xsd:boolean" use="optional" default="false"/>
+ #<xsd:attribute name="published" type="xsd:boolean" use="optional" default="true"/>
+ #<xsd:attribute name="codeName" type="xsd:string" use="optional"/>
+ #<xsd:attribute name="filterMode" type="xsd:boolean" use="optional" default="false"/>
+ #<xsd:attribute name="enableFormatConditionsCalculation" type="xsd:boolean" use="optional" default="true"/>
+ #</xsd:complexType>
# The SheetPr class manages serialization fo a worksheet's sheetPr element.
# Only fit_to_page is implemented
class SheetPr
@@ -107,10 +107,13 @@ module Axlsx
str
end
-
+
def update_properties
page_setup_pr.fit_to_page = worksheet.fit_to_page?
- self.filter_mode = worksheet.auto_filter.columns.size > 0
+ if worksheet.auto_filter.columns.size > 0
+ self.filter_mode = 1
+ self.enable_format_conditions_calculation = 0
+ end
end
end
@@ -122,9 +125,9 @@ module Axlsx
# @option [Boolean] fit_to_page Flag indicating whether the sheet displays Automatic Page Breaks.
# @option [Boolean] auto_page_breaks Flag indicating whether the Fit to Page print option is enabled.
def initialize(options = {})
- options.each do |key, value|
- self.send("#{key}=",value) if self.respond_to?("#{key}=")
- end
+ options.each do |key, value|
+ self.send("#{key}=",value) if self.respond_to?("#{key}=")
+ end
end
# Flag indicating whether the sheet displays Automatic Page Breaks.