Write the EXTERNCOUNT and EXTERNSHEET records. These are used as indexes for
the NAME records.

@access private
161256
function _storeExterns()
    {
        // Create EXTERNCOUNT with number of worksheets
        $this->_storeExterncount(count($this->_worksheets));

        // Create EXTERNSHEET for each worksheet
        foreach ($this->_sheetnames as $sheetname) {
            $this->_storeExternsheet($sheetname);
        }
    }
1177404
void writeExternal(DataOutput out) throws IOException {
        final int timeSecs = time.toSecondOfDay() + adjustDays * SECS_PER_DAY;
        final int stdOffset = standardOffset.getTotalSeconds();
        final int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
        final int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
        final int timeByte = (timeSecs % 3600 == 0 && timeSecs <= SECS_PER_DAY ?
                (timeSecs == SECS_PER_DAY ? 24 : time.getHour()) : 31);
        final int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
        final int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
        final int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
        final int dowByte = (dow == null ? 0 : dow.getValue());
        int b = (month.getValue() << 28) +          // 4 bits
                ((dom + 32) << 22) +                // 6 bits
                (dowByte << 19) +                   // 3 bits
                (timeByte << 14) +                  // 5 bits
                (timeDefinition.ordinal() << 12) +  // 2 bits
                (stdOffsetByte << 4) +              // 8 bits
                (beforeByte << 2) +                 // 2 bits
                afterByte;                          // 2 bits
        out.writeInt(b);
        if (timeByte == 31) {
            out.writeInt(timeSecs);
        }
        if (stdOffsetByte == 255) {
            out.writeInt(stdOffset);
        }
        if (beforeByte == 3) {
            out.writeInt(offsetBefore.getTotalSeconds());
        }
        if (afterByte == 3) {
            out.writeInt(offsetAfter.getTotalSeconds());
        }
    }
414318
private function _readExternName()
	{
		$length = self::_GetInt2d($this->_data, $this->_pos + 2);
		$recordData = substr($this->_data, $this->_pos + 4, $length);

		// move stream pointer to next record
		$this->_pos += 4 + $length;

		// external sheet references provided for named cells
		if ($this->_version == self::XLS_BIFF8) {
			// offset: 0; size: 2; options
			$options = self::_GetInt2d($recordData, 0);

			// offset: 2; size: 2;

			// offset: 4; size: 2; not used

			// offset: 6; size: var
			$nameString = self::_readUnicodeStringShort(substr($recordData, 6));

			// offset: var; size: var; formula data
			$offset = 6 + $nameString['size'];
			$formula = $this->_getFormulaFromStructure(substr($recordData, $offset));

			$this->_externalNames[] = array(
				'name' => $nameString['value'],
				'formula' => $formula,
			);
		}
	}
1096785
private function _writeWindow1()
	{
		$record    = 0x003D;                 // Record identifier
		$length    = 0x0012;                 // Number of bytes to follow

		$xWn       = 0x0000;                 // Horizontal position of window
		$yWn       = 0x0000;                 // Vertical position of window
		$dxWn      = 0x25BC;                 // Width of window
		$dyWn      = 0x1572;                 // Height of window

		$grbit     = 0x0038;                 // Option flags

		// not supported by PHPExcel, so there is only one selected sheet, the active
		$ctabsel   = 1;       // Number of workbook tabs selected

		$wTabRatio = 0x0258;                 // Tab to scrollbar ratio

		// not supported by PHPExcel, set to 0
		$itabFirst = 0;     // 1st displayed worksheet
		$itabCur   = $this->_phpExcel->getActiveSheetIndex();    // Active worksheet

		$header    = pack("vv",        $record, $length);
		$data      = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn,
									   $grbit,
									   $itabCur, $itabFirst,
									   $ctabsel, $wTabRatio);
		$this->_append($header . $data);
	}
1190225
private function _writeDefaultRowHeight()
	{
		$defaultRowHeight = $this->_phpSheet->getDefaultRowDimension()->getRowHeight();

		if ($defaultRowHeight < 0) {
			return;
		}

		// convert to twips
		$defaultRowHeight = (int) 20 * $defaultRowHeight;

		$record   = 0x0225;	  // Record identifier
		$length   = 0x0004;	  // Number of bytes to follow

		$header   = pack("vv", $record, $length);
		$data	 = pack("vv",  1, $defaultRowHeight);
		$this->_append($header . $data);
	}
