/** * 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); }
/** * Write SheetProtection * * @param \PHPExcel\Shared\XMLWriter $objWriter XML Writer * @param \PHPExcel\Worksheet $pSheet Worksheet * @throws \PHPExcel\Writer\Exception */ private function writeSheetProtection(\PHPExcel\Shared\XMLWriter $objWriter = null, \PHPExcel\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(); }