public void TestAddRemoveArrayFormulas_recordUpdates()
        {
            IWorkbook wb = new HSSFWorkbook();
            ISheet    s  = wb.CreateSheet("Sheet1");

            ICellRange <ICell> cr = s.SetArrayFormula("123", CellRangeAddress.ValueOf("B5:C6"));

            Record[] recs;
            int      ix;

            recs = RecordInspector.GetRecords(s, 0);
            ix   = FindRecordOfType(recs, typeof(ArrayRecord), 0);
            ConfirmRecordClass(recs, ix - 1, typeof(FormulaRecord));
            ConfirmRecordClass(recs, ix + 1, typeof(FormulaRecord));
            ConfirmRecordClass(recs, ix + 2, typeof(FormulaRecord));
            ConfirmRecordClass(recs, ix + 3, typeof(FormulaRecord));
            // just one array record
            Assert.IsTrue(FindRecordOfType(recs, typeof(ArrayRecord), ix + 1) < 0);

            s.RemoveArrayFormula(cr.TopLeftCell);

            // Make sure the array formula has been Removed properly

            recs = RecordInspector.GetRecords(s, 0);
            Assert.IsTrue(FindRecordOfType(recs, typeof(ArrayRecord), 0) < 0);
            Assert.IsTrue(FindRecordOfType(recs, typeof(FormulaRecord), 0) < 0);
            RowRecordsAggregate rra = ((HSSFSheet)s).Sheet.RowsAggregate;
            SharedValueManager  svm = TestSharedValueManager.ExtractFromRRA(rra);

            if (svm.GetArrayRecord(4, 1) != null)
            {
                throw new AssertionException("Array record was not cleaned up properly.");
            }
        }
예제 #2
0
        public void TestCachedTypeChange()
        {
            HSSFSheet sheet = (HSSFSheet) new HSSFWorkbook().CreateSheet("Sheet1");
            HSSFCell  cell  = (HSSFCell)sheet.CreateRow(0).CreateCell(0);

            cell.CellFormula = ("A1");
            cell.SetCellValue("abc");
            ConfirmStringRecord(sheet, true);
            cell.SetCellValue(123);
            NPOI.HSSF.Record.Record[] recs = RecordInspector.GetRecords(sheet, 0);
            if (recs.Length == 28 && recs[23] is StringRecord)
            {
                throw new AssertionException("Identified bug - leftover StringRecord");
            }
            ConfirmStringRecord(sheet, false);

            // string to error code
            cell.SetCellValue("abc");
            ConfirmStringRecord(sheet, true);
            cell.SetCellErrorValue((byte)ErrorConstants.ERROR_REF);
            ConfirmStringRecord(sheet, false);

            // string to boolean
            cell.SetCellValue("abc");
            ConfirmStringRecord(sheet, true);
            cell.SetCellValue(false);
            ConfirmStringRecord(sheet, false);
        }
예제 #3
0
        private static void ConfirmStringRecord(HSSFSheet sheet, bool isPresent)
        {
            Record[] recs = RecordInspector.GetRecords(sheet, 0);
            Assert.AreEqual(isPresent ? 31 : 30, recs.Length);
            int    index = 24;
            Record fr    = recs[index++];

            Assert.AreEqual(typeof(FormulaRecord), fr.GetType());
            if (isPresent)
            {
                Assert.AreEqual(typeof(StringRecord), recs[index++].GetType());
            }
            else
            {
                Assert.IsFalse(typeof(StringRecord) == recs[index].GetType());
            }
            Record dbcr = recs[index++];

            Assert.AreEqual(typeof(DBCellRecord), dbcr.GetType());
        }
예제 #4
0
        private static void ConfirmStringRecord(HSSFSheet sheet, bool isPresent)
        {
            Record[] recs = RecordInspector.GetRecords(sheet, 0);
            Assert.AreEqual(isPresent ? 29 : 28, recs.Length); //for SheetExtRecord
            //Assert.AreEqual(isPresent ? 28 : 27, recs.Length);  // statement in poi, why use above line?
            int    index = 22;
            Record fr    = recs[index++];

            Assert.AreEqual(typeof(FormulaRecord), fr.GetType());
            if (isPresent)
            {
                Assert.AreEqual(typeof(StringRecord), recs[index++].GetType());
            }
            else
            {
                Assert.IsFalse(typeof(StringRecord) == recs[index].GetType());
            }
            Record dbcr = recs[index];

            Assert.AreEqual(typeof(DBCellRecord), dbcr.GetType());
        }