diff options
| author | Jonathan Tron <[email protected]> | 2014-02-26 15:14:56 +0100 |
|---|---|---|
| committer | Jonathan Tron <[email protected]> | 2014-02-26 15:14:56 +0100 |
| commit | a271a7d0f26ecb26d01aad00e094744d6fe8b0d2 (patch) | |
| tree | 644dc2c24a6d827d1705202508f1b14ee8f7671e /lib | |
| parent | 450d5e703ff6d45b6689959ea9079e81ff6dc4ad (diff) | |
| download | caxlsx-a271a7d0f26ecb26d01aad00e094744d6fe8b0d2.tar.gz caxlsx-a271a7d0f26ecb26d01aad00e094744d6fe8b0d2.zip | |
Ensure auto_filter defined name is correctly added to workbook (refs #285)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 12 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb index 05da57ef..9fd6be18 100644 --- a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +++ b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb @@ -47,8 +47,8 @@ module Axlsx columns.last end - # actually performs the filtering of rows who's cells do not - # match the filter. + # actually performs the filtering of rows who's cells do not + # match the filter. def apply first_cell, last_cell = range.split(':') start_point = Axlsx::name_to_indices(first_cell) diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index fcd883e1..f034a000 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -598,6 +598,7 @@ module Axlsx # Returns a sheet node serialization for this sheet in the workbook. def to_sheet_node_xml_string(str='') + add_autofilter_defined_name_to_workbook str << '<sheet ' serialized_attributes str str << "r:id='" << rId << "'" @@ -608,10 +609,8 @@ module Axlsx # This intentionally does not use nokogiri for performance reasons # @return [String] def to_xml_string - 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 + add_autofilter_defined_name_to_workbook + auto_filter.apply if auto_filter.range str = '<?xml version="1.0" encoding="UTF-8"?>' str << worksheet_node serializable_parts.each do |item| @@ -795,5 +794,10 @@ module Axlsx column_info[index] ||= Col.new(index + 1, index + 1) end + def add_autofilter_defined_name_to_workbook + return if workbook.defined_names.any?{|dn| dn.name=='_xlnm._FilterDatabase'} || !auto_filter.range + workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1 + end + end end |
