Generate sheet tabs

@return    string
@throws PHPExcel_Writer_Exception
971142
public function generateNavigation()
    {
        // PHPExcel object known?
        if (is_null($this->phpExcel)) {
            throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
        }

        // Fetch sheets
        $sheets = array();
        if (is_null($this->sheetIndex)) {
            $sheets = $this->phpExcel->getAllSheets();
        } else {
            $sheets[] = $this->phpExcel->getSheet($this->sheetIndex);
        }

        // Construct HTML
        $html = '';

        // Only if there are more than 1 sheets
        if (count($sheets) > 1) {
            // Loop all sheets
            $sheetId = 0;

            $html .= '<ul class="navigation">' . PHP_EOL;

            foreach ($sheets as $sheet) {
                $html .= '  <li class="sheet' . $sheetId . '"><a href="#sheet' . $sheetId . '">' . $sheet->getTitle() . '</a></li>' . PHP_EOL;
                ++$sheetId;
            }

            $html .= '</ul>' . PHP_EOL;
        }

        return $html;
    }
1229324
public function createWorkbookFile($worksheets)
    {
        $workbookXmlFileContents = <<<EOD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <sheets>
EOD;

        /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
        $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance();

        /** @var Worksheet $worksheet */
        foreach ($worksheets as $worksheet) {
            $worksheetName = $worksheet->getExternalSheet()->getName();
            $worksheetId = $worksheet->getId();
            $workbookXmlFileContents .= '<sheet name="' . $escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '"/>';
        }

        $workbookXmlFileContents .= <<<EOD
    </sheets>
</workbook>
EOD;

        $this->createFileWithContents($this->xlFolder, self::WORKBOOK_XML_FILE_NAME, $workbookXmlFileContents);

        return $this;
    }
1217326
private function _writeSheetProtection()
	{
		// record identifier
		$record = 0x0867;

		// prepare options
		$options  =   (int) !$this->_phpSheet->getProtection()->getObjects()
					| (int) !$this->_phpSheet->getProtection()->getScenarios()           << 1
					| (int) !$this->_phpSheet->getProtection()->getFormatCells()         << 2
					| (int) !$this->_phpSheet->getProtection()->getFormatColumns()       << 3
					| (int) !$this->_phpSheet->getProtection()->getFormatRows()          << 4
					| (int) !$this->_phpSheet->getProtection()->getInsertColumns()       << 5
					| (int) !$this->_phpSheet->getProtection()->getInsertRows()          << 6
					| (int) !$this->_phpSheet->getProtection()->getInsertHyperlinks()    << 7
					| (int) !$this->_phpSheet->getProtection()->getDeleteColumns()       << 8
					| (int) !$this->_phpSheet->getProtection()->getDeleteRows()          << 9
					| (int) !$this->_phpSheet->getProtection()->getSelectLockedCells()   << 10
					| (int) !$this->_phpSheet->getProtection()->getSort()                << 11
					| (int) !$this->_phpSheet->getProtection()->getAutoFilter()          << 12
					| (int) !$this->_phpSheet->getProtection()->getPivotTables()         << 13
					| (int) !$this->_phpSheet->getProtection()->getSelectUnlockedCells() << 14 ;

		// record data
		$recordData = pack(
			'vVVCVVvv'
			, 0x0867		// repeated record identifier
			, 0x0000		// not used
			, 0x0000		// not used
			, 0x00			// not used
			, 0x01000200	// unknown data
			, 0xFFFFFFFF	// unknown data
			, $options		// options
			, 0x0000		// not used
		);

		$length = strlen($recordData);
		$header = pack('vv', $record, $length);

		$this->_append($header . $recordData);
	}
572649
public function generate()
    {
        $code = array();

        if ($this->namespace !== null) {
            $code[] = $this->getIndentation() . 'namespace ' . $this->namespace;
            $code[] = '{';
            $code[] = null;

            // Temporarily add one more level of indentation.
            $this->addIndentationLevel(1);
        }

        $code = array_merge($code, $this->renderUsesLines());

        $indentation = $this->getIndentation();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $line = $indentation . 'interface ' . $this->name;
        if (count($this->extends) > 0) {
            $line .= ' extends ' . implode(', ', $this->extends);
        }

        $code[] = $line;
        $code[] = $indentation . '{';

        // Interface constants.
        $interfaceElements = $this->generateConstantsLines();

        // Interface methods.
        foreach ($this->methods as $method) {
            if ($method->getVisibility() !== Modifiers::VISIBILITY_PUBLIC) {
                throw new RuntimeException('The visibility of methods must be public.');
            }

            $method->setIndentationString($this->getIndentationString());
            $method->setIndentationLevel($this->getIndentationLevel() + 1);

            $doc = $method->generateDocumentation();
            if ($doc !== null) {
                $interfaceElements[] = $doc;
            }

            $interfaceElements[] = $method->generateSignature() . ';';
            $interfaceElements[] = null;
        }

        if (count($interfaceElements) > 0) {
            $code[] = null;
            $code = array_merge($code, $interfaceElements);
            // Remove last empty line.
            array_pop($code);
        }

        $code[] = $indentation . '}';

        if ($this->namespace !== null) {
            // Set back the indentation.
            $this->addIndentationLevel(-1);

            $code[] = $this->getIndentation() . '}';
        }

        return implode($this->getLineFeed(), $code);
    }