1356093
private function writeDefinedNames(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null)
    {
        // Write defined names
        $objWriter->startElement('definedNames');

        // Named ranges
        if (count($pPHPExcel->getNamedRanges()) > 0) {
            // Named ranges
            $this->writeNamedRanges($objWriter, $pPHPExcel);
        }

        // Other defined names
        $sheetCount = $pPHPExcel->getSheetCount();
        for ($i = 0; $i < $sheetCount; ++$i) {
            // definedName for autoFilter
            $this->writeDefinedNameForAutofilter($objWriter, $pPHPExcel->getSheet($i), $i);

            // definedName for Print_Titles
            $this->writeDefinedNameForPrintTitles($objWriter, $pPHPExcel->getSheet($i), $i);

            // definedName for Print_Area
            $this->writeDefinedNameForPrintArea($objWriter, $pPHPExcel->getSheet($i), $i);
        }

        $objWriter->endElement();
    }
265626
private void writeEOFRecord() throws IOException {
        for (int i = 0; i < this.recordBuf.length; ++i) {
            this.recordBuf[i] = 0;
        }

        this.buffer.writeRecord(this.recordBuf);
    }
1090804
private function writeSheets(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null)
    {
        // Write sheets
        $objWriter->startElement('sheets');
        $sheetCount = $pPHPExcel->getSheetCount();
        for ($i = 0; $i < $sheetCount; ++$i) {
            // sheet
            $this->writeSheet(
                $objWriter,
                $pPHPExcel->getSheet($i)->getTitle(),
                ($i + 1),
                ($i + 1 + 3),
                $pPHPExcel->getSheet($i)->getSheetState()
            );
        }

        $objWriter->endElement();
    }
647603
function _storeExternsheetBiff8()
    {
        $total_references = count($this->_parser->_references);
        $record   = 0x0017;                     // Record identifier
        $length   = 2 + 6 * $total_references;  // Number of bytes to follow

        $supbook_index = 0;           // FIXME: only using internal SUPBOOK record
        $header           = pack("vv",  $record, $length);
        $data             = pack('v', $total_references);
        for ($i = 0; $i < $total_references; $i++) {
            $data .= $this->_parser->_references[$i];
        }
        $this->_append($header . $data);
    }
828891
private function _writeDefinedNames(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null)
	{
		// Write defined names
		$objWriter->startElement('definedNames');

		// Named ranges
		if (count($pPHPExcel->getNamedRanges()) > 0) {
			// Named ranges
			$this->_writeNamedRanges($objWriter, $pPHPExcel);
		}

		// Other defined names
		$sheetCount = $pPHPExcel->getSheetCount();
		for ($i = 0; $i < $sheetCount; ++$i) {
			// definedName for autoFilter
			$this->_writeDefinedNameForAutofilter($objWriter, $pPHPExcel->getSheet($i), $i);

			// definedName for Print_Titles
			$this->_writeDefinedNameForPrintTitles($objWriter, $pPHPExcel->getSheet($i), $i);

			// definedName for Print_Area
			$this->_writeDefinedNameForPrintArea($objWriter, $pPHPExcel->getSheet($i), $i);
		}

		$objWriter->endElement();
	}
383935
void writeExternal(DataOutput out) throws IOException {
        out.writeInt(standardTransitions.length);
        for (long trans : standardTransitions) {
            Ser.writeEpochSec(trans, out);
        }
        for (ZoneOffset offset : standardOffsets) {
            Ser.writeOffset(offset, out);
        }
        out.writeInt(savingsInstantTransitions.length);
        for (long trans : savingsInstantTransitions) {
            Ser.writeEpochSec(trans, out);
        }
        for (ZoneOffset offset : wallOffsets) {
            Ser.writeOffset(offset, out);
        }
        out.writeByte(lastRules.length);
        for (ZoneOffsetTransitionRule rule : lastRules) {
            rule.writeExternal(out);
        }
    }
112397
private function _writeHcenter()
	{
		$record   = 0x0083;			  // Record identifier
		$length   = 0x0002;			  // Bytes to follow

		$fHCenter = $this->_phpSheet->getPageSetup()->getHorizontalCentered() ? 1 : 0;	 // Horizontal centering

		$header	= pack("vv", $record, $length);
		$data	  = pack("v",  $fHCenter);

		$this->_append($header.$data);
	}
