Commits

Charlie Clark  committed f303878

Handle filterColumns without filters children.
Added sample file and naive test.
Resolves #275

  • Participants
  • Parent commits 23e377d
  • Branches 1.9

Comments (0)

Files changed (4)

 #46  - ColumnDimension style error
 #137 - Workbooks with chartsheets
 #269 - Handling unsized worksheets in IterableWorksheet
+#275 - Handling auto filters where there are only custom filters
 
 
 1.8.4 (unreleased)

File openpyxl/reader/worksheet.py

         self.ws.auto_filter.ref = element.get("ref")
         for fc in safe_iterator(element, '{%s}filterColumn' % SHEET_MAIN_NS):
             filters = fc.find('{%s}filters' % SHEET_MAIN_NS)
+            if filters is None:
+                continue
             vals = [f.get("val") for f in safe_iterator(filters, '{%s}filter' % SHEET_MAIN_NS)]
-            self.ws.auto_filter.add_filter_column(fc.get("colId"), vals, blank=filters.get("blank"))
+            blank = filters.get("blank")
+            self.ws.auto_filter.add_filter_column(fc.get("colId"), vals, blank=blank)
         for sc in safe_iterator(element, '{%s}sortCondition' % SHEET_MAIN_NS):
             self.ws.auto_filter.add_sort_condition(sc.get("ref"), sc.get("descending"))
 

File openpyxl/tests/test_data/reader/bug275.xlsx

Binary file added.

File openpyxl/tests/test_read.py

     stream = FUT(z.open("test"))
     assert hasattr(stream, "read")
     z.close()
+
+
+def test_read_autofilter(datadir):
+    datadir.join("reader").chdir()
+    wb = load_workbook("bug275.xlsx")
+    ws = wb.active
+    assert ws.auto_filter.ref == 'A1:B6'