private bool ReadARecord(RecordStream rs) { switch (rs.PeekNextSid()) { case ProtectRecord.sid: CheckNotPresent(_protectRecord); _protectRecord = rs.GetNext() as ProtectRecord; break; case ObjectProtectRecord.sid: CheckNotPresent(_objectProtectRecord); _objectProtectRecord = rs.GetNext() as ObjectProtectRecord; break; case ScenarioProtectRecord.sid: CheckNotPresent(_scenarioProtectRecord); _scenarioProtectRecord = rs.GetNext() as ScenarioProtectRecord; break; case PasswordRecord.sid: CheckNotPresent(_passwordRecord); _passwordRecord = rs.GetNext() as PasswordRecord; break; default: // all other record types are not part of the PageSettingsBlock return false; } return true; }
public override Object Clone() { ScenarioProtectRecord rec = new ScenarioProtectRecord(); rec.field_1_protect = field_1_protect; return(rec); }
/// <summary> /// Creates a ScenarioProtect record with protect set to false. /// </summary> /// <returns></returns> private static ScenarioProtectRecord CreateScenarioProtect() { ScenarioProtectRecord retval = new ScenarioProtectRecord(); retval.Protect = (false); return retval; }
/// <summary> /// protect a spreadsheet with a password (not encrypted, just sets protect flags and the password.) /// </summary> /// <param name="password">password to set;Pass <code>null</code> to remove all protection</param> /// <param name="shouldProtectObjects">shouldProtectObjects are protected</param> /// <param name="shouldProtectScenarios">shouldProtectScenarios are protected</param> public void ProtectSheet(String password, bool shouldProtectObjects, bool shouldProtectScenarios) { if (password == null) { _passwordRecord = null; _protectRecord = null; _objectProtectRecord = null; _scenarioProtectRecord = null; return; } ProtectRecord prec = this.Protect; PasswordRecord pass = this.Password; prec.Protect = true; pass.Password = (PasswordRecord.HashPassword(password)); if (_objectProtectRecord == null && shouldProtectObjects) { ObjectProtectRecord rec = CreateObjectProtect(); rec.Protect = (true); _objectProtectRecord = rec; } if (_scenarioProtectRecord == null && shouldProtectScenarios) { ScenarioProtectRecord srec = CreateScenarioProtect(); srec.Protect = (true); _scenarioProtectRecord = srec; } }
public override Object Clone() { ScenarioProtectRecord rec = new ScenarioProtectRecord(); rec.field_1_protect = field_1_protect; return rec; }
/** * Creates a ScenarioProtect record with protect Set to false. * @see org.apache.poi.hssf.record.ScenarioProtectRecord * @see org.apache.poi.hssf.record.Record * @return a ScenarioProtectRecord */ protected ScenarioProtectRecord CreateScenarioProtect() { //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "Create protect record with protection disabled"); ScenarioProtectRecord retval = new ScenarioProtectRecord(); retval.Protect = (false); return retval; }
/** * protect a spReadsheet with a password (not encypted, just Sets protect * flags and the password. * @param password to Set * @param objects are protected * @param scenarios are protected */ public void ProtectSheet(String password, bool objects, bool scenarios) { int protIdx = -1; ProtectRecord prec = Protect; PasswordRecord pass = Password; prec.Protect = true; pass.Password = PasswordRecord.HashPassword(password); if ((objprotect == null && objects) || (scenprotect != null && scenarios)) { protIdx = records.IndexOf(protect); } if (objprotect == null && objects) { ObjectProtectRecord rec = CreateObjectProtect(); rec.Protect = (true); records.Insert(protIdx + 1, rec); objprotect = rec; } if (scenprotect == null && scenarios) { ScenarioProtectRecord srec = CreateScenarioProtect(); srec.Protect = (true); records.Insert(protIdx + 2, srec); scenprotect = srec; } }
/// <summary> /// Initializes a new instance of the <see cref="Sheet"/> class. /// </summary> /// <param name="rs">The stream.</param> private Sheet(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; 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) && bofEofNestingLevel == 1) { //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 (PageSettingsBlock.IsComponentRecord(recSid)) { PageSettingsBlock psb = new PageSettingsBlock(rs); if (bofEofNestingLevel == 1) { if (_psBlock == null) { _psBlock = psb; } else { // more than one 'Page Settings Block' at nesting level 1 ? // apparently this happens in about 15 test sample files } } records.Add(psb); 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; } 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 == BOFRecord.sid) { bofEofNestingLevel++; //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "Hit BOF record. Nesting increased to " + bofEofNestingLevel); } else if (recSid == EOFRecord.sid) { --bofEofNestingLevel; //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "Hit EOF record. Nesting decreased to " + bofEofNestingLevel); if (bofEofNestingLevel == 0) { records.Add(rec); break; } } else 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 == ProtectRecord.sid) { protect = (ProtectRecord)rec; } else if (recSid == ObjectProtectRecord.sid) { objprotect = (ObjectProtectRecord)rec; } else if (recSid == ScenarioProtectRecord.sid) { scenprotect = (ScenarioProtectRecord)rec; } else if (recSid == PasswordRecord.sid) { password = (PasswordRecord)rec; } else if (recSid == SheetExtRecord.sid) { sheetext = (SheetExtRecord)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); //if (log.Check(POILogger.DEBUG)) // log.Log(POILogger.DEBUG, "sheet createSheet (existing file) exited"); }