1024051
protected function getTabs()
    {
        $tabs['default'] = array($this->_('Default'), 'title' => $this->_('To do 2 weeks ahead and done'));
        $tabs['todo']    = $this->_('To do');
        $tabs['done']    = $this->_('Done');
        $tabs['missed']  = $this->_('Missed');
        $tabs['all']     = $this->_('All');

        return $tabs;
    }
1181833
function _packExtRef($ext_ref)
	{
		$ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading  ' if any.
		$ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.

		// Check if there is a sheet range eg., Sheet1:Sheet2.
		if (preg_match("/:/", $ext_ref)) {
			list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);

			$sheet1 = $this->_getSheetIndex($sheet_name1);
			if ($sheet1 == -1) {
				throw new PHPExcel_Writer_Exception("Unknown sheet name $sheet_name1 in formula");
			}
			$sheet2 = $this->_getSheetIndex($sheet_name2);
			if ($sheet2 == -1) {
				throw new PHPExcel_Writer_Exception("Unknown sheet name $sheet_name2 in formula");
			}

			// Reverse max and min sheet numbers if necessary
			if ($sheet1 > $sheet2) {
				list($sheet1, $sheet2) = array($sheet2, $sheet1);
			}
		} else { // Single sheet name only.
			$sheet1 = $this->_getSheetIndex($ext_ref);
			if ($sheet1 == -1) {
				throw new PHPExcel_Writer_Exception("Unknown sheet name $ext_ref in formula");
			}
			$sheet2 = $sheet1;
		}

		// References are stored relative to 0xFFFF.
		$offset = -1 - $sheet1;

		return pack('vdvv', $offset, 0x00, $sheet1, $sheet2);
	}
844194
public function buildTab()
    {
        $tab = $this->tab;
        $tab->setParameters($this->parametersToView);
        $this->tab = null;
        $this->parametersToView = [];
        return $tab;
    }
540721
protected function createExcel()
    {
        $this->phpexcel = new \PHPExcel();
        $tableNumber = 0;

        // Loop over all tables in document
        foreach($this->document->getTables() as $table){

            // Handle worksheets
            if ($tableNumber > 0) {
                $this->phpexcel->createSheet();
            }
            $excelWorksheet = $this->phpexcel->setActiveSheetIndex($tableNumber);
            if ($sheetTitle = $table->getAttribute('_excel-name')) {
                $excelWorksheet->setTitle($sheetTitle);
            }

            // Loop over all rows
            $rowNumber = 1;
            foreach($table->getRows() as $row){

                $excelWorksheet->getStyle($rowNumber.':'.$rowNumber)->applyFromArray($this->getRowStylesArray($row));
                $this->setDimensions($excelWorksheet, $excelWorksheet->getRowIterator($rowNumber)->current(), $row);

                // Loop over all cells in row
                $cellNumber = 0;
                foreach($row->getCells() as $cell){
                    $excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber).$rowNumber;
                    
                    // Skip cells withing merge range
                    while ($excelWorksheet->getCell($excelCellIndex)->isInMergeRange()) {
                        $cellNumber++;
                        $excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber).$rowNumber;
                    }
                    
                    // Set value
                    $explicitCellType = $cell->getAttribute('_excel-explicit');
                    if (!$explicitCellType) {
                        $explicitCellType = $row->getAttribute('_excel-explicit');
                    }

                    if ($explicitCellType) {
                        $excelWorksheet->setCellValueExplicit(
                            $excelCellIndex,
                            $this->changeValueEncoding($cell->getValue()),
                            $this->convertStaticPhpExcelConstantsFromStringsToConstants($explicitCellType)
                        );
                    } else {
                        $excelWorksheet->setCellValue(
                            $excelCellIndex,
                            $this->changeValueEncoding($cell->getValue())
                        );
                    }

                    // Merge cells
                    $colspan = $cell->getAttribute('colspan');
                    $rowspan = $cell->getAttribute('rowspan');

                    if ($colspan || $rowspan) {
                        if ($colspan) {$colspan = $colspan - 1;}
                        if ($rowspan) {$rowspan = $rowspan - 1;}
                        $mergeCellsTargetCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber + $colspan).($rowNumber + $rowspan);
                        $excelWorksheet->mergeCells($excelCellIndex.':'.$mergeCellsTargetCellIndex);
                    }

                    // Set styles
                    $excelWorksheet->getStyle($excelCellIndex)->applyFromArray($this->getCellStylesArray($cell));
                    $this->setDimensions($excelWorksheet, $excelWorksheet->getCell($excelCellIndex), $cell);

                    $cellNumber++;
                }

                $rowNumber++;
            }

            $tableNumber++;
        }

        return $this->phpexcel;
    }
