32 $this->officeNs = $styleDom->lookupNamespaceUri(
'office');
33 $this->stylesNs = $styleDom->lookupNamespaceUri(
'style');
34 $this->stylesFo = $styleDom->lookupNamespaceUri(
'fo');
39 $styles = $styleDom->getElementsByTagNameNS($this->officeNs,
'automatic-styles')
41 ->getElementsByTagNameNS($this->stylesNs,
'page-layout');
43 foreach ($styles as $styleSet) {
44 $styleName = $styleSet->getAttributeNS($this->stylesNs,
'name');
45 $pageLayoutProperties = $styleSet->getElementsByTagNameNS($this->stylesNs,
'page-layout-properties')[0];
46 $styleOrientation = $pageLayoutProperties->getAttributeNS($this->stylesNs,
'print-orientation');
47 $styleScale = $pageLayoutProperties->getAttributeNS($this->stylesNs,
'scale-to');
48 $stylePrintOrder = $pageLayoutProperties->getAttributeNS($this->stylesNs,
'print-page-order');
49 $centered = $pageLayoutProperties->getAttributeNS($this->stylesNs,
'table-centering');
51 $marginLeft = $pageLayoutProperties->getAttributeNS($this->stylesFo,
'margin-left');
52 $marginRight = $pageLayoutProperties->getAttributeNS($this->stylesFo,
'margin-right');
53 $marginTop = $pageLayoutProperties->getAttributeNS($this->stylesFo,
'margin-top');
54 $marginBottom = $pageLayoutProperties->getAttributeNS($this->stylesFo,
'margin-bottom');
55 $header = $styleSet->getElementsByTagNameNS($this->stylesNs,
'header-style')[0];
56 $headerProperties =
$header->getElementsByTagNameNS($this->stylesNs,
'header-footer-properties')[0];
57 $marginHeader = isset($headerProperties) ? $headerProperties->getAttributeNS($this->stylesFo,
'min-height') : null;
58 $footer = $styleSet->getElementsByTagNameNS($this->stylesNs,
'footer-style')[0];
59 $footerProperties = $footer->getElementsByTagNameNS($this->stylesNs,
'header-footer-properties')[0];
60 $marginFooter = isset($footerProperties) ? $footerProperties->getAttributeNS($this->stylesFo,
'min-height') : null;
62 $this->pageLayoutStyles[$styleName] = (object) [
63 'orientation' => $styleOrientation ?: PageSetup::ORIENTATION_DEFAULT,
64 'scale' => $styleScale ?: 100,
65 'printOrder' => $stylePrintOrder,
66 'horizontalCentered' => $centered ===
'horizontal' || $centered ===
'both',
67 'verticalCentered' => $centered ===
'vertical' || $centered ===
'both',
69 'marginLeft' => (
float) $marginLeft ?? 0.7,
70 'marginRight' => (float) $marginRight ?? 0.7,
71 'marginTop' => (
float) $marginTop ?? 0.3,
72 'marginBottom' => (float) $marginBottom ?? 0.3,
73 'marginHeader' => (
float) $marginHeader ?? 0.45,
74 'marginFooter' => (float) $marginFooter ?? 0.45,
81 $styleMasterLookup = $styleDom->getElementsByTagNameNS($this->officeNs,
'master-styles')
83 ->getElementsByTagNameNS($this->stylesNs,
'master-page');
85 foreach ($styleMasterLookup as $styleMasterSet) {
86 $styleMasterName = $styleMasterSet->getAttributeNS($this->stylesNs,
'name');
87 $pageLayoutName = $styleMasterSet->getAttributeNS($this->stylesNs,
'page-layout-name');
88 $this->masterPrintStylesCrossReference[$styleMasterName] = $pageLayoutName;
94 $styleXReferences = $contentDom->getElementsByTagNameNS($this->officeNs,
'automatic-styles')
96 ->getElementsByTagNameNS($this->stylesNs,
'style');
98 foreach ($styleXReferences as $styleXreferenceSet) {
99 $styleXRefName = $styleXreferenceSet->getAttributeNS($this->stylesNs,
'name');
100 $stylePageLayoutName = $styleXreferenceSet->getAttributeNS($this->stylesNs,
'master-page-name');
101 if (!empty($stylePageLayoutName)) {
102 $this->masterStylesCrossReference[$styleXRefName] = $stylePageLayoutName;
109 if (!array_key_exists($styleName, $this->masterStylesCrossReference)) {
112 $masterStyleName = $this->masterStylesCrossReference[$styleName];
114 if (!array_key_exists($masterStyleName, $this->masterPrintStylesCrossReference)) {
117 $printSettingsIndex = $this->masterPrintStylesCrossReference[$masterStyleName];
119 if (!array_key_exists($printSettingsIndex, $this->pageLayoutStyles)) {
122 $printSettings = $this->pageLayoutStyles[$printSettingsIndex];
125 ->setOrientation($printSettings->orientation ?? PageSetup::ORIENTATION_DEFAULT)
126 ->setPageOrder($printSettings->printOrder ===
'ltr' ? PageSetup::PAGEORDER_OVER_THEN_DOWN : PageSetup::PAGEORDER_DOWN_THEN_OVER)
127 ->setScale((
int) trim($printSettings->scale,
'%'))
128 ->setHorizontalCentered($printSettings->horizontalCentered)
129 ->setVerticalCentered($printSettings->verticalCentered);
132 ->setLeft($printSettings->marginLeft)
133 ->setRight($printSettings->marginRight)
134 ->setTop($printSettings->marginTop)
135 ->setBottom($printSettings->marginBottom)
136 ->setHeader($printSettings->marginHeader)
137 ->setFooter($printSettings->marginFooter);
getPageMargins()
Get page margins.
getPageSetup()
Get page setup.
readStyleMasterLookup(DOMDocument $styleDom)
readPageSettingStyles(DOMDocument $styleDom)
__construct(DOMDocument $styleDom)
readStyleCrossReferences(DOMDocument $contentDom)
setPrintSettingsForWorksheet(Worksheet $worksheet, string $styleName)
$masterStylesCrossReference
$masterPrintStylesCrossReference
setDomNameSpaces(DOMDocument $styleDom)