public void TestStartBlock_EndBlock_Write()
        {
            HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("chartdemo.xls");
            Record[] sheetRecs = RecordInspector.GetRecords(wb.GetSheetAt(0), 0);

            RecordStream rs = new RecordStream(Arrays.AsList(sheetRecs), 0);

            rs.FindChartSubStream();
            int pos = rs.GetCountRead();

            ChartSheetAggregate csAgg = new ChartSheetAggregate(rs, null);
            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            csAgg.VisitContainedRecords(rv);
            Record[] outRecs = rv.Records;
            for (int i = 0; i < outRecs.Length; i++)
            {
                Assert.AreEqual(sheetRecs[pos + i].GetType(), outRecs[i].GetType());
            }
        }
Exemple #2
0
        public void TestDvProtectionOrder_bug47363b()
        {
            IWorkbook workbook = new HSSFWorkbook();
            ISheet    sheet    = workbook.CreateSheet("Sheet1");

            sheet.ProtectSheet("secret");

            IDataValidationHelper     dataValidationHelper = sheet.GetDataValidationHelper();
            IDataValidationConstraint dvc = dataValidationHelper.CreateintConstraint(OperatorType.BETWEEN, "10", "100");
            CellRangeAddressList      numericCellAddressList = new CellRangeAddressList(0, 0, 1, 1);
            IDataValidation           dv = dataValidationHelper.CreateValidation(dvc, numericCellAddressList);

            try
            {
                sheet.AddValidationData(dv);
            }
            catch (InvalidOperationException e)
            {
                String expMsg = "Unexpected (NPOI.HSSF.Record.PasswordRecord) while looking for DV Table insert pos";
                if (expMsg.Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 47363b");
                }
                throw e;
            }
            TestCases.HSSF.UserModel.RecordInspector.RecordCollector rc;
            rc = new RecordInspector.RecordCollector();
            ((HSSFSheet)sheet).Sheet.VisitContainedRecords(rc, 0);
            int nRecsWithProtection = rc.Records.Length;

            sheet.ProtectSheet(null);
            rc = new RecordInspector.RecordCollector();
            ((HSSFSheet)sheet).Sheet.VisitContainedRecords(rc, 0);
            int nRecsWithoutProtection = rc.Records.Length;

            Assert.AreEqual(4, nRecsWithProtection - nRecsWithoutProtection);
        }
Exemple #3
0
        public void TestMissingDims()
        {

            int rowIx = 5;
            int colIx = 6;
            NumberRecord nr = new NumberRecord();
            nr.Row = (rowIx);
            nr.Column = ((short)colIx);
            nr.Value = (3.0);

            ArrayList inRecs = new ArrayList();
            inRecs.Add(BOFRecord.CreateSheetBOF());
            inRecs.Add(new RowRecord(rowIx));
            inRecs.Add(nr);
            inRecs.Add(CreateWindow2Record());
            inRecs.Add(EOFRecord.instance);
            InternalSheet sheet;
            try
            {
                sheet = CreateSheet(inRecs);
            }
            catch (Exception e)
            {
                if ("DimensionsRecord was not found".Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 46206");
                }
                throw e;
            }

            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            sheet.VisitContainedRecords(rv, rowIx);
            Record[] outRecs = rv.Records;
            Assert.AreEqual(8, outRecs.Length);
            DimensionsRecord dims = (DimensionsRecord)outRecs[5];
            Assert.AreEqual(rowIx, dims.FirstRow);
            Assert.AreEqual(rowIx, dims.LastRow);
            Assert.AreEqual(colIx, dims.FirstCol);
            Assert.AreEqual(colIx, dims.LastCol);
        }
