summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJonathan Tron <[email protected]>2014-02-26 14:57:26 +0100
committerJonathan Tron <[email protected]>2014-02-26 14:57:26 +0100
commit450d5e703ff6d45b6689959ea9079e81ff6dc4ad (patch)
tree5cc16a644498cde0a3884e7ed4c013b031f0e841 /lib
parentd7b4ae4b2508732f1648594d0056c0e2b4105d1a (diff)
downloadcaxlsx-450d5e703ff6d45b6689959ea9079e81ff6dc4ad.tar.gz
caxlsx-450d5e703ff6d45b6689959ea9079e81ff6dc4ad.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb6
1 files changed, 4 insertions, 2 deletions
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 = '<?xml version="1.0" encoding="UTF-8"?>'
str << worksheet_node
serializable_parts.each do |item|