From 450d5e703ff6d45b6689959ea9079e81ff6dc4ad Mon Sep 17 00:00:00 2001 From: Jonathan Tron Date: Wed, 26 Feb 2014 14:57:26 +0100 Subject: Add auto_filter defined name in `Axlsx::Worksheet#to_xml_string` (refs #285) The way ot was done previously (adding the defined name on `Axlsx::Worksheet#auto_filter=`) meant that it was added only when using this method. But it's possible to assign range on the auto-created `AutoFilter` with: ```ruby workheet.auto_filter.range = "A1:B2" ``` In this case the defined name was never added to the workbook. --- lib/axlsx/workbook/worksheet/worksheet.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index f8f2ff83..fcd883e1 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -367,7 +367,6 @@ module Axlsx def auto_filter=(v) DataTypeValidator.validate "Worksheet.auto_filter", String, v auto_filter.range = v - workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1 end # Accessor for controlling whether leading and trailing spaces in cells are @@ -609,7 +608,10 @@ module Axlsx # This intentionally does not use nokogiri for performance reasons # @return [String] def to_xml_string - auto_filter.apply if auto_filter.range + if auto_filter.range + auto_filter.apply + workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1 + end str = '' str << worksheet_node serializable_parts.each do |item| -- cgit v1.2.3