Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void TestRead()
        {
            AutoFilterInfoRecord record = new AutoFilterInfoRecord(TestcaseRecordInputStream.Create(AutoFilterInfoRecord.sid, data));

            Assert.AreEqual(AutoFilterInfoRecord.sid, record.Sid);
            Assert.AreEqual(data.Length, record.RecordSize - 4);
            Assert.AreEqual(5, record.NumEntries);
            record.NumEntries = (/*setter*/ (short)3);
            Assert.AreEqual(3, record.NumEntries);
        }
Beispiel #3
0
        public void TestWrite()
        {
            AutoFilterInfoRecord record = new AutoFilterInfoRecord();

            record.NumEntries = (/*setter*/ (short)3);

            byte[] ser = record.Serialize();
            Assert.AreEqual(ser.Length - 4, data.Length);
            record = new AutoFilterInfoRecord(TestcaseRecordInputStream.Create(ser));
            Assert.AreEqual(3, record.NumEntries);
        }
Beispiel #4
0
        public void TestClone()
        {
            AutoFilterInfoRecord record = new AutoFilterInfoRecord();

            record.NumEntries = (/*setter*/ (short)3);
            byte[] src = record.Serialize();

            AutoFilterInfoRecord Cloned = (AutoFilterInfoRecord)record.Clone();

            Assert.AreEqual(3, record.NumEntries);
            byte[] cln = Cloned.Serialize();

            Assert.AreEqual(record.RecordSize, Cloned.RecordSize);
            Assert.IsTrue(Arrays.Equals(src, cln));
        }
Beispiel #5
0
        private void CreateAutoFilterInfoRecord(HSSFSheet sheet, int insertPos, Area3DPtg ptg)
        {
            //look for the AutoFilterInfo Record
            NPOI.HSSF.Record.Record record = sheet.Sheet.FindFirstRecordBySid(AutoFilterInfoRecord.sid);
            AutoFilterInfoRecord    info;

            if (record == null)
            {
                info = new AutoFilterInfoRecord();
                sheet.Sheet.Records.Insert(insertPos, info);
            }
            else
            {
                info = record as AutoFilterInfoRecord;
            }
            info.NumberOfFilterColumns = (short)(ptg.LastColumn - ptg.FirstColumn + 1);
        }