Exemple #4
0
 private static Record[] GetSheetRecords(InternalSheet s, int offset)
 {
     RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
     s.VisitContainedRecords(rc, offset);
     return rc.Records;
 }
        public void TestUnknownContinue_bug46280()
        {
            byte[] dummtydata = Encoding.Unicode.GetBytes("dummydata");
            byte[] moredummydata = Encoding.Unicode.GetBytes("moredummydata");
            Record[] inRecs = {
			new RowRecord(0),
			new NumberRecord(),
            new UnknownRecord(0x5555,dummtydata),
            new ContinueRecord(moredummydata)
			//new UnknownRecord(0x5555, "dummydata".getBytes()),
			//new ContinueRecord("moredummydata".getBytes()),
		};
            RecordStream rs = new RecordStream(Arrays.AsList(inRecs), 0);
            RowRecordsAggregate rra;
            try
            {
                rra = new RowRecordsAggregate(rs, SharedValueManager.CreateEmpty());
            }
            catch (RuntimeException e)
            {
                if (e.Message.StartsWith("Unexpected record type"))
                {
                    throw new AssertionException("Identified bug 46280a");
                }
                throw e;
            }
            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            rra.VisitContainedRecords(rv);
            Record[] outRecs = rv.Records;
            Assert.AreEqual(5, outRecs.Length);
        }
        public void TestDuplicateHeaderFooter_bug48026()
        {

            NPOI.HSSF.Record.Record[] recs = {
                BOFRecord.CreateSheetBOF(),
                new IndexRecord(),

                //PageSettingsBlock
                new HeaderRecord("&LDecember"),
                new FooterRecord("&LJanuary"),
                new DimensionsRecord(),

                new WindowTwoRecord(),

                //CustomViewSettingsRecordAggregate
                new UserSViewBegin(HexRead.ReadFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")),
                new SelectionRecord(0, 0),
                new UserSViewEnd(HexRead.ReadFromString("01 00")),

                // two HeaderFooterRecord records, the first one has zero GUID (16 bytes at offset 12) and belongs to the PSB,
                // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
                new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")),
                new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")),

                EOFRecord.instance,
            };
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            InternalSheet sheet;
            try
            {
                sheet = InternalSheet.CreateSheet(rs);
            }
            catch (Exception e)
            {
                if (e.Message.Equals("Duplicate PageSettingsBlock record (sid=0x89c)"))
                {
                    throw new AssertionException("Identified bug 48026");
                }
                throw e;
            }

            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            sheet.VisitContainedRecords(rv, 0);
            NPOI.HSSF.Record.Record[] outRecs = rv.Records;

            Assert.AreEqual(recs.Length, outRecs.Length);
            //expected order of records:
            NPOI.HSSF.Record.Record[] expectedRecs = {
                recs[0],  //BOFRecord
                recs[1],  //IndexRecord

                //PageSettingsBlock
                recs[2],  //HeaderRecord
                recs[3],  //FooterRecord
                recs[9],  //HeaderFooterRecord
                recs[4],  // DimensionsRecord
                recs[5],  // WindowTwoRecord

                //CustomViewSettingsRecordAggregate
                recs[6],  // UserSViewBegin
                recs[7],  // SelectionRecord
                recs[10], // HeaderFooterRecord
                recs[8],  // UserSViewEnd

                recs[11],  //EOFRecord
            };
            for (int i = 0; i < expectedRecs.Length; i++)
            {
                Assert.AreEqual(expectedRecs[i].GetType(), outRecs[i].GetType(), "Record mismatch at index " + i);
            }
            HeaderFooterRecord hd1 = (HeaderFooterRecord)expectedRecs[4];
            //GUID is zero
            Assert.IsTrue(Arrays.Equals(new byte[16], hd1.Guid));
            Assert.IsTrue(hd1.IsCurrentSheet);

            UserSViewBegin svb = (UserSViewBegin)expectedRecs[7];
            HeaderFooterRecord hd2 = (HeaderFooterRecord)expectedRecs[9];
            Assert.IsFalse(hd2.IsCurrentSheet);
            //GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
            Assert.IsTrue(Arrays.Equals(svb.Guid, hd2.Guid));
        }
        public void TestDuplicatePLS_bug47415()
        {
            NPOI.HSSF.Record.Record plsA = ur(UnknownRecord.PLS_004D, "BA AD F0 0D");
            NPOI.HSSF.Record.Record plsB = ur(UnknownRecord.PLS_004D, "DE AD BE EF");
            NPOI.HSSF.Record.Record contB1 = new ContinueRecord(HexRead.ReadFromString("FE ED"));
            NPOI.HSSF.Record.Record contB2 = new ContinueRecord(HexRead.ReadFromString("FA CE"));
            NPOI.HSSF.Record.Record[] recs = {
				new HeaderRecord("&LSales Figures"),
				new FooterRecord("&LInventory"),
				new HCenterRecord(),
				new VCenterRecord(),
				plsA,
				plsB, contB1, contB2, // make sure continuing PLS is still OK
		};
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            PageSettingsBlock psb;
            try
            {
                psb = new PageSettingsBlock(rs);
            }
            catch (RecordFormatException e)
            {
                if ("Duplicate PageSettingsBlock record (sid=0x4d)".Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 47415");
                }
                throw e;
            }

            // serialize the PSB to see what records come out
            RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
            psb.VisitContainedRecords(rc);
            NPOI.HSSF.Record.Record[] outRecs = rc.Records;

            // records were assembled in standard order, so this simple check is OK
            Assert.IsTrue(Arrays.Equals(recs, outRecs));
        }
        public void TestMissingHeaderFooter()
        {
            // Initialise PSB with some records, but not the header / footer
            NPOI.HSSF.Record.Record[] recs = {
				new HCenterRecord(),
				new VCenterRecord(),
		};
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            PageSettingsBlock psb = new PageSettingsBlock(rs);

            // serialize the PSB to see what records come out
            RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
            psb.VisitContainedRecords(rc);
            NPOI.HSSF.Record.Record[] outRecs = rc.Records;

            if (outRecs.Length == 2)
            {
                throw new AssertionException("PageSettingsBlock didn't add missing header/footer records");
            }
            Assert.AreEqual(4, outRecs.Length);
            Assert.AreEqual(typeof(HeaderRecord), outRecs[0].GetType());
            Assert.AreEqual(typeof(FooterRecord), outRecs[1].GetType());
            Assert.AreEqual(typeof(HCenterRecord), outRecs[2].GetType());
            Assert.AreEqual(typeof(VCenterRecord), outRecs[3].GetType());

            // make sure the Added header / footer records are empty
            HeaderRecord hr = (HeaderRecord)outRecs[0];
            Assert.AreEqual("", hr.Text);
            FooterRecord fr = (FooterRecord)outRecs[1];
            Assert.AreEqual("", fr.Text);
        }
        public void TestLateHeaderFooter_bug46953()
        {

            int rowIx = 5;
            int colIx = 6;
            NumberRecord nr = new NumberRecord();
            nr.Row = (rowIx);
            nr.Column = ((short)colIx);
            nr.Value = (3.0);

            NPOI.HSSF.Record.Record[] recs = {
				BOFRecord.CreateSheetBOF(),
				new HeaderRecord("&LSales Figures"),
				new FooterRecord("&LJanuary"),
				new DimensionsRecord(),
				new WindowTwoRecord(),
				new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")),
				EOFRecord.instance,
		};
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            InternalSheet sheet = InternalSheet.CreateSheet(rs);

            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            sheet.VisitContainedRecords(rv, 0);
            NPOI.HSSF.Record.Record[] outRecs = rv.Records;
            if (outRecs[4] == EOFRecord.instance)
            {
                throw new AssertionException("Identified bug 46953 - EOF incorrectly Appended to PSB");
            }
            Assert.AreEqual(recs.Length + 1, outRecs.Length); // +1 for index record

            Assert.AreEqual(typeof(BOFRecord), outRecs[0].GetType());
            Assert.AreEqual(typeof(IndexRecord), outRecs[1].GetType());
            Assert.AreEqual(typeof(HeaderRecord), outRecs[2].GetType());
            Assert.AreEqual(typeof(FooterRecord), outRecs[3].GetType());
            Assert.AreEqual(typeof(HeaderFooterRecord), outRecs[4].GetType());
            Assert.AreEqual(typeof(DimensionsRecord), outRecs[5].GetType());
            Assert.AreEqual(typeof(WindowTwoRecord), outRecs[6].GetType());
            Assert.AreEqual(typeof(EOFRecord), outRecs[7].GetType());
        }
Exemple #10
0
        public void TestDvProtectionOrder_bug47363b()
        {
            IWorkbook workbook = new HSSFWorkbook();
            ISheet sheet = workbook.CreateSheet("Sheet1");
            sheet.ProtectSheet("secret");

            IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper();
            IDataValidationConstraint dvc = dataValidationHelper.CreateintConstraint(OperatorType.BETWEEN, "10", "100");
            CellRangeAddressList numericCellAddressList = new CellRangeAddressList(0, 0, 1, 1);
            IDataValidation dv = dataValidationHelper.CreateValidation(dvc, numericCellAddressList);
            try
            {
                sheet.AddValidationData(dv);
            }
            catch (InvalidOperationException e)
            {
                String expMsg = "Unexpected (NPOI.HSSF.Record.PasswordRecord) while looking for DV Table insert pos";
                if (expMsg.Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 47363b");
                }
                throw e;
            }
            TestCases.HSSF.UserModel.RecordInspector.RecordCollector rc;
            rc = new RecordInspector.RecordCollector();
            ((HSSFSheet)sheet).Sheet.VisitContainedRecords(rc, 0);
            int nRecsWithProtection = rc.Records.Length;

            sheet.ProtectSheet(null);
            rc = new RecordInspector.RecordCollector();
            ((HSSFSheet)sheet).Sheet.VisitContainedRecords(rc, 0);
            int nRecsWithoutProtection = rc.Records.Length;

            Assert.AreEqual(4, nRecsWithProtection - nRecsWithoutProtection);
        }