Exemplo n.º 1
0
        public void TestColPageBreaks()
        {
            int rowFrom = 0;
            int rowTo   = 65535;

            InternalSheet     worksheet = InternalSheet.CreateSheet();
            PageSettingsBlock sheet     = worksheet.PageSettings;

            sheet.SetColumnBreak(0, rowFrom, rowTo);

            Assert.IsTrue(sheet.IsColumnBroken(0), "no col break at 0");
            Assert.AreEqual(1, sheet.NumColumnBreaks, "1 col break available");

            sheet.SetColumnBreak(0, rowFrom, rowTo);

            Assert.IsTrue(sheet.IsColumnBroken(0), "no col break at 0");
            Assert.AreEqual(1, sheet.NumColumnBreaks, "1 col break available");

            sheet.SetColumnBreak(1, rowFrom, rowTo);
            sheet.SetColumnBreak(10, rowFrom, rowTo);
            sheet.SetColumnBreak(15, rowFrom, rowTo);

            Assert.IsTrue(sheet.IsColumnBroken(1), "no col break at 1");
            Assert.IsTrue(sheet.IsColumnBroken(10), "no col break at 10");
            Assert.IsTrue(sheet.IsColumnBroken(15), "no col break at 15");
            Assert.AreEqual(4, sheet.NumColumnBreaks, "4 col break available");

            bool is10 = false;
            bool is0  = false;
            bool is1  = false;
            bool is15 = false;

            int[] colBreaks = sheet.ColumnBreaks;
            for (int i = 0; i < colBreaks.Length; i++)
            {
                int main = colBreaks[i];
                if (main != 0 && main != 1 && main != 10 && main != 15)
                {
                    Assert.Fail("Invalid page break");
                }
                if (main == 0)
                {
                    is0 = true;
                }
                if (main == 1)
                {
                    is1 = true;
                }
                if (main == 10)
                {
                    is10 = true;
                }
                if (main == 15)
                {
                    is15 = true;
                }
            }

            Assert.IsTrue(is0 && is1 && is10 && is15, "one of the breaks didnt make it");

            sheet.RemoveColumnBreak(15);
            Assert.IsFalse(sheet.IsColumnBroken(15), "column break should not be there");

            sheet.RemoveColumnBreak(0);
            Assert.IsFalse(sheet.IsColumnBroken(0), "column break should not be there");

            sheet.RemoveColumnBreak(1);
            Assert.IsFalse(sheet.IsColumnBroken(1), "column break should not be there");

            sheet.RemoveColumnBreak(10);
            Assert.IsFalse(sheet.IsColumnBroken(10), "column break should not be there");

            Assert.AreEqual(0, sheet.NumColumnBreaks, "no more breaks");
        }
Exemplo n.º 2
0
        public void TestRowPageBreaks()
        {
            short colFrom = 0;
            short colTo   = 255;

            InternalSheet     worksheet = InternalSheet.CreateSheet();
            PageSettingsBlock sheet     = worksheet.PageSettings;

            sheet.SetRowBreak(0, colFrom, colTo);

            Assert.IsTrue(sheet.IsRowBroken(0), "no row break at 0");
            Assert.AreEqual(1, sheet.NumRowBreaks, "1 row break available");

            sheet.SetRowBreak(0, colFrom, colTo);
            sheet.SetRowBreak(0, colFrom, colTo);

            Assert.IsTrue(sheet.IsRowBroken(0), "no row break at 0");
            Assert.AreEqual(1, sheet.NumRowBreaks, "1 row break available");

            sheet.SetRowBreak(10, colFrom, colTo);
            sheet.SetRowBreak(11, colFrom, colTo);

            Assert.IsTrue(sheet.IsRowBroken(10), "no row break at 10");
            Assert.IsTrue(sheet.IsRowBroken(11), "no row break at 11");
            Assert.AreEqual(3, sheet.NumRowBreaks, "3 row break available");


            bool is10 = false;
            bool is0  = false;
            bool is11 = false;

            int[] rowBreaks = sheet.RowBreaks;
            for (int i = 0; i < rowBreaks.Length; i++)
            {
                int main = rowBreaks[i];
                if (main != 0 && main != 10 && main != 11)
                {
                    Assert.Fail("Invalid page break");
                }
                if (main == 0)
                {
                    is0 = true;
                }
                if (main == 10)
                {
                    is10 = true;
                }
                if (main == 11)
                {
                    is11 = true;
                }
            }

            Assert.IsTrue(is0 && is10 && is11, "one of the breaks didnt make it");

            sheet.RemoveRowBreak(11);
            Assert.IsFalse(sheet.IsRowBroken(11), "row should be removed");

            sheet.RemoveRowBreak(0);
            Assert.IsFalse(sheet.IsRowBroken(0), "row should be removed");

            sheet.RemoveRowBreak(10);
            Assert.IsFalse(sheet.IsRowBroken(10), "row should be removed");

            Assert.AreEqual(0, sheet.NumRowBreaks, "no more breaks");
        }
