コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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;
            }
        }
コード例 #3
0
        /// <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 = (short)CryptoFunctions.CreateXorVerifier1(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;
            }
        }
コード例 #4
0
ファイル: TestHSSFSheet.cs プロジェクト: thinhmascot/NPOI
        public void TestProtectSheet()
        {
            short        expected = unchecked ((short)0xfef1);
            HSSFWorkbook wb       = new HSSFWorkbook();
            HSSFSheet    s        = (HSSFSheet)wb.CreateSheet();

            s.ProtectSheet("abcdefghij");
            NPOI.HSSF.Model.Sheet sheet   = s.Sheet;
            ProtectRecord         Protect = sheet.Protect;
            PasswordRecord        pass    = sheet.Password;

            Assert.IsTrue(Protect.Protect, "Protection should be on");
            Assert.IsTrue(sheet.IsProtected[1], "object Protection should be on");
            Assert.IsTrue(sheet.IsProtected[2], "scenario Protection should be on");
            Assert.AreEqual(expected, pass.Password, "well known value for top secret hash should be " + NPOI.Util.StringUtil.ToHexString(expected).Substring(4));
        }
コード例 #5
0
ファイル: TestHSSFSheet.cs プロジェクト: thinhmascot/NPOI
        public void TestProtect()
        {
            HSSFWorkbook workbook  = new HSSFWorkbook();
            HSSFSheet    hssfSheet = (HSSFSheet)workbook.CreateSheet();

            NPOI.HSSF.Model.Sheet sheet   = hssfSheet.Sheet;
            ProtectRecord         Protect = sheet.Protect;

            Assert.IsFalse(Protect.Protect);

            // This will tell us that CloneSheet, and by extension,
            // the list forms of CreateSheet leave us with an accessible
            // ProtectRecord.
            hssfSheet.ProtectSheet("secret");
            NPOI.HSSF.Model.Sheet Cloned = sheet.CloneSheet();
            Assert.IsNotNull(Cloned.Protect);
            Assert.IsTrue(hssfSheet.Protect);
        }
コード例 #6
0
ファイル: InternalChart.cs プロジェクト: zzy092/npoi
        public InternalChart(RecordStream rs)
        {
            _plsRecords = new List <PLSAggregate>();
            records     = new List <RecordBase>(128);

            if (rs.PeekNextSid() != BOFRecord.sid)
            {
                throw new Exception("BOF record expected");
            }
            BOFRecord bof = (BOFRecord)rs.GetNext();

            if (bof.Type != BOFRecordType.Chart)
            {
                throw new RuntimeException("Bad BOF record type");
            }

            records.Add(bof);
            while (rs.HasNext())
            {
                int recSid = rs.PeekNextSid();

                Record.Record rec = rs.GetNext();
                if (recSid == EOFRecord.sid)
                {
                    records.Add(rec);
                    break;
                }

                if (recSid == ChartRecord.sid)
                {
                    continue;
                }

                if (recSid == ChartFRTInfoRecord.sid)
                {
                    _chartFrtInfo = (ChartFRTInfoRecord)rec;
                }
                else if (recSid == HeaderRecord.sid)
                {
                    header = (HeaderRecord)rec;
                }
                else if (recSid == FooterRecord.sid)
                {
                    footer = (FooterRecord)rec;
                }
                else if (recSid == HCenterRecord.sid)
                {
                    _hCenter = (HCenterRecord)rec;
                }
                else if (recSid == VCenterRecord.sid)
                {
                    _vCenter = (VCenterRecord)rec;
                }
                else if (recSid == LeftMarginRecord.sid)
                {
                    _leftMargin = (LeftMarginRecord)rec;
                }
                else if (recSid == RightMarginRecord.sid)
                {
                    _rightMargin = (RightMarginRecord)rec;
                }
                else if (recSid == TopMarginRecord.sid)
                {
                    _topMargin = (TopMarginRecord)rec;
                }
                else if (recSid == BottomMarginRecord.sid)
                {
                    _bottomMargin = (BottomMarginRecord)rec;
                }
                else if (recSid == UnknownRecord.PLS_004D) // PLS
                {
                    PLSAggregate        pls = new PLSAggregate(rs);
                    PLSAggregateVisitor rv  = new PLSAggregateVisitor(records);
                    pls.VisitContainedRecords(rv);
                    _plsRecords.Add(pls);

                    continue;
                }
                else if (recSid == PrintSetupRecord.sid)
                {
                    printSetup = (PrintSetupRecord)rec;
                }
                else if (recSid == PrintSizeRecord.sid)
                {
                    _printSize = (PrintSizeRecord)rec;
                }
                else if (recSid == HeaderFooterRecord.sid)
                {
                    HeaderFooterRecord hf = (HeaderFooterRecord)rec;
                    if (hf.IsCurrentSheet)
                    {
                        _headerFooter = hf;
                    }
                    else
                    {
                        _sviewHeaderFooters.Add(hf);
                    }
                }
                else if (recSid == ProtectRecord.sid)
                {
                    _protect = (ProtectRecord)rec;
                }
                records.Add(rec);
            }
        }