9377
protected function output()
    {
        ob_start();

        $writer = PHPExcel_IOFactory::createWriter($this->PhpExcel, 'Excel2007');

        if (!isset($writer)) {
            throw new Exception('Excel writer not found');
        }

        $writer->setPreCalculateFormulas(false);
        $writer->setIncludeCharts(true);
        $writer->save('php://output');

        $output = ob_get_clean();

        return $output;
    }
54364
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();
    }
631347
public function getTab()
    {
        if (is_null($this->tab)) {
            $this->tab = new Tab($this);
        }

        return $this->tab;
    }
795784
public function getFormFields()
    {
        if (!$theme = CmsTheme::load($this->theme)) {
            throw new Exception(Lang::get('Unable to find theme with name :name', $this->theme));
        }

        $config = $theme->getFormConfig();

        return array_get($config, 'fields', []) +
            array_get($config, 'tabs.fields', []) +
            array_get($config, 'secondaryTabs.fields', []);
    }
866496
public function generate()
    {
        $this->fill();
        $content = [];
        foreach ($this->_cells as $item) {
            $content[] = $item->generate();
        }
        //return implode('', $content);
        return Html::tag('div', implode('', $content), $this->htmlOptions);
    }
89171
public function getSheets()
    {
        $sheets = [];
        $sheetIndex = 0;
        $activeSheetIndex = 0; // By default, the first sheet is active

        $xmlReader = new XMLReader();
        if ($xmlReader->openFileInZip($this->filePath, self::WORKBOOK_XML_FILE_PATH)) {
            while ($xmlReader->read()) {
                if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_WORKBOOK_VIEW)) {
                    // The "workbookView" node is located before "sheet" nodes, ensuring that
                    // the active sheet is known before parsing sheets data.
                    $activeSheetIndex = (int) $xmlReader->getAttribute(self::XML_ATTRIBUTE_ACTIVE_TAB);
                } else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_SHEET)) {
                    $isSheetActive = ($sheetIndex === $activeSheetIndex);
                    $sheets[] = $this->getSheetFromSheetXMLNode($xmlReader, $sheetIndex, $isSheetActive);
                    $sheetIndex++;
                } else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_SHEETS)) {
                    // stop reading once all sheets have been read
                    break;
                }
            }

            $xmlReader->close();
        }

        return $sheets;
    }
558249
public function generateStyles($generateSurroundingHTML = true)
    {
        // PHPExcel object known?
        if (is_null($this->phpExcel)) {
            throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
        }

        // Build CSS
        $css = $this->buildCSS($generateSurroundingHTML);

        // Construct HTML
        $html = '';

        // Start styles
        if ($generateSurroundingHTML) {
            $html .= '    <style type="text/css">' . PHP_EOL;
            $html .= '      html { ' . $this->assembleCSS($css['html']) . ' }' . PHP_EOL;
        }

        // Write all other styles
        foreach ($css as $styleName => $styleDefinition) {
            if ($styleName != 'html') {
                $html .= '      ' . $styleName . ' { ' . $this->assembleCSS($styleDefinition) . ' }' . PHP_EOL;
            }
        }

        // End styles
        if ($generateSurroundingHTML) {
            $html .= '    </style>' . PHP_EOL;
        }

        // Return
        return $html;
    }
483974
private function writeSheetPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
    {
        // sheetPr
        $objWriter->startElement('sheetPr');
        //$objWriter->writeAttribute('codeName',        $pSheet->getTitle());
        if ($pSheet->getParent()->hasMacros()) {//if the workbook have macros, we need to have codeName for the sheet
            if ($pSheet->hasCodeName()==false) {
                $pSheet->setCodeName($pSheet->getTitle());
            }
            $objWriter->writeAttribute('codeName', $pSheet->getCodeName());
        }
        $autoFilterRange = $pSheet->getAutoFilter()->getRange();
        if (!empty($autoFilterRange)) {
            $objWriter->writeAttribute('filterMode', 1);
            $pSheet->getAutoFilter()->showHideRows();
        }

        // tabColor
        if ($pSheet->isTabColorSet()) {
            $objWriter->startElement('tabColor');
            $objWriter->writeAttribute('rgb', $pSheet->getTabColor()->getARGB());
            $objWriter->endElement();
        }

        // outlinePr
        $objWriter->startElement('outlinePr');
        $objWriter->writeAttribute('summaryBelow', ($pSheet->getShowSummaryBelow() ? '1' : '0'));
        $objWriter->writeAttribute('summaryRight', ($pSheet->getShowSummaryRight() ? '1' : '0'));
        $objWriter->endElement();

        // pageSetUpPr
        if ($pSheet->getPageSetup()->getFitToPage()) {
            $objWriter->startElement('pageSetUpPr');
            $objWriter->writeAttribute('fitToPage', '1');
            $objWriter->endElement();
        }

        $objWriter->endElement();
    }
1074834
public function dump(int $tab = 0): string
    {
        $declarations = implode(', ', array_keys($this->declarations));
        $usages = implode(', ', $this->usages);

        $self = sprintf("%s : {D : %s} {U : %s} \n", $name ?? 'noname', $declarations, $usages);

        $children = "";

        foreach ($this->children as $child) {
            $children .= str_repeat(" ", $tab) . $child->dump($tab + 4) . "\n";
        }

        return $self . $children;
    }