From 37da8ab829c1161a9bacb1153bc3961e200adc59 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Wed, 26 Sep 2012 22:46:32 +0900 Subject: 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! --- .../worksheet/auto_filter/filter_column.rb | 13 ++++++- .../workbook/worksheet/auto_filter/filters.rb | 18 +++++---- lib/axlsx/workbook/worksheet/sheet_pr.rb | 45 ++++++++++++---------- 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 << "" + str << "" @filter.to_xml_string(str) str << "" 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 << "" + str << "" filter_items.each { |filter| filter.to_xml_string(str) } date_group_items.each { |date_group_item| date_group_item.to_xml_string(str) } str << '' @@ -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 -# -# -# -# -# -# -# -# -# -# -# -# -# -# -# -# + # + # + # + # + # + # + # + # + # + # + # + # + # + # + # + # # 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. -- cgit v1.2.3