public CustomViewSettingsRecordAggregate(RecordStream rs) { _begin = rs.GetNext(); if (_begin.Sid != UserSViewBegin.sid) { throw new InvalidOperationException("Bad begin record"); } List<RecordBase> temp = new List<RecordBase>(); while (rs.PeekNextSid() != UserSViewEnd.sid) { if (PageSettingsBlock.IsComponentRecord(rs.PeekNextSid())) { if (_psBlock != null) { throw new InvalidOperationException( "Found more than one PageSettingsBlock in custom view Settings sub-stream"); } _psBlock = new PageSettingsBlock(rs); temp.Add(_psBlock); continue; } temp.Add(rs.GetNext()); } _recs = temp; _end = rs.GetNext(); // no need to save EOF in field if (_end.Sid != UserSViewEnd.sid) { throw new InvalidOperationException("Bad custom view Settings end record"); } }
public ChartSubstreamRecordAggregate(RecordStream rs) { _bofRec = (BOFRecord)rs.GetNext(); List<RecordBase> temp = new List<RecordBase>(); while (rs.PeekNextClass() != typeof(EOFRecord)) { Type a = rs.PeekNextClass(); if (PageSettingsBlock.IsComponentRecord(rs.PeekNextSid())) { if (_psBlock != null) { if (rs.PeekNextSid() == HeaderFooterRecord.sid) { // test samples: 45538_classic_Footer.xls, 45538_classic_Header.xls _psBlock.AddLateHeaderFooter((HeaderFooterRecord)rs.GetNext()); continue; } throw new InvalidDataException( "Found more than one PageSettingsBlock in chart sub-stream"); } _psBlock = new PageSettingsBlock(rs); temp.Add(_psBlock); continue; } temp.Add(rs.GetNext()); } _recs = temp; Record eof = rs.GetNext(); // no need to save EOF in field if (!(eof is EOFRecord)) { throw new InvalidOperationException("Bad chart EOF"); } }
public ChartSheetAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_CHARTSHEET, container) { _bofRec = (BOFRecord)rs.GetNext(); List<RecordBase> temp = new List<RecordBase>(); while (rs.PeekNextClass() != typeof(EOFRecord)) { Type a = rs.PeekNextClass(); if (PageSettingsBlock.IsComponentRecord(rs.PeekNextChartSid())) { if (_psBlock != null) { if (rs.PeekNextChartSid() == HeaderFooterRecord.sid) { // test samples: 45538_classic_Footer.xls, 45538_classic_Header.xls _psBlock.AddLateHeaderFooter((HeaderFooterRecord)rs.GetNext()); continue; } throw new InvalidDataException( "Found more than one PageSettingsBlock in chart sub-stream"); } _psBlock = new PageSettingsBlock(rs); temp.Add(_psBlock); continue; } if (rs.PeekNextChartSid() == ChartRecord.sid) { chartFormats = new ChartFormatsAggregate(rs, this); temp.Add(chartFormats); continue; } if (rs.PeekNextChartSid() == DimensionsRecord.sid) { seriesData = new SeriesDataAggregate(rs); temp.Add(seriesData); continue; } temp.Add(rs.GetNext()); } _recs = temp; Record eof = rs.GetNext(); // no need to save EOF in field if (!(eof is EOFRecord)) { throw new InvalidOperationException("Bad chart EOF"); } }
/// <summary> /// Initializes a new instance of the <see cref="HSSFFooter"/> class. /// </summary> /// <param name="psb">Footer record to create the footer with</param> public HSSFFooter(PageSettingsBlock psb) { _psb = psb; }
private InternalSheet() { _mergedCellsTable = new MergedCellsTable(); records = new List<RecordBase>(32); //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "Sheet Createsheet from scratch called"); records.Add(CreateBOF()); records.Add(CreateCalcMode()); records.Add(CreateCalcCount()); records.Add(CreateRefMode()); records.Add(CreateIteration()); records.Add(CreateDelta()); records.Add(CreateSaveRecalc()); records.Add(CreatePrintHeaders()); printGridlines = CreatePrintGridlines(); records.Add(printGridlines); gridset = CreateGridset(); records.Add(gridset); _gutsRecord = CreateGuts(); records.Add(_gutsRecord); defaultrowheight = CreateDefaultRowHeight(); records.Add(defaultrowheight); records.Add(CreateWSBool()); // 'Page Settings Block' _psBlock = new PageSettingsBlock(); records.Add(_psBlock); // 'Worksheet Protection Block' (after 'Page Settings Block' and before DEFCOLWIDTH) records.Add(_protectionBlock); defaultcolwidth = CreateDefaultColWidth(); records.Add(defaultcolwidth); ColumnInfoRecordsAggregate columns = new ColumnInfoRecordsAggregate(); records.Add(columns); _columnInfos = columns; _dimensions = CreateDimensions(); records.Add(_dimensions); _rowsAggregate = new RowRecordsAggregate(); records.Add(_rowsAggregate); // 'Sheet View Settings' records.Add(windowTwo = CreateWindowTwo()); selection = CreateSelection(); records.Add(selection); records.Add(_mergedCellsTable); // MCT comes after 'Sheet View Settings' sheetext = new SheetExtRecord(); records.Add(sheetext); records.Add(EOFRecord.instance); //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "Sheet Createsheet from scratch exit"); }
/// <summary> /// Initializes a new instance of the <see cref="InternalSheet"/> class. /// </summary> /// <param name="rs">The stream.</param> private InternalSheet(RecordStream rs) { _mergedCellsTable = new MergedCellsTable(); RowRecordsAggregate rra = null; records = new List<RecordBase>(128); // TODO - take chart streams off into separate java objects //int bofEofNestingLevel = 0; // nesting level can only get to 2 (when charts are present) int dimsloc = -1; if (rs.PeekNextSid() != BOFRecord.sid) { throw new Exception("BOF record expected"); } BOFRecord bof = (BOFRecord)rs.GetNext(); if (bof.Type != BOFRecord.TYPE_WORKSHEET) { // TODO - fix junit tests throw new RuntimeException("Bad BOF record type"); } records.Add(bof); while (rs.HasNext()) { int recSid = rs.PeekNextSid(); if (recSid == CFHeaderRecord.sid) { condFormatting = new ConditionalFormattingTable(rs); records.Add(condFormatting); continue; } if (recSid == ColumnInfoRecord.sid) { _columnInfos = new ColumnInfoRecordsAggregate(rs); records.Add(_columnInfos); continue; } if (recSid == DVALRecord.sid) { _dataValidityTable = new DataValidityTable(rs); records.Add(_dataValidityTable); continue; } if (RecordOrderer.IsRowBlockRecord(recSid)) { //only Add the aggregate once if (rra != null) { throw new InvalidOperationException("row/cell records found in the wrong place"); } RowBlocksReader rbr = new RowBlocksReader(rs); _mergedCellsTable.AddRecords(rbr.LooseMergedCells); rra = new RowRecordsAggregate(rbr.PlainRecordStream, rbr.SharedFormulaManager); records.Add(rra); //only Add the aggregate once continue; } if (CustomViewSettingsRecordAggregate.IsBeginRecord(recSid)) { // This happens three times in test sample file "29982.xls" // Also several times in bugzilla samples 46840-23373 and 46840-23374 records.Add(new CustomViewSettingsRecordAggregate(rs)); continue; } if (PageSettingsBlock.IsComponentRecord(recSid)) { if (_psBlock == null) { // first PSB record encountered - read all of them: _psBlock = new PageSettingsBlock(rs); records.Add(_psBlock); } else { // one or more PSB records found after some intervening non-PSB records _psBlock.AddLateRecords(rs); } // YK: in some cases records can be moved to the preceding // CustomViewSettingsRecordAggregate blocks _psBlock.PositionRecords(records); continue; } if (WorksheetProtectionBlock.IsComponentRecord(recSid)) { _protectionBlock.AddRecords(rs); continue; } if (recSid == MergeCellsRecord.sid) { // when the MergedCellsTable is found in the right place, we expect those records to be contiguous _mergedCellsTable.Read(rs); continue; } if (recSid == BOFRecord.sid) { ChartSubstreamRecordAggregate chartAgg = new ChartSubstreamRecordAggregate(rs); //if (false) //{ // TODO - would like to keep the chart aggregate packed, but one unit test needs attention // records.Add(chartAgg); //} //else //{ SpillAggregate(chartAgg, records); //} continue; } Record rec = rs.GetNext(); if (recSid == IndexRecord.sid) { // ignore INDEX record because it is only needed by Excel, // and POI always re-calculates its contents continue; } if (recSid == UncalcedRecord.sid) { // don't Add UncalcedRecord to the list _isUncalced = true; // this flag is enough continue; } if (recSid == FeatRecord.sid || recSid == FeatHdrRecord.sid) { records.Add(rec); continue; } if (recSid == EOFRecord.sid) { records.Add(rec); break; } if (recSid == DimensionsRecord.sid) { // Make a columns aggregate if one hasn't Ready been created. if (_columnInfos == null) { _columnInfos = new ColumnInfoRecordsAggregate(); records.Add(_columnInfos); } _dimensions = (DimensionsRecord)rec; dimsloc = records.Count; } else if (recSid == DefaultColWidthRecord.sid) { defaultcolwidth = (DefaultColWidthRecord)rec; } else if (recSid == DefaultRowHeightRecord.sid) { defaultrowheight = (DefaultRowHeightRecord)rec; } else if (recSid == PrintGridlinesRecord.sid) { printGridlines = (PrintGridlinesRecord)rec; } else if (recSid == GridsetRecord.sid) { gridset = (GridsetRecord)rec; } else if (recSid == SelectionRecord.sid) { selection = (SelectionRecord)rec; } else if (recSid == WindowTwoRecord.sid) { windowTwo = (WindowTwoRecord)rec; } else if (recSid == SheetExtRecord.sid) { sheetext = (SheetExtRecord)rec; } else if (recSid == GutsRecord.sid) { _gutsRecord = (GutsRecord)rec; } records.Add(rec); } if (windowTwo == null) { throw new InvalidOperationException("WINDOW2 was not found"); } if (_dimensions == null) { // Excel seems to always write the DIMENSION record, but tolerates when it is not present // in all cases Excel (2007) adds the missing DIMENSION record if (rra == null) { // bug 46206 alludes to files which skip the DIMENSION record // when there are no row/cell records. // Not clear which application wrote these files. rra = new RowRecordsAggregate(); } else { //log.log(POILogger.WARN, "DIMENSION record not found even though row/cells present"); // Not sure if any tools write files like this, but Excel reads them OK } dimsloc = FindFirstRecordLocBySid(WindowTwoRecord.sid); _dimensions = rra.CreateDimensions(); records.Insert(dimsloc, _dimensions); } if (rra == null) { rra = new RowRecordsAggregate(); records.Insert(dimsloc + 1, rra); } _rowsAggregate = rra; // put merged cells table in the right place (regardless of where the first MergedCellsRecord was found */ RecordOrderer.AddNewSheetRecord(records, _mergedCellsTable); RecordOrderer.AddNewSheetRecord(records, _protectionBlock); //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "sheet createSheet (existing file) exited"); }
/// <summary> /// Initializes a new instance of the <see cref="HSSFFooter"/> class. /// </summary> /// <param name="psb">Footer record to Create the footer with</param> public HSSFHeader(PageSettingsBlock psb) { _psb = psb; }
/// <summary> /// Initializes a new instance of the <see cref="HSSFFooter"/> class. /// </summary> /// <param name="footerRecord">Footer record to Create the footer with</param> public HSSFHeader(PageSettingsBlock psb) { _psb = psb; }
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"); }
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"); }