188        $this->writerPartChart = 
new Chart($this);
 
  189        $this->writerPartComments = 
new Comments($this);
 
  190        $this->writerPartContentTypes = 
new ContentTypes($this);
 
  191        $this->writerPartDocProps = 
new DocProps($this);
 
  192        $this->writerPartDrawing = 
new Drawing($this);
 
  193        $this->writerPartRels = 
new Rels($this);
 
  194        $this->writerPartRelsRibbon = 
new RelsRibbon($this);
 
  195        $this->writerPartRelsVBA = 
new RelsVBA($this);
 
  196        $this->writerPartStringTable = 
new StringTable($this);
 
  197        $this->writerPartStyle = 
new Style($this);
 
  198        $this->writerPartTheme = 
new Theme($this);
 
  199        $this->writerPartWorkbook = 
new Workbook($this);
 
  200        $this->writerPartWorksheet = 
new Worksheet($this);
 
  204        $this->bordersHashTable = 
new HashTable();
 
  206        $this->drawingHashTable = 
new HashTable();
 
  212        $this->numFmtHashTable = 
new HashTable();
 
  216        $this->stylesConditionalHashTable = 
new HashTable();
 
  289    public function save($pFilename): void
 
  292        $this->pathNames = [];
 
  293        $this->spreadSheet->garbageCollect();
 
  301        $this->stringTable = [];
 
  302        for (
$i = 0; 
$i < $this->spreadSheet->getSheetCount(); ++
$i) {
 
  303            $this->stringTable = $this->
getWriterPartStringTable()->createStringTable($this->spreadSheet->getSheet(
$i), $this->stringTable);
 
  307        $this->styleHashTable->addFromSource($this->
getWriterPartStyle()->allStyles($this->spreadSheet));
 
  308        $this->stylesConditionalHashTable->addFromSource($this->
getWriterPartStyle()->allConditionalStyles($this->spreadSheet));
 
  309        $this->fillHashTable->addFromSource($this->
getWriterPartStyle()->allFills($this->spreadSheet));
 
  310        $this->fontHashTable->addFromSource($this->
getWriterPartStyle()->allFonts($this->spreadSheet));
 
  311        $this->bordersHashTable->addFromSource($this->
getWriterPartStyle()->allBorders($this->spreadSheet));
 
  312        $this->numFmtHashTable->addFromSource($this->
getWriterPartStyle()->allNumberFormats($this->spreadSheet));
 
  315        $this->drawingHashTable->addFromSource($this->
getWriterPartDrawing()->allDrawings($this->spreadSheet));
 
  319        $zipContent[
'[Content_Types].xml'] = $this->
getWriterPartContentTypes()->writeContentTypes($this->spreadSheet, $this->includeCharts);
 
  322        if ($this->spreadSheet->hasMacros()) {
 
  323            $macrosCode = $this->spreadSheet->getMacrosCode();
 
  324            if ($macrosCode !== 
null) {
 
  326                $zipContent[
'xl/vbaProject.bin'] = $macrosCode; 
 
  327                if ($this->spreadSheet->hasMacrosCertificate()) {
 
  330                    $zipContent[
'xl/vbaProjectSignature.bin'] = $this->spreadSheet->getMacrosCertificate();
 
  331                    $zipContent[
'xl/_rels/vbaProject.bin.rels'] = $this->
getWriterPartRelsVBA()->writeVBARelationships($this->spreadSheet);
 
  336        if ($this->spreadSheet->hasRibbon()) {
 
  337            $tmpRibbonTarget = $this->spreadSheet->getRibbonXMLData(
'target');
 
  338            $zipContent[$tmpRibbonTarget] = $this->spreadSheet->getRibbonXMLData(
'data');
 
  339            if ($this->spreadSheet->hasRibbonBinObjects()) {
 
  340                $tmpRootPath = dirname($tmpRibbonTarget) . 
'/';
 
  341                $ribbonBinObjects = $this->spreadSheet->getRibbonBinObjects(
'data'); 
 
  342                foreach ($ribbonBinObjects as $aPath => $aContent) {
 
  343                    $zipContent[$tmpRootPath . $aPath] = $aContent;
 
  346                $zipContent[$tmpRootPath . 
'_rels/' . basename($tmpRibbonTarget) . 
'.rels'] = $this->
getWriterPartRelsRibbon()->writeRibbonRelationships($this->spreadSheet);
 
  351        $zipContent[
'_rels/.rels'] = $this->
getWriterPartRels()->writeRelationships($this->spreadSheet);
 
  352        $zipContent[
'xl/_rels/workbook.xml.rels'] = $this->
getWriterPartRels()->writeWorkbookRelationships($this->spreadSheet);
 
  355        $zipContent[
'docProps/app.xml'] = $this->
getWriterPartDocProps()->writeDocPropsApp($this->spreadSheet);
 
  356        $zipContent[
'docProps/core.xml'] = $this->
getWriterPartDocProps()->writeDocPropsCore($this->spreadSheet);
 
  358        if ($customPropertiesPart !== 
null) {
 
  359            $zipContent[
'docProps/custom.xml'] = $customPropertiesPart;
 
  363        $zipContent[
'xl/theme/theme1.xml'] = $this->
getWriterPartTheme()->writeTheme($this->spreadSheet);
 
  369        $zipContent[
'xl/styles.xml'] = $this->
getWriterPartStyle()->writeStyles($this->spreadSheet);
 
  372        $zipContent[
'xl/workbook.xml'] = $this->
getWriterPartWorkbook()->writeWorkbook($this->spreadSheet, $this->preCalculateFormulas);
 
  376        for (
$i = 0; 
$i < $this->spreadSheet->getSheetCount(); ++
$i) {
 
  378            if ($this->includeCharts) {
 
  379                $charts = $this->spreadSheet->getSheet(
$i)->getChartCollection();
 
  380                if (count($charts) > 0) {
 
  381                    foreach ($charts as $chart) {
 
  382                        $zipContent[
'xl/charts/chart' . ($chartCount + 1) . 
'.xml'] = $this->
getWriterPartChart()->writeChart($chart, $this->preCalculateFormulas);
 
  391        for (
$i = 0; 
$i < $this->spreadSheet->getSheetCount(); ++
$i) {
 
  393            $zipContent[
'xl/worksheets/_rels/sheet' . (
$i + 1) . 
'.xml.rels'] = $this->
getWriterPartRels()->writeWorksheetRelationships($this->spreadSheet->getSheet(
$i), (
$i + 1), $this->includeCharts);
 
  396            $sheetCodeName = $this->spreadSheet->getSheet(
$i)->getCodeName();
 
  397            $unparsedLoadedData = $this->spreadSheet->getUnparsedLoadedData();
 
  398            if (isset($unparsedLoadedData[
'sheets'][$sheetCodeName][
'ctrlProps'])) {
 
  399                foreach ($unparsedLoadedData[
'sheets'][$sheetCodeName][
'ctrlProps'] as $ctrlProp) {
 
  400                    $zipContent[$ctrlProp[
'filePath']] = $ctrlProp[
'content'];
 
  403            if (isset($unparsedLoadedData[
'sheets'][$sheetCodeName][
'printerSettings'])) {
 
  404                foreach ($unparsedLoadedData[
'sheets'][$sheetCodeName][
'printerSettings'] as $ctrlProp) {
 
  405                    $zipContent[$ctrlProp[
'filePath']] = $ctrlProp[
'content'];
 
  409            $drawings = $this->spreadSheet->getSheet(
$i)->getDrawingCollection();
 
  410            $drawingCount = count($drawings);
 
  411            if ($this->includeCharts) {
 
  412                $chartCount = $this->spreadSheet->getSheet(
$i)->getChartCount();
 
  416            if (($drawingCount > 0) || ($chartCount > 0)) {
 
  422            } elseif (isset($unparsedLoadedData[
'sheets'][$sheetCodeName][
'drawingAlternateContents'])) {
 
  428            if (isset($unparsedLoadedData[
'sheets'][$sheetCodeName][
'Drawings'])) {
 
  429                foreach ($unparsedLoadedData[
'sheets'][$sheetCodeName][
'Drawings'] as $relId => $drawingXml) {
 
  430                    $drawingFile = array_search($relId, $unparsedLoadedData[
'sheets'][$sheetCodeName][
'drawingOriginalIds']);
 
  431                    if ($drawingFile !== 
false) {
 
  432                        $drawingFile = ltrim($drawingFile, 
'.');
 
  433                        $zipContent[
'xl' . $drawingFile] = $drawingXml;
 
  439            if (count($this->spreadSheet->getSheet(
$i)->getComments()) > 0) {
 
  441                $zipContent[
'xl/drawings/vmlDrawing' . (
$i + 1) . 
'.vml'] = $this->
getWriterPartComments()->writeVMLComments($this->spreadSheet->getSheet(
$i));
 
  444                $zipContent[
'xl/comments' . (
$i + 1) . 
'.xml'] = $this->
getWriterPartComments()->writeComments($this->spreadSheet->getSheet(
$i));
 
  448            if (isset($unparsedLoadedData[
'sheets'][$sheetCodeName][
'vmlDrawings'])) {
 
  449                foreach ($unparsedLoadedData[
'sheets'][$sheetCodeName][
'vmlDrawings'] as $vmlDrawing) {
 
  450                    $zipContent[$vmlDrawing[
'filePath']] = $vmlDrawing[
'content'];
 
  455            if (count($this->spreadSheet->getSheet(
$i)->getHeaderFooter()->getImages()) > 0) {
 
  457                $zipContent[
'xl/drawings/vmlDrawingHF' . (
$i + 1) . 
'.vml'] = $this->
getWriterPartDrawing()->writeVMLHeaderFooterImages($this->spreadSheet->getSheet(
$i));
 
  460                $zipContent[
'xl/drawings/_rels/vmlDrawingHF' . (
$i + 1) . 
'.vml.rels'] = $this->
getWriterPartRels()->writeHeaderFooterDrawingRelationships($this->spreadSheet->getSheet(
$i));
 
  463                foreach ($this->spreadSheet->getSheet(
$i)->getHeaderFooter()->getImages() as $image) {
 
  464                    $zipContent[
'xl/media/' . $image->getIndexedFilename()] = file_get_contents($image->getPath());
 
  472                $imageContents = 
null;
 
  474                if (strpos($imagePath, 
'zip://') !== 
false) {
 
  475                    $imagePath = substr($imagePath, 6);
 
  476                    $imagePathSplitted = explode(
'#', $imagePath);
 
  478                    $imageZip = 
new ZipArchive();
 
  479                    $imageZip->open($imagePathSplitted[0]);
 
  480                    $imageContents = $imageZip->getFromName($imagePathSplitted[1]);
 
  484                    $imageContents = file_get_contents($imagePath);
 
  487                $zipContent[
'xl/media/' . str_replace(
' ', 
'_', $this->
getDrawingHashTable()->getByIndex(
$i)->getIndexedFilename())] = $imageContents;
 
  494                $imageContents = ob_get_contents();
 
  497                $zipContent[
'xl/media/' . str_replace(
' ', 
'_', $this->
getDrawingHashTable()->getByIndex(
$i)->getIndexedFilename())] = $imageContents;
 
  508        $options->setOutputStream($this->fileHandle);
 
  516            $this->zip->finish();
 
  518            throw new WriterException(
'Could not close resource.');
 
  543        $this->spreadSheet = $spreadsheet;
 
  647        $this->office2003compatibility = $pValue;
 
  656        if (!in_array(
$path, $this->pathNames)) {
 
  657            $this->pathNames[] = 
$path;
 
  658            $this->zip->addFile(
$path, $content);
 
  664        foreach ($zipContent as 
$path => $content) {
 
An exception for terminatinating execution or to throw for unit testing.
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.
static setReturnDateType($returnDateType)
Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric o...
static getReturnDateType()
Return the current Return Date Format for functions that return a date/time (Excel,...
@template T of IComparable
openFileHandle($filename)
Open file handle.
maybeCloseFileHandle()
Close file handle only if we opened it ourselves.
setOffice2003Compatibility($pValue)
Set Office2003 compatibility.
getFontHashTable()
Get \PhpOffice\PhpSpreadsheet\Style\Font HashTable.
getStylesConditionalHashTable()
Get Conditional HashTable.
getFillHashTable()
Get Fill HashTable.
getNumFmtHashTable()
Get NumberFormat HashTable.
getSpreadsheet()
Get Spreadsheet object.
getWriterPartRelsRibbon()
getOffice2003Compatibility()
Get Office2003 compatibility.
setSpreadsheet(Spreadsheet $spreadsheet)
Set Spreadsheet object.
$stylesConditionalHashTable
getStringTable()
Get string table.
getWriterPartContentTypes()
getDrawingHashTable()
Get \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\BaseDrawing HashTable.
addZipFiles(array $zipContent)
getWriterPartStringTable()
save($pFilename)
Save PhpSpreadsheet to file.
__construct(Spreadsheet $spreadsheet)
Create a new Xlsx Writer.
getBordersHashTable()
Get Borders HashTable.
addZipFile(string $path, string $content)
getStyleHashTable()
Get Style HashTable.
This Exception gets invoked if a counter value exceeds storage size.