35 $objWriter =
new XMLWriter(XMLWriter::STORAGE_MEMORY);
39 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
42 $objWriter->startElement(
'worksheet');
43 $objWriter->writeAttribute(
'xml:space',
'preserve');
44 $objWriter->writeAttribute(
'xmlns',
'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
45 $objWriter->writeAttribute(
'xmlns:r',
'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
47 $objWriter->writeAttribute(
'xmlns:xdr',
'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing');
48 $objWriter->writeAttribute(
'xmlns:x14',
'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main');
49 $objWriter->writeAttribute(
'xmlns:xm',
'http://schemas.microsoft.com/office/excel/2006/main');
50 $objWriter->writeAttribute(
'xmlns:mc',
'http://schemas.openxmlformats.org/markup-compatibility/2006');
51 $objWriter->writeAttribute(
'mc:Ignorable',
'x14ac');
52 $objWriter->writeAttribute(
'xmlns:x14ac',
'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac');
122 $this->writeExtLst($objWriter, $pSheet);
124 $objWriter->endElement();
127 return $objWriter->getData();
139 $objWriter->startElement(
'sheetPr');
140 if ($pSheet->getParent()->hasMacros()) {
142 if (!$pSheet->hasCodeName()) {
143 $pSheet->setCodeName($pSheet->getTitle());
145 $objWriter->writeAttribute(
'codeName', $pSheet->getCodeName());
147 $autoFilterRange = $pSheet->getAutoFilter()->getRange();
148 if (!empty($autoFilterRange)) {
149 $objWriter->writeAttribute(
'filterMode', 1);
150 $pSheet->getAutoFilter()->showHideRows();
154 if ($pSheet->isTabColorSet()) {
155 $objWriter->startElement(
'tabColor');
156 $objWriter->writeAttribute(
'rgb', $pSheet->getTabColor()->getARGB());
157 $objWriter->endElement();
161 $objWriter->startElement(
'outlinePr');
162 $objWriter->writeAttribute(
'summaryBelow', ($pSheet->getShowSummaryBelow() ?
'1' :
'0'));
163 $objWriter->writeAttribute(
'summaryRight', ($pSheet->getShowSummaryRight() ?
'1' :
'0'));
164 $objWriter->endElement();
167 if ($pSheet->getPageSetup()->getFitToPage()) {
168 $objWriter->startElement(
'pageSetUpPr');
169 $objWriter->writeAttribute(
'fitToPage',
'1');
170 $objWriter->endElement();
173 $objWriter->endElement();
185 $objWriter->startElement(
'dimension');
186 $objWriter->writeAttribute(
'ref', $pSheet->calculateWorksheetDimension());
187 $objWriter->endElement();
199 $objWriter->startElement(
'sheetViews');
202 $sheetSelected =
false;
204 $sheetSelected =
true;
208 $objWriter->startElement(
'sheetView');
209 $objWriter->writeAttribute(
'tabSelected', $sheetSelected ?
'1' :
'0');
210 $objWriter->writeAttribute(
'workbookViewId',
'0');
213 if ($pSheet->getSheetView()->getZoomScale() != 100) {
214 $objWriter->writeAttribute(
'zoomScale', $pSheet->getSheetView()->getZoomScale());
216 if ($pSheet->getSheetView()->getZoomScaleNormal() != 100) {
217 $objWriter->writeAttribute(
'zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal());
221 if ($pSheet->getSheetView()->getShowZeros() ===
false) {
222 $objWriter->writeAttribute(
'showZeros', 0);
226 if ($pSheet->getSheetView()->getView() !== SheetView::SHEETVIEW_NORMAL) {
227 $objWriter->writeAttribute(
'view', $pSheet->getSheetView()->getView());
231 if ($pSheet->getShowGridlines()) {
232 $objWriter->writeAttribute(
'showGridLines',
'true');
234 $objWriter->writeAttribute(
'showGridLines',
'false');
238 if ($pSheet->getShowRowColHeaders()) {
239 $objWriter->writeAttribute(
'showRowColHeaders',
'1');
241 $objWriter->writeAttribute(
'showRowColHeaders',
'0');
245 if ($pSheet->getRightToLeft()) {
246 $objWriter->writeAttribute(
'rightToLeft',
'true');
249 $activeCell = $pSheet->getActiveCell();
250 $sqref = $pSheet->getSelectedCells();
254 if ($pSheet->getFreezePane()) {
260 $topLeftCell = $pSheet->getTopLeftCell();
264 $objWriter->startElement(
'pane');
266 $objWriter->writeAttribute(
'xSplit', $xSplit);
269 $objWriter->writeAttribute(
'ySplit', $ySplit);
270 $pane = ($xSplit > 0) ?
'bottomRight' :
'bottomLeft';
272 $objWriter->writeAttribute(
'topLeftCell', $topLeftCell);
273 $objWriter->writeAttribute(
'activePane', $pane);
274 $objWriter->writeAttribute(
'state',
'frozen');
275 $objWriter->endElement();
277 if (($xSplit > 0) && ($ySplit > 0)) {
279 $objWriter->startElement(
'selection');
280 $objWriter->writeAttribute(
'pane',
'topRight');
281 $objWriter->endElement();
282 $objWriter->startElement(
'selection');
283 $objWriter->writeAttribute(
'pane',
'bottomLeft');
284 $objWriter->endElement();
291 $objWriter->startElement(
'selection');
293 $objWriter->writeAttribute(
'pane', $pane);
295 $objWriter->writeAttribute(
'activeCell', $activeCell);
296 $objWriter->writeAttribute(
'sqref', $sqref);
297 $objWriter->endElement();
299 $objWriter->endElement();
301 $objWriter->endElement();
313 $objWriter->startElement(
'sheetFormatPr');
316 if ($pSheet->getDefaultRowDimension()->getRowHeight() >= 0) {
317 $objWriter->writeAttribute(
'customHeight',
'true');
318 $objWriter->writeAttribute(
'defaultRowHeight',
StringHelper::formatNumber($pSheet->getDefaultRowDimension()->getRowHeight()));
320 $objWriter->writeAttribute(
'defaultRowHeight',
'14.4');
325 (
string) $pSheet->getDefaultRowDimension()->getZeroHeight() ===
'1' ||
326 strtolower((
string) $pSheet->getDefaultRowDimension()->getZeroHeight()) ==
'true' 328 $objWriter->writeAttribute(
'zeroHeight',
'1');
332 if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) {
337 $outlineLevelRow = 0;
338 foreach ($pSheet->getRowDimensions() as $dimension) {
339 if ($dimension->getOutlineLevel() > $outlineLevelRow) {
340 $outlineLevelRow = $dimension->getOutlineLevel();
343 $objWriter->writeAttribute(
'outlineLevelRow', (
int) $outlineLevelRow);
346 $outlineLevelCol = 0;
347 foreach ($pSheet->getColumnDimensions() as $dimension) {
348 if ($dimension->getOutlineLevel() > $outlineLevelCol) {
349 $outlineLevelCol = $dimension->getOutlineLevel();
352 $objWriter->writeAttribute(
'outlineLevelCol', (
int) $outlineLevelCol);
354 $objWriter->endElement();
366 if (count($pSheet->getColumnDimensions()) > 0) {
367 $objWriter->startElement(
'cols');
369 $pSheet->calculateColumnWidths();
372 foreach ($pSheet->getColumnDimensions() as $colDimension) {
374 $objWriter->startElement(
'col');
378 if ($colDimension->getWidth() < 0) {
380 $objWriter->writeAttribute(
'width',
'9.10');
387 if ($colDimension->getVisible() ===
false) {
388 $objWriter->writeAttribute(
'hidden',
'true');
392 if ($colDimension->getAutoSize()) {
393 $objWriter->writeAttribute(
'bestFit',
'true');
397 if ($colDimension->getWidth() != $pSheet->getDefaultColumnDimension()->getWidth()) {
398 $objWriter->writeAttribute(
'customWidth',
'true');
402 if ($colDimension->getCollapsed() ===
true) {
403 $objWriter->writeAttribute(
'collapsed',
'true');
407 if ($colDimension->getOutlineLevel() > 0) {
408 $objWriter->writeAttribute(
'outlineLevel', $colDimension->getOutlineLevel());
412 $objWriter->writeAttribute(
'style', $colDimension->getXfIndex());
414 $objWriter->endElement();
417 $objWriter->endElement();
430 $objWriter->startElement(
'sheetProtection');
432 $protection = $pSheet->getProtection();
434 if ($protection->getAlgorithm()) {
435 $objWriter->writeAttribute(
'algorithmName', $protection->getAlgorithm());
436 $objWriter->writeAttribute(
'hashValue', $protection->getPassword());
437 $objWriter->writeAttribute(
'saltValue', $protection->getSalt());
438 $objWriter->writeAttribute(
'spinCount', $protection->getSpinCount());
439 } elseif ($protection->getPassword() !==
'') {
440 $objWriter->writeAttribute(
'password', $protection->getPassword());
443 $objWriter->writeAttribute(
'sheet', ($protection->getSheet() ?
'true' :
'false'));
444 $objWriter->writeAttribute(
'objects', ($protection->getObjects() ?
'true' :
'false'));
445 $objWriter->writeAttribute(
'scenarios', ($protection->getScenarios() ?
'true' :
'false'));
446 $objWriter->writeAttribute(
'formatCells', ($protection->getFormatCells() ?
'true' :
'false'));
447 $objWriter->writeAttribute(
'formatColumns', ($protection->getFormatColumns() ?
'true' :
'false'));
448 $objWriter->writeAttribute(
'formatRows', ($protection->getFormatRows() ?
'true' :
'false'));
449 $objWriter->writeAttribute(
'insertColumns', ($protection->getInsertColumns() ?
'true' :
'false'));
450 $objWriter->writeAttribute(
'insertRows', ($protection->getInsertRows() ?
'true' :
'false'));
451 $objWriter->writeAttribute(
'insertHyperlinks', ($protection->getInsertHyperlinks() ?
'true' :
'false'));
452 $objWriter->writeAttribute(
'deleteColumns', ($protection->getDeleteColumns() ?
'true' :
'false'));
453 $objWriter->writeAttribute(
'deleteRows', ($protection->getDeleteRows() ?
'true' :
'false'));
454 $objWriter->writeAttribute(
'selectLockedCells', ($protection->getSelectLockedCells() ?
'true' :
'false'));
455 $objWriter->writeAttribute(
'sort', ($protection->getSort() ?
'true' :
'false'));
456 $objWriter->writeAttribute(
'autoFilter', ($protection->getAutoFilter() ?
'true' :
'false'));
457 $objWriter->writeAttribute(
'pivotTables', ($protection->getPivotTables() ?
'true' :
'false'));
458 $objWriter->writeAttribute(
'selectUnlockedCells', ($protection->getSelectUnlockedCells() ?
'true' :
'false'));
459 $objWriter->endElement();
465 $objWriter->writeAttribute($attr, $val);
472 $objWriter->writeElement($attr, $val);
483 foreach ($conditional->getConditions() as $formula) {
485 $objWriter->writeElement(
'formula',
Xlfn::addXlfn($formula));
489 $objWriter->writeElement(
'formula',
'LEN(TRIM(' . $cellCoordinate .
'))=0');
492 $objWriter->writeElement(
'formula',
'LEN(TRIM(' . $cellCoordinate .
'))>0');
498 $txt = $conditional->getText();
500 $objWriter->writeAttribute(
'text',
$txt);
502 $objWriter->writeElement(
'formula',
'NOT(ISERROR(SEARCH("' .
$txt .
'",' . $cellCoordinate .
')))');
504 $objWriter->writeElement(
'formula',
'LEFT(' . $cellCoordinate .
',' . strlen(
$txt) .
')="' .
$txt .
'"');
506 $objWriter->writeElement(
'formula',
'RIGHT(' . $cellCoordinate .
',' . strlen(
$txt) .
')="' .
$txt .
'"');
508 $objWriter->writeElement(
'formula',
'ISERROR(SEARCH("' .
$txt .
'",' . $cellCoordinate .
'))');
516 $objWriter->startElementNs($prefix,
'conditionalFormatting', null);
518 $objWriter->startElementNs($prefix,
'cfRule', null);
519 $objWriter->writeAttribute(
'type', $ruleExtension->
getCfRule());
520 $objWriter->writeAttribute(
'id', $ruleExtension->
getId());
521 $objWriter->startElementNs($prefix,
'dataBar', null);
523 foreach ($dataBar->getXmlAttributes() as $attrKey => $val) {
524 $objWriter->writeAttribute($attrKey, $val);
526 $minCfvo = $dataBar->getMinimumConditionalFormatValueObject();
528 $objWriter->startElementNs($prefix,
'cfvo', null);
529 $objWriter->writeAttribute(
'type', $minCfvo->getType());
530 if ($minCfvo->getCellFormula()) {
531 $objWriter->writeElement(
'xm:f', $minCfvo->getCellFormula());
533 $objWriter->endElement();
536 $maxCfvo = $dataBar->getMaximumConditionalFormatValueObject();
538 $objWriter->startElementNs($prefix,
'cfvo', null);
539 $objWriter->writeAttribute(
'type', $maxCfvo->getType());
540 if ($maxCfvo->getCellFormula()) {
541 $objWriter->writeElement(
'xm:f', $maxCfvo->getCellFormula());
543 $objWriter->endElement();
546 foreach ($dataBar->getXmlElements() as $elmKey => $elmAttr) {
547 $objWriter->startElementNs($prefix, $elmKey, null);
548 foreach ($elmAttr as $attrKey => $attrVal) {
549 $objWriter->writeAttribute($attrKey, $attrVal);
551 $objWriter->endElement();
553 $objWriter->endElement();
554 $objWriter->endElement();
555 $objWriter->writeElement(
'xm:sqref', $ruleExtension->
getSqref());
556 $objWriter->endElement();
559 private static function writeDataBarElements(
XMLWriter $objWriter, $dataBar):
void 563 $objWriter->startElement(
'dataBar');
564 self::writeAttributeIf($objWriter, null !== $dataBar->getShowValue(),
'showValue', $dataBar->getShowValue() ?
'1' :
'0');
566 $minCfvo = $dataBar->getMinimumConditionalFormatValueObject();
568 $objWriter->startElement(
'cfvo');
569 self::writeAttributeIf($objWriter, $minCfvo->getType(),
'type', (string) $minCfvo->getType());
570 self::writeAttributeIf($objWriter, $minCfvo->getValue(),
'val', (string) $minCfvo->getValue());
571 $objWriter->endElement();
573 $maxCfvo = $dataBar->getMaximumConditionalFormatValueObject();
575 $objWriter->startElement(
'cfvo');
576 self::writeAttributeIf($objWriter, $maxCfvo->getType(),
'type', (string) $maxCfvo->getType());
577 self::writeAttributeIf($objWriter, $maxCfvo->getValue(),
'val', (string) $maxCfvo->getValue());
578 $objWriter->endElement();
580 if ($dataBar->getColor()) {
581 $objWriter->startElement(
'color');
582 $objWriter->writeAttribute(
'rgb', $dataBar->getColor());
583 $objWriter->endElement();
585 $objWriter->endElement();
587 if ($dataBar->getConditionalFormattingRuleExt()) {
588 $objWriter->startElement(
'extLst');
589 $extension = $dataBar->getConditionalFormattingRuleExt();
590 $objWriter->startElement(
'ext');
591 $objWriter->writeAttribute(
'uri',
'{B025F937-C7B1-47D3-B67F-A62EFF666E3E}');
592 $objWriter->startElementNs(
'x14',
'id', null);
593 $objWriter->text($extension->getId());
594 $objWriter->endElement();
595 $objWriter->endElement();
596 $objWriter->endElement();
613 foreach ($pSheet->getConditionalStylesCollection() as $cellCoordinate => $conditionalStyles) {
614 foreach ($conditionalStyles as $conditional) {
621 $objWriter->startElement(
'conditionalFormatting');
622 $objWriter->writeAttribute(
'sqref', $cellCoordinate);
625 $objWriter->startElement(
'cfRule');
626 $objWriter->writeAttribute(
'type', $conditional->getConditionType());
627 self::writeAttributeIf(
631 $this->
getParentWriter()->getStylesConditionalHashTable()->getIndexForHashCode($conditional->getHashCode())
633 $objWriter->writeAttribute(
'priority',
$id++);
635 self::writeAttributeif(
643 $conditional->getOperatorType()
646 self::writeAttributeIf($objWriter, $conditional->getStopIfTrue(),
'stopIfTrue',
'1');
652 self::writeTextCondElements($objWriter, $conditional, $cellCoordinate);
654 self::writeOtherCondElements($objWriter, $conditional, $cellCoordinate);
658 self::writeDataBarElements($objWriter, $conditional->getDataBar());
660 $objWriter->endElement();
662 $objWriter->endElement();
677 $dataValidationCollection = $pSheet->getDataValidationCollection();
680 if (!empty($dataValidationCollection)) {
682 $objWriter->startElement(
'dataValidations');
683 $objWriter->writeAttribute(
'count', count($dataValidationCollection));
685 foreach ($dataValidationCollection as $coordinate => $dv) {
686 $objWriter->startElement(
'dataValidation');
688 if ($dv->getType() !=
'') {
689 $objWriter->writeAttribute(
'type', $dv->getType());
692 if ($dv->getErrorStyle() !=
'') {
693 $objWriter->writeAttribute(
'errorStyle', $dv->getErrorStyle());
696 if ($dv->getOperator() !=
'') {
697 $objWriter->writeAttribute(
'operator', $dv->getOperator());
700 $objWriter->writeAttribute(
'allowBlank', ($dv->getAllowBlank() ?
'1' :
'0'));
701 $objWriter->writeAttribute(
'showDropDown', (!$dv->getShowDropDown() ?
'1' :
'0'));
702 $objWriter->writeAttribute(
'showInputMessage', ($dv->getShowInputMessage() ?
'1' :
'0'));
703 $objWriter->writeAttribute(
'showErrorMessage', ($dv->getShowErrorMessage() ?
'1' :
'0'));
705 if ($dv->getErrorTitle() !==
'') {
706 $objWriter->writeAttribute(
'errorTitle', $dv->getErrorTitle());
708 if ($dv->getError() !==
'') {
709 $objWriter->writeAttribute(
'error', $dv->getError());
711 if ($dv->getPromptTitle() !==
'') {
712 $objWriter->writeAttribute(
'promptTitle', $dv->getPromptTitle());
714 if ($dv->getPrompt() !==
'') {
715 $objWriter->writeAttribute(
'prompt', $dv->getPrompt());
718 $objWriter->writeAttribute(
'sqref', $coordinate);
720 if ($dv->getFormula1() !==
'') {
721 $objWriter->writeElement(
'formula1', $dv->getFormula1());
723 if ($dv->getFormula2() !==
'') {
724 $objWriter->writeElement(
'formula2', $dv->getFormula2());
727 $objWriter->endElement();
730 $objWriter->endElement();
743 $hyperlinkCollection = $pSheet->getHyperlinkCollection();
749 if (!empty($hyperlinkCollection)) {
750 $objWriter->startElement(
'hyperlinks');
752 foreach ($hyperlinkCollection as $coordinate => $hyperlink) {
753 $objWriter->startElement(
'hyperlink');
755 $objWriter->writeAttribute(
'ref', $coordinate);
756 if (!$hyperlink->isInternal()) {
757 $objWriter->writeAttribute(
'r:id',
'rId_hyperlink_' . $relationId);
760 $objWriter->writeAttribute(
'location', str_replace(
'sheet://',
'', $hyperlink->getUrl()));
763 if ($hyperlink->getTooltip() !==
'') {
764 $objWriter->writeAttribute(
'tooltip', $hyperlink->getTooltip());
765 $objWriter->writeAttribute(
'display', $hyperlink->getTooltip());
768 $objWriter->endElement();
771 $objWriter->endElement();
783 if (count($pSheet->getProtectedCells()) > 0) {
785 $objWriter->startElement(
'protectedRanges');
788 foreach ($pSheet->getProtectedCells() as $protectedCell => $passwordHash) {
790 $objWriter->startElement(
'protectedRange');
791 $objWriter->writeAttribute(
'name',
'p' . md5($protectedCell));
792 $objWriter->writeAttribute(
'sqref', $protectedCell);
793 if (!empty($passwordHash)) {
794 $objWriter->writeAttribute(
'password', $passwordHash);
796 $objWriter->endElement();
799 $objWriter->endElement();
811 if (count($pSheet->getMergeCells()) > 0) {
813 $objWriter->startElement(
'mergeCells');
816 foreach ($pSheet->getMergeCells() as $mergeCell) {
818 $objWriter->startElement(
'mergeCell');
819 $objWriter->writeAttribute(
'ref', $mergeCell);
820 $objWriter->endElement();
823 $objWriter->endElement();
836 $objWriter->startElement(
'printOptions');
838 $objWriter->writeAttribute(
'gridLines', ($pSheet->getPrintGridlines() ?
'true' :
'false'));
839 $objWriter->writeAttribute(
'gridLinesSet',
'true');
841 if ($pSheet->getPageSetup()->getHorizontalCentered()) {
842 $objWriter->writeAttribute(
'horizontalCentered',
'true');
845 if ($pSheet->getPageSetup()->getVerticalCentered()) {
846 $objWriter->writeAttribute(
'verticalCentered',
'true');
849 $objWriter->endElement();
861 $objWriter->startElement(
'pageMargins');
868 $objWriter->endElement();
879 $autoFilterRange = $pSheet->getAutoFilter()->getRange();
880 if (!empty($autoFilterRange)) {
882 $objWriter->startElement(
'autoFilter');
888 [$ws, $range[0]] = PhpspreadsheetWorksheet::extractSheetTitle($range[0],
true);
889 $range = implode(
':', $range);
891 $objWriter->writeAttribute(
'ref', str_replace(
'$',
'', $range));
893 $columns = $pSheet->getAutoFilter()->getColumns();
895 foreach (
$columns as $columnID => $column) {
896 $rules = $column->getRules();
897 if (count($rules) > 0) {
898 $objWriter->startElement(
'filterColumn');
899 $objWriter->writeAttribute(
'colId', $pSheet->getAutoFilter()->getColumnOffset($columnID));
901 $objWriter->startElement($column->getFilterType());
902 if ($column->getJoin() == Column::AUTOFILTER_COLUMN_JOIN_AND) {
903 $objWriter->writeAttribute(
'and', 1);
906 foreach ($rules as
$rule) {
908 ($column->getFilterType() === Column::AUTOFILTER_FILTERTYPE_FILTER) &&
909 ($rule->getOperator() === Rule::AUTOFILTER_COLUMN_RULE_EQUAL) &&
910 ($rule->getValue() ===
'')
913 $objWriter->writeAttribute(
'blank', 1);
914 } elseif ($rule->getRuleType() === Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER) {
916 $objWriter->writeAttribute(
'type', $rule->getGrouping());
917 $val = $column->getAttribute(
'val');
919 $objWriter->writeAttribute(
'val', $val);
921 $maxVal = $column->getAttribute(
'maxVal');
922 if ($maxVal !== null) {
923 $objWriter->writeAttribute(
'maxVal', $maxVal);
925 } elseif ($rule->getRuleType() === Rule::AUTOFILTER_RULETYPE_TOPTENFILTER) {
927 $objWriter->writeAttribute(
'val', $rule->getValue());
928 $objWriter->writeAttribute(
'percent', (($rule->getOperator() === Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT) ?
'1' :
'0'));
929 $objWriter->writeAttribute(
'top', (($rule->getGrouping() === Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) ?
'1' :
'0'));
932 $objWriter->startElement($rule->getRuleType());
934 if ($rule->getOperator() !== Rule::AUTOFILTER_COLUMN_RULE_EQUAL) {
935 $objWriter->writeAttribute(
'operator', $rule->getOperator());
937 if ($rule->getRuleType() === Rule::AUTOFILTER_RULETYPE_DATEGROUP) {
939 foreach ($rule->getValue() as
$key => $value) {
941 $objWriter->writeAttribute($key, $value);
944 $objWriter->writeAttribute(
'dateTimeGrouping', $rule->getGrouping());
946 $objWriter->writeAttribute(
'val', $rule->getValue());
949 $objWriter->endElement();
953 $objWriter->endElement();
955 $objWriter->endElement();
959 $objWriter->endElement();
972 $objWriter->startElement(
'pageSetup');
973 $objWriter->writeAttribute(
'paperSize', $pSheet->getPageSetup()->getPaperSize());
974 $objWriter->writeAttribute(
'orientation', $pSheet->getPageSetup()->getOrientation());
976 if ($pSheet->getPageSetup()->getScale() !== null) {
977 $objWriter->writeAttribute(
'scale', $pSheet->getPageSetup()->getScale());
979 if ($pSheet->getPageSetup()->getFitToHeight() !== null) {
980 $objWriter->writeAttribute(
'fitToHeight', $pSheet->getPageSetup()->getFitToHeight());
982 $objWriter->writeAttribute(
'fitToHeight',
'0');
984 if ($pSheet->getPageSetup()->getFitToWidth() !== null) {
985 $objWriter->writeAttribute(
'fitToWidth', $pSheet->getPageSetup()->getFitToWidth());
987 $objWriter->writeAttribute(
'fitToWidth',
'0');
989 if ($pSheet->getPageSetup()->getFirstPageNumber() !== null) {
990 $objWriter->writeAttribute(
'firstPageNumber', $pSheet->getPageSetup()->getFirstPageNumber());
991 $objWriter->writeAttribute(
'useFirstPageNumber',
'1');
993 $objWriter->writeAttribute(
'pageOrder', $pSheet->getPageSetup()->getPageOrder());
995 $getUnparsedLoadedData = $pSheet->getParent()->getUnparsedLoadedData();
996 if (isset($getUnparsedLoadedData[
'sheets'][$pSheet->getCodeName()][
'pageSetupRelId'])) {
997 $objWriter->writeAttribute(
'r:id', $getUnparsedLoadedData[
'sheets'][$pSheet->getCodeName()][
'pageSetupRelId']);
1000 $objWriter->endElement();
1012 $objWriter->startElement(
'headerFooter');
1013 $objWriter->writeAttribute(
'differentOddEven', ($pSheet->getHeaderFooter()->getDifferentOddEven() ?
'true' :
'false'));
1014 $objWriter->writeAttribute(
'differentFirst', ($pSheet->getHeaderFooter()->getDifferentFirst() ?
'true' :
'false'));
1015 $objWriter->writeAttribute(
'scaleWithDoc', ($pSheet->getHeaderFooter()->getScaleWithDocument() ?
'true' :
'false'));
1016 $objWriter->writeAttribute(
'alignWithMargins', ($pSheet->getHeaderFooter()->getAlignWithMargins() ?
'true' :
'false'));
1018 $objWriter->writeElement(
'oddHeader', $pSheet->getHeaderFooter()->getOddHeader());
1019 $objWriter->writeElement(
'oddFooter', $pSheet->getHeaderFooter()->getOddFooter());
1020 $objWriter->writeElement(
'evenHeader', $pSheet->getHeaderFooter()->getEvenHeader());
1021 $objWriter->writeElement(
'evenFooter', $pSheet->getHeaderFooter()->getEvenFooter());
1022 $objWriter->writeElement(
'firstHeader', $pSheet->getHeaderFooter()->getFirstHeader());
1023 $objWriter->writeElement(
'firstFooter', $pSheet->getHeaderFooter()->getFirstFooter());
1024 $objWriter->endElement();
1037 $aColumnBreaks = [];
1038 foreach ($pSheet->getBreaks() as $cell => $breakType) {
1039 if ($breakType == PhpspreadsheetWorksheet::BREAK_ROW) {
1040 $aRowBreaks[] = $cell;
1041 } elseif ($breakType == PhpspreadsheetWorksheet::BREAK_COLUMN) {
1042 $aColumnBreaks[] = $cell;
1047 if (!empty($aRowBreaks)) {
1048 $objWriter->startElement(
'rowBreaks');
1049 $objWriter->writeAttribute(
'count', count($aRowBreaks));
1050 $objWriter->writeAttribute(
'manualBreakCount', count($aRowBreaks));
1052 foreach ($aRowBreaks as $cell) {
1055 $objWriter->startElement(
'brk');
1056 $objWriter->writeAttribute(
'id',
$coords[1]);
1057 $objWriter->writeAttribute(
'man',
'1');
1058 $objWriter->endElement();
1061 $objWriter->endElement();
1065 if (!empty($aColumnBreaks)) {
1066 $objWriter->startElement(
'colBreaks');
1067 $objWriter->writeAttribute(
'count', count($aColumnBreaks));
1068 $objWriter->writeAttribute(
'manualBreakCount', count($aColumnBreaks));
1070 foreach ($aColumnBreaks as $cell) {
1073 $objWriter->startElement(
'brk');
1075 $objWriter->writeAttribute(
'man',
'1');
1076 $objWriter->endElement();
1079 $objWriter->endElement();
1093 $aFlippedStringTable = $this->
getParentWriter()->getWriterPartstringtable()->flipStringTable($pStringTable);
1096 $objWriter->startElement(
'sheetData');
1102 $highestRow = $pSheet->getHighestRow();
1106 foreach ($pSheet->getCoordinates() as $coordinate) {
1108 $cellsByRow[$cellAddress[1]][] = $coordinate;
1112 while ($currentRow++ < $highestRow) {
1114 $rowDimension = $pSheet->getRowDimension($currentRow);
1117 $writeCurrentRow = isset($cellsByRow[$currentRow]) || $rowDimension->getRowHeight() >= 0 || $rowDimension->getVisible() ==
false || $rowDimension->getCollapsed() ==
true || $rowDimension->getOutlineLevel() > 0 || $rowDimension->getXfIndex() !== null;
1119 if ($writeCurrentRow) {
1121 $objWriter->startElement(
'row');
1122 $objWriter->writeAttribute(
'r', $currentRow);
1123 $objWriter->writeAttribute(
'spans',
'1:' . $colCount);
1126 if ($rowDimension->getRowHeight() >= 0) {
1127 $objWriter->writeAttribute(
'customHeight',
'1');
1132 if (!$rowDimension->getVisible() ===
true) {
1133 $objWriter->writeAttribute(
'hidden',
'true');
1137 if ($rowDimension->getCollapsed() ===
true) {
1138 $objWriter->writeAttribute(
'collapsed',
'true');
1142 if ($rowDimension->getOutlineLevel() > 0) {
1143 $objWriter->writeAttribute(
'outlineLevel', $rowDimension->getOutlineLevel());
1147 if ($rowDimension->getXfIndex() !== null) {
1148 $objWriter->writeAttribute(
's', $rowDimension->getXfIndex());
1149 $objWriter->writeAttribute(
'customFormat',
'1');
1153 if (isset($cellsByRow[$currentRow])) {
1154 foreach ($cellsByRow[$currentRow] as $cellAddress) {
1156 $this->
writeCell($objWriter, $pSheet, $cellAddress, $aFlippedStringTable);
1161 $objWriter->endElement();
1165 $objWriter->endElement();
1173 $objWriter->writeAttribute(
't', $mappedType);
1174 if (!$cellValue instanceof
RichText) {
1176 } elseif ($cellValue instanceof RichText) {
1177 $objWriter->startElement(
'is');
1178 $this->
getParentWriter()->getWriterPartstringtable()->writeRichText($objWriter, $cellValue);
1179 $objWriter->endElement();
1189 $objWriter->writeAttribute(
't', $mappedType);
1190 if (!$cellValue instanceof
RichText) {
1191 self::writeElementIf($objWriter, isset($pFlippedStringTable[$cellValue]),
'v', $pFlippedStringTable[$cellValue] ??
'');
1193 $objWriter->writeElement(
'v', $pFlippedStringTable[$cellValue->getHashCode()]);
1203 if (is_float($cellValue)) {
1205 $cellValue = str_replace(
',',
'.', (
string) $cellValue);
1206 if (strpos($cellValue,
'.') ===
false) {
1207 $cellValue = $cellValue .
'.0';
1210 $objWriter->writeElement(
'v', $cellValue);
1215 $objWriter->writeAttribute(
't', $mappedType);
1216 $objWriter->writeElement(
'v', $cellValue ?
'1' :
'0');
1221 $objWriter->writeAttribute(
't', $mappedType);
1222 $cellIsFormula = substr($cellValue, 0, 1) ===
'=';
1224 $objWriter->writeElement(
'v', $cellIsFormula ? $formulaerr : $cellValue);
1230 if (is_string($calculatedValue)) {
1232 $this->
writeCellError($objWriter,
'e', $cellValue, $calculatedValue);
1236 $objWriter->writeAttribute(
't',
'str');
1237 } elseif (is_bool($calculatedValue)) {
1238 $objWriter->writeAttribute(
't',
'b');
1239 $calculatedValue = (int) $calculatedValue;
1255 self::writeElementIf(
1275 $pCell = $pSheet->getCell($pCellAddress);
1276 $objWriter->startElement(
'c');
1277 $objWriter->writeAttribute(
'r', $pCellAddress);
1280 $xfi = $pCell->getXfIndex();
1281 self::writeAttributeIf($objWriter, $xfi,
's', $xfi);
1284 $cellValue = $pCell->getValue();
1285 if (is_object($cellValue) || $cellValue !==
'') {
1287 $mappedType = $pCell->getDataType();
1290 switch (strtolower($mappedType)) {
1296 $this->
writeCellString($objWriter, $mappedType, $cellValue, $pFlippedStringTable);
1316 $objWriter->endElement();
1328 $unparsedLoadedData = $pSheet->getParent()->getUnparsedLoadedData();
1329 $hasUnparsedDrawing = isset($unparsedLoadedData[
'sheets'][$pSheet->getCodeName()][
'drawingOriginalIds']);
1330 $chartCount = (
$includeCharts) ? $pSheet->getChartCollection()->count() : 0;
1331 if ($chartCount == 0 && $pSheet->getDrawingCollection()->count() == 0 && !$hasUnparsedDrawing) {
1336 $objWriter->startElement(
'drawing');
1339 if (isset($unparsedLoadedData[
'sheets'][$pSheet->getCodeName()][
'drawingOriginalIds'])) {
1340 $drawingOriginalIds = $unparsedLoadedData[
'sheets'][$pSheet->getCodeName()][
'drawingOriginalIds'];
1343 $rId = reset($drawingOriginalIds);
1346 $objWriter->writeAttribute(
'r:id', $rId);
1347 $objWriter->endElement();
1359 if (count($pSheet->getComments()) > 0) {
1360 $objWriter->startElement(
'legacyDrawing');
1361 $objWriter->writeAttribute(
'r:id',
'rId_comments_vml1');
1362 $objWriter->endElement();
1375 if (count($pSheet->getHeaderFooter()->getImages()) > 0) {
1376 $objWriter->startElement(
'legacyDrawingHF');
1377 $objWriter->writeAttribute(
'r:id',
'rId_headerfooter_vml1');
1378 $objWriter->endElement();
1384 if (empty($pSheet->getParent()->getUnparsedLoadedData()[
'sheets'][$pSheet->getCodeName()][
'AlternateContents'])) {
1388 foreach ($pSheet->getParent()->getUnparsedLoadedData()[
'sheets'][$pSheet->getCodeName()][
'AlternateContents'] as $alternateContent) {
1389 $objWriter->writeRaw($alternateContent);
1401 $conditionalFormattingRuleExtList = [];
1402 foreach ($pSheet->getConditionalStylesCollection() as $cellCoordinate => $conditionalStyles) {
1404 foreach ($conditionalStyles as $conditional) {
1405 $dataBar = $conditional->getDataBar();
1406 if ($dataBar && $dataBar->getConditionalFormattingRuleExt()) {
1407 $conditionalFormattingRuleExtList[] = $dataBar->getConditionalFormattingRuleExt();
1412 if (count($conditionalFormattingRuleExtList) > 0) {
1413 $conditionalFormattingRuleExtNsPrefix =
'x14';
1414 $objWriter->startElement(
'extLst');
1415 $objWriter->startElement(
'ext');
1416 $objWriter->writeAttribute(
'uri',
'{78C0D931-6437-407d-A8EE-F0AAD7539E65}');
1417 $objWriter->startElementNs($conditionalFormattingRuleExtNsPrefix,
'conditionalFormattings', null);
1418 foreach ($conditionalFormattingRuleExtList as $extension) {
1419 self::writeExtConditionalFormattingElements($objWriter, $extension);
1421 $objWriter->endElement();
1422 $objWriter->endElement();
1423 $objWriter->endElement();
static controlCharacterPHP2OOXML($value)
Convert from PHP control character to OpenXML escaped control character.
static splitRange($pRange)
Split range into coordinate strings.
writeCellFormula(XMLWriter $objWriter, string $cellValue, Cell $pCell)
const CONDITION_CONTAINSTEXT
writeLegacyDrawingHF(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write LegacyDrawingHF.
writeSheetProtection(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write SheetProtection.
const OPERATOR_NOTCONTAINS
writeSheetPr(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write SheetPr.
writeConditionalFormatting(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write ConditionalFormatting.
static writeElementIf(XMLWriter $objWriter, $condition, string $attr, string $val)
writePageSetup(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write PageSetup.
if(!array_key_exists('StateId', $_REQUEST)) $id
writeDataValidations(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write DataValidations.
writeSheetFormatPr(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write SheetFormatPr.
static formatNumber($value)
Formats a numeric value as a string for output in various output writers forcing point as decimal sep...
getDiskCachingDirectory()
Get disk caching directory.
getOffice2003Compatibility()
Get Office2003 compatibility.
writeMergeCells(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write MergeCells.
writeCellInlineStr(XMLWriter $objWriter, string $mappedType, $cellValue)
writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, string $pCellAddress, array $pFlippedStringTable)
Write Cell.
static addXlfnStripEquals(string $funcstring)
Prefix function name in string with _xlfn.
const CONDITION_NOTCONTAINSTEXT
writeBreaks(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write Breaks.
writeLegacyDrawing(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write LegacyDrawing.
getParentWriter()
Get parent Xlsx object.
const OPERATOR_BEGINSWITH
static isError($value='')
IS_ERROR.
writeSheetViews(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write SheetViews.
getPreCalculateFormulas()
Get Pre-Calculate Formulas flag If this is true (the default), then the writer will recalculate all f...
static writeOtherCondElements(XMLWriter $objWriter, Conditional $conditional, string $cellCoordinate)
const OPERATOR_CONTAINSTEXT
writeHeaderFooter(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write Header / Footer.
getSpreadsheet()
Get Spreadsheet object.
writePageMargins(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write PageMargins.
writeProtectedRanges(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write ProtectedRanges.
writeCellBoolean(XMLWriter $objWriter, string $mappedType, bool $cellValue)
writeCellNumeric(XMLWriter $objWriter, $cellValue)
writeAlternateContent(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, array $pStringTable)
Write SheetData.
const CONDITION_EXPRESSION
static coordinateFromString($pCoordinateString)
Coordinate from string.
writeHyperlinks(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write Hyperlinks.
writeDrawings(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, $includeCharts=false)
Write Drawings.
static mergeRangesInCollection(array $pCoordCollection)
Convert an associative array of single cell coordinates to values to an associative array of cell ran...
static addXlfn(string $funcstring)
Prefix function name in string with _xlfn.
getCalculatedValue($resetLog=true)
Get calculated cell value.
writeDimension(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write Dimension.
static writeTextCondElements(XMLWriter $objWriter, Conditional $conditional, string $cellCoordinate)
getUseDiskCaching()
Get use disk caching where possible?
static writeExtConditionalFormattingElements(XMLWriter $objWriter, ConditionalFormattingRuleExtension $ruleExtension)
static writeAttributeIf(XMLWriter $objWriter, $condition, string $attr, string $val)
writeCellString(XMLWriter $objWriter, string $mappedType, $cellValue, array $pFlippedStringTable)
const CONDITION_NOTCONTAINSBLANKS
static columnIndexFromString($pString)
Column index from string.
writeCellError(XMLWriter $objWriter, string $mappedType, string $cellValue, string $formulaerr='#NULL!')
const CONDITION_CONTAINSBLANKS
writeCols(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write Cols.
writeWorksheet(PhpspreadsheetWorksheet $pSheet, $pStringTable=null, $includeCharts=false)
Write worksheet to XML format.
writeAutoFilter(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write AutoFilter.
writePrintOptions(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet)
Write PrintOptions.