/** * @return the value calculated for the position of the first DBCELL record for this sheet. * That value is1 found on the IndexRecord. */ private static int GetDbCellRecordPos(InternalSheet sheet) { MyIndexRecordListener myIndexListener = new MyIndexRecordListener(); sheet.VisitContainedRecords(myIndexListener, 0); IndexRecord indexRecord = myIndexListener.GetIndexRecord(); int dbCellRecordPos = indexRecord.GetDbcellAt(0); return(dbCellRecordPos); }
public void TestAddMergedRegion() { InternalSheet sheet = InternalSheet.CreateSheet(); int regionsToAdd = 4096; int startRecords = sheet.Records.Count; //simple Test that Adds a load of regions for (int n = 0; n < regionsToAdd; n++) { int index = sheet.AddMergedRegion(0, 0, 1, 1); Assert.AreEqual(index, n, "Merged region index expected to be " + n + " got " + index); } //test all the regions were indeed Added Assert.AreEqual(sheet.NumMergedRegions, regionsToAdd); //test that the regions were spread out over the appropriate number of records MergedCellListener mcListener = new MergedCellListener(); sheet.VisitContainedRecords(mcListener, 0); int recordsAdded = mcListener.Count; int recordsExpected = regionsToAdd / 1027; if ((regionsToAdd % 1027) != 0) { recordsExpected++; } Assert.AreEqual(recordsAdded, recordsExpected, "The " + regionsToAdd + " merged regions should have been spRead out over " + recordsExpected + " records, not " + recordsAdded); // Check we can't Add one with invalid date try { sheet.AddMergedRegion(10, 10, 9, 12); Assert.Fail("Expected an exception to occur"); } catch (ArgumentException e) { // occurs during successful Test Assert.AreEqual("The 'to' row (9) must not be less than the 'from' row (10)", e.Message); } try { sheet.AddMergedRegion(10, 10, 12, 9); Assert.Fail("Expected an exception to occur"); } catch (ArgumentException e) { // occurs during successful Test Assert.AreEqual("The 'to' col (9) must not be less than the 'from' col (10)", e.Message); } }
public void TestUncalcSize_bug45066() { List <Record> records = new List <Record>(); records.Add(BOFRecord.CreateSheetBOF()); records.Add(new UncalcedRecord()); records.Add(new DimensionsRecord()); records.Add(CreateWindow2Record()); records.Add(new EOFRecord()); InternalSheet sheet = CreateSheet(records); // The original bug was due to different logic for collecting records for sizing and // serialization. The code has since been refactored into a single method for visiting // all contained records. Now this Test is much less interesting SizeCheckingRecordVisitor scrv = new SizeCheckingRecordVisitor(); sheet.VisitContainedRecords(scrv, 0); Assert.AreEqual(90, scrv.TotalSize); }
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()); }
private static Record[] GetSheetRecords(InternalSheet s, int offset) { RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector(); s.VisitContainedRecords(rc, offset); return(rc.Records); }