Exemplo n.º 3
0
        public void TestXFIndexForColumn()
        {
            short         TEST_IDX    = 10;
            short         DEFAULT_IDX = 0xF; // 15
            short         xfindex     = short.MinValue;
            InternalSheet sheet       = InternalSheet.CreateSheet();

            // without ColumnInfoRecord
            xfindex = sheet.GetXFIndexForColAt((short)0);
            Assert.AreEqual(DEFAULT_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)1);
            Assert.AreEqual(DEFAULT_IDX, xfindex);

            ColumnInfoRecord nci = new ColumnInfoRecord();

            sheet.ColumnInfos.InsertColumn(nci);

            // single column ColumnInfoRecord
            nci.FirstColumn = ((short)2);
            nci.LastColumn  = ((short)2);
            nci.XFIndex     = (TEST_IDX);
            xfindex         = sheet.GetXFIndexForColAt((short)0);
            Assert.AreEqual(DEFAULT_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)1);
            Assert.AreEqual(DEFAULT_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)2);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)3);
            Assert.AreEqual(DEFAULT_IDX, xfindex);

            // ten column ColumnInfoRecord
            nci.FirstColumn = ((short)2);
            nci.LastColumn  = ((short)11);
            nci.XFIndex     = (TEST_IDX);
            xfindex         = sheet.GetXFIndexForColAt((short)1);
            Assert.AreEqual(DEFAULT_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)2);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)6);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)11);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)12);
            Assert.AreEqual(DEFAULT_IDX, xfindex);

            // single column ColumnInfoRecord starting at index 0
            nci.FirstColumn = ((short)0);
            nci.LastColumn  = ((short)0);
            nci.XFIndex     = (TEST_IDX);
            xfindex         = sheet.GetXFIndexForColAt((short)0);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)1);
            Assert.AreEqual(DEFAULT_IDX, xfindex);

            // ten column ColumnInfoRecord starting at index 0
            nci.FirstColumn = ((short)0);
            nci.LastColumn  = ((short)9);
            nci.XFIndex     = (TEST_IDX);
            xfindex         = sheet.GetXFIndexForColAt((short)0);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)7);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)9);
            Assert.AreEqual(TEST_IDX, xfindex);
            xfindex = sheet.GetXFIndexForColAt((short)10);
            Assert.AreEqual(DEFAULT_IDX, xfindex);
        }
Exemplo n.º 4
0
 private static InternalSheet CreateSheet(ArrayList inRecs)
 {
     return(InternalSheet.CreateSheet(new RecordStream(inRecs, 0)));
 }
Exemplo n.º 5
0
        public void TestDuplicateHeaderFooter_bug48026()
        {
            Npoi.Core.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((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.Core.HSSF.Record.Record[] outRecs = rv.Records;

            Assert.AreEqual(recs.Length, outRecs.Length);
            //expected order of records:
            Npoi.Core.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));
        }