public void TestAutoFilter() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = (HSSFSheet)wb.CreateSheet(); InternalWorkbook iwb = wb.Workbook; InternalSheet ish = sh.Sheet; Assert.IsNull(iwb.GetSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1)); Assert.IsNull(ish.FindFirstRecordBySid(AutoFilterInfoRecord.sid)); CellRangeAddress range = CellRangeAddress.ValueOf("A1:B10"); sh.SetAutoFilter(range); NameRecord name = iwb.GetSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1); Assert.IsNotNull(name); // The built-in name for auto-filter must consist of a single Area3d Ptg. Ptg[] ptg = name.NameDefinition; Assert.AreEqual(1, ptg.Length, "The built-in name for auto-filter must consist of a single Area3d Ptg"); Assert.IsTrue(ptg[0] is Area3DPtg, "The built-in name for auto-filter must consist of a single Area3d Ptg"); Area3DPtg aref = (Area3DPtg)ptg[0]; Assert.AreEqual(range.FirstColumn, aref.FirstColumn); Assert.AreEqual(range.FirstRow, aref.FirstRow); Assert.AreEqual(range.LastColumn, aref.LastColumn); Assert.AreEqual(range.LastRow, aref.LastRow); // verify AutoFilterInfoRecord AutoFilterInfoRecord afilter = (AutoFilterInfoRecord)ish.FindFirstRecordBySid(AutoFilterInfoRecord.sid); Assert.IsNotNull(afilter); Assert.AreEqual(2, afilter.NumEntries); //filter covers two columns HSSFPatriarch dr = (HSSFPatriarch)sh.DrawingPatriarch; Assert.IsNotNull(dr); HSSFSimpleShape comboBoxShape = (HSSFSimpleShape)dr.Children[0]; Assert.AreEqual(comboBoxShape.ShapeType, HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX); Assert.IsNull(ish.FindFirstRecordBySid(ObjRecord.sid)); // ObjRecord will appear after serializetion wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = (HSSFSheet)wb.GetSheetAt(0); ish = sh.Sheet; ObjRecord objRecord = (ObjRecord)ish.FindFirstRecordBySid(ObjRecord.sid); IList subRecords = objRecord.SubRecords; Assert.AreEqual(3, subRecords.Count); Assert.IsTrue(subRecords[0] is CommonObjectDataSubRecord); Assert.IsTrue(subRecords[1] is FtCblsSubRecord); // must be present, see Bug 51481 Assert.IsTrue(subRecords[2] is LbsDataSubRecord); }