Example #1
0
        /**
         * Clone this record.
         */
        public override Object Clone()
        {
            PasswordRecord Clone = new PasswordRecord();

            Clone.Password = field_1_password;
            return(Clone);
        }
Example #2
0
 /**
  * Clone this record.
  */
 public override Object Clone()
 {
     PasswordRecord Clone = new PasswordRecord();
     Clone.Password=field_1_password;
     return Clone;
 }
 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;
 }
        /// <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;
            }
        }
Example #5
0
        /**
 * creates a Password record with password set to 00.
 */
        protected static PasswordRecord CreatePassword()
        {
            //if (log.check(POILogger.DEBUG))
            //    log.log(POILogger.DEBUG, "create password record with 00 password");
            PasswordRecord retval = new PasswordRecord((short)00);
            return retval;
        }
Example #6
0
        /**
         * Creates the Password record with password Set to 0.
         * @see org.apache.poi.hssf.record.PasswordRecord
         * @see org.apache.poi.hssf.record.Record
         * @return record containing a PasswordRecord
         */

        protected Record CreatePassword()
        {
            PasswordRecord retval = new PasswordRecord();

            retval.Password=(short)0;   // no password by default!
            return retval;
        }
Example #7
0
        /// <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");

        }
Example #8
0
        /**
         * Creates a Password record with password Set to 00.
         * @see org.apache.poi.hssf.record.PasswordRecord
         * @see org.apache.poi.hssf.record.Record
         * @return a PasswordRecord
         */
        protected PasswordRecord CreatePassword()
        {
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(POILogger.DEBUG, "Create password record with 00 password");
            PasswordRecord retval = new PasswordRecord();

            retval.Password = ((short)00);
            return retval;
        }