1047570
private function _writeMarginRight()
	{
		$record  = 0x0027;				   // Record identifier
		$length  = 0x0008;				   // Bytes to follow

		$margin  = $this->_phpSheet->getPageMargins()->getRight();	 // Margin in inches

		$header	= pack("vv",  $record, $length);
		$data	  = pack("d",   $margin);
		if (self::getByteOrder()) { // if it's Big Endian
			$data = strrev($data);
		}

		$this->_append($header . $data);
	}
1308678
private function _writeNamedRanges(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel)
	{
		// Loop named ranges
		$namedRanges = $pPHPExcel->getNamedRanges();
		foreach ($namedRanges as $namedRange) {
			$this->_writeDefinedNameForNamedRange($objWriter, $namedRange);
		}
	}
293644
private function readExternName()
    {
        $length = self::getInt2d($this->data, $this->pos + 2);
        $recordData = $this->readRecordData($this->data, $this->pos + 4, $length);

        // move stream pointer to next record
        $this->pos += 4 + $length;

        // external sheet references provided for named cells
        if ($this->version == self::XLS_BIFF8) {
            // offset: 0; size: 2; options
            $options = self::getInt2d($recordData, 0);

            // offset: 2; size: 2;

            // offset: 4; size: 2; not used

            // offset: 6; size: var
            $nameString = self::readUnicodeStringShort(substr($recordData, 6));

            // offset: var; size: var; formula data
            $offset = 6 + $nameString['size'];
            $formula = $this->getFormulaFromStructure(substr($recordData, $offset));

            $this->externalNames[] = array(
                'name' => $nameString['value'],
                'formula' => $formula,
            );
        }
    }
939284
private function _writeWindow2()
	{
		$record		 = 0x023E;	 // Record identifier
		$length		 = 0x0012;

		$grbit		  = 0x00B6;	 // Option flags
		$rwTop		  = 0x0000;	 // Top row visible in window
		$colLeft		= 0x0000;	 // Leftmost column visible in window


		// The options flags that comprise $grbit
		$fDspFmla	   = 0;					 // 0 - bit
		$fDspGrid	   = $this->_phpSheet->getShowGridlines() ? 1 : 0; // 1
		$fDspRwCol	  = $this->_phpSheet->getShowRowColHeaders() ? 1 : 0; // 2
		$fFrozen		= $this->_phpSheet->getFreezePane() ? 1 : 0;		// 3
		$fDspZeros	  = 1;					 // 4
		$fDefaultHdr	= 1;					 // 5
		$fArabic		= $this->_phpSheet->getRightToLeft() ? 1 : 0; // 6
		$fDspGuts	   = $this->_outline_on;	// 7
		$fFrozenNoSplit = 0;					 // 0 - bit
		// no support in PHPExcel for selected sheet, therefore sheet is only selected if it is the active sheet
		$fSelected	  = ($this->_phpSheet === $this->_phpSheet->getParent()->getActiveSheet()) ? 1 : 0;
		$fPaged		 = 1;					 // 2
		$fPageBreakPreview = $this->_phpSheet->getSheetView()->getView() === PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW;

		$grbit			 = $fDspFmla;
		$grbit			|= $fDspGrid	   << 1;
		$grbit			|= $fDspRwCol	   << 2;
		$grbit			|= $fFrozen		   << 3;
		$grbit			|= $fDspZeros	   << 4;
		$grbit			|= $fDefaultHdr	   << 5;
		$grbit			|= $fArabic		   << 6;
		$grbit			|= $fDspGuts	   << 7;
		$grbit			|= $fFrozenNoSplit << 8;
		$grbit			|= $fSelected	   << 9;
		$grbit			|= $fPaged		   << 10;
		$grbit			|= $fPageBreakPreview << 11;

		$header  = pack("vv",   $record, $length);
		$data	= pack("vvv", $grbit, $rwTop, $colLeft);

		// FIXME !!!
		$rgbHdr	   = 0x0040; // Row/column heading and gridline color index
		$zoom_factor_page_break = ($fPageBreakPreview? $this->_phpSheet->getSheetView()->getZoomScale() : 0x0000);
		$zoom_factor_normal =  $this->_phpSheet->getSheetView()->getZoomScaleNormal();

		$data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);

		$this->_append($header.$data);
	}
1025788
public function write()
    {
        $stats = array('hits' => $this->hits, 'misses' => $this->misses);

        file_put_contents($this->getFilename(), serialize($stats));
    }