Пример #1
0
 /**
  * Write the worksheet PASSWORD record.
  */
 private function _writePassword()
 {
     // Exit unless sheet protection and password have been specified
     if (!$this->_phpSheet->getProtection()->getSheet() || !$this->_phpSheet->getProtection()->getPassword()) {
         return;
     }
     $record = 0x13;
     // Record identifier
     $length = 0x2;
     // Bytes to follow
     $wPassword = hexdec($this->_phpSheet->getProtection()->getPassword());
     // Encoded password
     $header = pack("vv", $record, $length);
     $data = pack("v", $wPassword);
     $this->_append($header . $data);
 }
Пример #2
0
 /**
  * Read SHEETPROTECTION record (FEATHEADR)
  */
 private function _readSheetProtection()
 {
     $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
     $recordData = substr($this->_data, $this->_pos + 4, $length);
     // move stream pointer to next record
     $this->_pos += 4 + $length;
     if ($this->_readDataOnly) {
         return;
     }
     // offset: 0; size: 2; repeated record header
     // offset: 2; size: 2; FRT cell reference flag (=0 currently)
     // offset: 4; size: 8; Currently not used and set to 0
     // offset: 12; size: 2; Shared feature type index (2=Enhanced Protetion, 4=SmartTag)
     $isf = $this->_GetInt2d($recordData, 12);
     if ($isf != 2) {
         return;
     }
     // offset: 14; size: 1; =1 since this is a feat header
     // offset: 15; size: 4; size of rgbHdrSData
     // rgbHdrSData, assume "Enhanced Protection"
     // offset: 19; size: 2; option flags
     $options = $this->_GetInt2d($recordData, 19);
     // bit: 0; mask 0x0001; 1 = user may edit objects, 0 = users must not edit objects
     $bool = (0x1 & $options) >> 0;
     $this->_phpSheet->getProtection()->setObjects(!$bool);
     // bit: 1; mask 0x0002; edit scenarios
     $bool = (0x2 & $options) >> 1;
     $this->_phpSheet->getProtection()->setScenarios(!$bool);
     // bit: 2; mask 0x0004; format cells
     $bool = (0x4 & $options) >> 2;
     $this->_phpSheet->getProtection()->setFormatCells(!$bool);
     // bit: 3; mask 0x0008; format columns
     $bool = (0x8 & $options) >> 3;
     $this->_phpSheet->getProtection()->setFormatColumns(!$bool);
     // bit: 4; mask 0x0010; format rows
     $bool = (0x10 & $options) >> 4;
     $this->_phpSheet->getProtection()->setFormatRows(!$bool);
     // bit: 5; mask 0x0020; insert columns
     $bool = (0x20 & $options) >> 5;
     $this->_phpSheet->getProtection()->setInsertColumns(!$bool);
     // bit: 6; mask 0x0040; insert rows
     $bool = (0x40 & $options) >> 6;
     $this->_phpSheet->getProtection()->setInsertRows(!$bool);
     // bit: 7; mask 0x0080; insert hyperlinks
     $bool = (0x80 & $options) >> 7;
     $this->_phpSheet->getProtection()->setInsertHyperlinks(!$bool);
     // bit: 8; mask 0x0100; delete columns
     $bool = (0x100 & $options) >> 8;
     $this->_phpSheet->getProtection()->setDeleteColumns(!$bool);
     // bit: 9; mask 0x0200; delete rows
     $bool = (0x200 & $options) >> 9;
     $this->_phpSheet->getProtection()->setDeleteRows(!$bool);
     // bit: 10; mask 0x0400; select locked cells
     $bool = (0x400 & $options) >> 10;
     $this->_phpSheet->getProtection()->setSelectLockedCells(!$bool);
     // bit: 11; mask 0x0800; sort cell range
     $bool = (0x800 & $options) >> 11;
     $this->_phpSheet->getProtection()->setSort(!$bool);
     // bit: 12; mask 0x1000; auto filter
     $bool = (0x1000 & $options) >> 12;
     $this->_phpSheet->getProtection()->setAutoFilter(!$bool);
     // bit: 13; mask 0x2000; pivot tables
     $bool = (0x2000 & $options) >> 13;
     $this->_phpSheet->getProtection()->setPivotTables(!$bool);
     // bit: 14; mask 0x4000; select unlocked cells
     $bool = (0x4000 & $options) >> 14;
     $this->_phpSheet->getProtection()->setSelectUnlockedCells(!$bool);
     // offset: 21; size: 2; not used
 }
Пример #3
0
 /**
  * Write SheetProtection
  *
  * @param	Shared_XMLWriter			$objWriter		XML Writer
  * @param	Worksheet					$pSheet			Worksheet
  * @throws	Exception
  */
 private function _writeSheetProtection(Shared_XMLWriter $objWriter = null, Worksheet $pSheet = null)
 {
     // sheetProtection
     $objWriter->startElement('sheetProtection');
     if ($pSheet->getProtection()->getPassword() != '') {
         $objWriter->writeAttribute('password', $pSheet->getProtection()->getPassword());
     }
     $objWriter->writeAttribute('sheet', $pSheet->getProtection()->getSheet() ? 'true' : 'false');
     $objWriter->writeAttribute('objects', $pSheet->getProtection()->getObjects() ? 'true' : 'false');
     $objWriter->writeAttribute('scenarios', $pSheet->getProtection()->getScenarios() ? 'true' : 'false');
     $objWriter->writeAttribute('formatCells', $pSheet->getProtection()->getFormatCells() ? 'true' : 'false');
     $objWriter->writeAttribute('formatColumns', $pSheet->getProtection()->getFormatColumns() ? 'true' : 'false');
     $objWriter->writeAttribute('formatRows', $pSheet->getProtection()->getFormatRows() ? 'true' : 'false');
     $objWriter->writeAttribute('insertColumns', $pSheet->getProtection()->getInsertColumns() ? 'true' : 'false');
     $objWriter->writeAttribute('insertRows', $pSheet->getProtection()->getInsertRows() ? 'true' : 'false');
     $objWriter->writeAttribute('insertHyperlinks', $pSheet->getProtection()->getInsertHyperlinks() ? 'true' : 'false');
     $objWriter->writeAttribute('deleteColumns', $pSheet->getProtection()->getDeleteColumns() ? 'true' : 'false');
     $objWriter->writeAttribute('deleteRows', $pSheet->getProtection()->getDeleteRows() ? 'true' : 'false');
     $objWriter->writeAttribute('selectLockedCells', $pSheet->getProtection()->getSelectLockedCells() ? 'true' : 'false');
     $objWriter->writeAttribute('sort', $pSheet->getProtection()->getSort() ? 'true' : 'false');
     $objWriter->writeAttribute('autoFilter', $pSheet->getProtection()->getAutoFilter() ? 'true' : 'false');
     $objWriter->writeAttribute('pivotTables', $pSheet->getProtection()->getPivotTables() ? 'true' : 'false');
     $objWriter->writeAttribute('selectUnlockedCells', $pSheet->getProtection()->getSelectUnlockedCells() ? 'true' : 'false');
     $objWriter->endElement();
 }