30 $objWriter =
new XMLWriter(XMLWriter::STORAGE_MEMORY);
34 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
37 $objWriter->startElement(
'styleSheet');
38 $objWriter->writeAttribute(
'xml:space',
'preserve');
39 $objWriter->writeAttribute(
'xmlns',
'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
42 $objWriter->startElement(
'numFmts');
50 $objWriter->endElement();
53 $objWriter->startElement(
'fonts');
61 $objWriter->endElement();
64 $objWriter->startElement(
'fills');
72 $objWriter->endElement();
75 $objWriter->startElement(
'borders');
83 $objWriter->endElement();
86 $objWriter->startElement(
'cellStyleXfs');
87 $objWriter->writeAttribute(
'count', 1);
90 $objWriter->startElement(
'xf');
91 $objWriter->writeAttribute(
'numFmtId', 0);
92 $objWriter->writeAttribute(
'fontId', 0);
93 $objWriter->writeAttribute(
'fillId', 0);
94 $objWriter->writeAttribute(
'borderId', 0);
95 $objWriter->endElement();
97 $objWriter->endElement();
100 $objWriter->startElement(
'cellXfs');
108 $objWriter->endElement();
111 $objWriter->startElement(
'cellStyles');
112 $objWriter->writeAttribute(
'count', 1);
115 $objWriter->startElement(
'cellStyle');
116 $objWriter->writeAttribute(
'name',
'Normal');
117 $objWriter->writeAttribute(
'xfId', 0);
118 $objWriter->writeAttribute(
'builtinId', 0);
119 $objWriter->endElement();
121 $objWriter->endElement();
124 $objWriter->startElement(
'dxfs');
132 $objWriter->endElement();
135 $objWriter->startElement(
'tableStyles');
136 $objWriter->writeAttribute(
'defaultTableStyle',
'TableStyleMedium9');
137 $objWriter->writeAttribute(
'defaultPivotStyle',
'PivotTableStyle1');
138 $objWriter->endElement();
140 $objWriter->endElement();
143 return $objWriter->getData();
176 $objWriter->startElement(
'fill');
179 $objWriter->startElement(
'gradientFill');
180 $objWriter->writeAttribute(
'type', $pFill->
getFillType());
181 $objWriter->writeAttribute(
'degree', $pFill->
getRotation());
184 $objWriter->startElement(
'stop');
185 $objWriter->writeAttribute(
'position',
'0');
188 $objWriter->startElement(
'color');
189 $objWriter->writeAttribute(
'rgb', $pFill->
getStartColor()->getARGB());
190 $objWriter->endElement();
192 $objWriter->endElement();
195 $objWriter->startElement(
'stop');
196 $objWriter->writeAttribute(
'position',
'1');
199 $objWriter->startElement(
'color');
200 $objWriter->writeAttribute(
'rgb', $pFill->
getEndColor()->getARGB());
201 $objWriter->endElement();
203 $objWriter->endElement();
205 $objWriter->endElement();
207 $objWriter->endElement();
219 $objWriter->startElement(
'fill');
222 $objWriter->startElement(
'patternFill');
223 $objWriter->writeAttribute(
'patternType', $pFill->
getFillType());
228 $objWriter->startElement(
'fgColor');
229 $objWriter->writeAttribute(
'rgb', $pFill->
getStartColor()->getARGB());
230 $objWriter->endElement();
236 $objWriter->startElement(
'bgColor');
237 $objWriter->writeAttribute(
'rgb', $pFill->
getEndColor()->getARGB());
238 $objWriter->endElement();
242 $objWriter->endElement();
244 $objWriter->endElement();
256 $objWriter->startElement(
'font');
264 if ($pFont->
getBold() !== null) {
265 $objWriter->startElement(
'b');
266 $objWriter->writeAttribute(
'val', $pFont->
getBold() ?
'1' :
'0');
267 $objWriter->endElement();
272 $objWriter->startElement(
'i');
273 $objWriter->writeAttribute(
'val', $pFont->
getItalic() ?
'1' :
'0');
274 $objWriter->endElement();
279 $objWriter->startElement(
'strike');
281 $objWriter->endElement();
286 $objWriter->startElement(
'u');
287 $objWriter->writeAttribute(
'val', $pFont->
getUnderline());
288 $objWriter->endElement();
293 $objWriter->startElement(
'vertAlign');
295 $objWriter->writeAttribute(
'val',
'superscript');
297 $objWriter->writeAttribute(
'val',
'subscript');
299 $objWriter->endElement();
303 if ($pFont->
getSize() !== null) {
304 $objWriter->startElement(
'sz');
306 $objWriter->endElement();
310 if ($pFont->
getColor()->getARGB() !== null) {
311 $objWriter->startElement(
'color');
312 $objWriter->writeAttribute(
'rgb', $pFont->
getColor()->getARGB());
313 $objWriter->endElement();
317 if ($pFont->
getName() !== null) {
318 $objWriter->startElement(
'name');
319 $objWriter->writeAttribute(
'val', $pFont->
getName());
320 $objWriter->endElement();
323 $objWriter->endElement();
335 $objWriter->startElement(
'border');
339 $objWriter->writeAttribute(
'diagonalUp',
'true');
340 $objWriter->writeAttribute(
'diagonalDown',
'false');
344 $objWriter->writeAttribute(
'diagonalUp',
'false');
345 $objWriter->writeAttribute(
'diagonalDown',
'true');
349 $objWriter->writeAttribute(
'diagonalUp',
'true');
350 $objWriter->writeAttribute(
'diagonalDown',
'true');
361 $objWriter->endElement();
374 $objWriter->startElement(
'xf');
375 $objWriter->writeAttribute(
'xfId', 0);
377 if ($pStyle->getQuotePrefix()) {
378 $objWriter->writeAttribute(
'quotePrefix', 1);
381 if ($pStyle->getNumberFormat()->getBuiltInFormatCode() ===
false) {
382 $objWriter->writeAttribute(
'numFmtId', (
int) ($this->
getParentWriter()->
getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164));
384 $objWriter->writeAttribute(
'numFmtId', (
int) $pStyle->getNumberFormat()->getBuiltInFormatCode());
391 $objWriter->writeAttribute(
'applyFont', ($spreadsheet->
getDefaultStyle()->getFont()->getHashCode() != $pStyle->getFont()->getHashCode()) ?
'1' :
'0');
392 $objWriter->writeAttribute(
'applyNumberFormat', ($spreadsheet->
getDefaultStyle()->getNumberFormat()->getHashCode() != $pStyle->getNumberFormat()->getHashCode()) ?
'1' :
'0');
393 $objWriter->writeAttribute(
'applyFill', ($spreadsheet->
getDefaultStyle()->getFill()->getHashCode() != $pStyle->getFill()->getHashCode()) ?
'1' :
'0');
394 $objWriter->writeAttribute(
'applyBorder', ($spreadsheet->
getDefaultStyle()->getBorders()->getHashCode() != $pStyle->getBorders()->getHashCode()) ?
'1' :
'0');
395 $objWriter->writeAttribute(
'applyAlignment', ($spreadsheet->
getDefaultStyle()->getAlignment()->getHashCode() != $pStyle->getAlignment()->getHashCode()) ?
'1' :
'0');
396 if ($pStyle->getProtection()->getLocked() != Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != Protection::PROTECTION_INHERIT) {
397 $objWriter->writeAttribute(
'applyProtection',
'true');
401 $objWriter->startElement(
'alignment');
402 $objWriter->writeAttribute(
'horizontal', $pStyle->getAlignment()->getHorizontal());
403 $objWriter->writeAttribute(
'vertical', $pStyle->getAlignment()->getVertical());
406 if ($pStyle->getAlignment()->getTextRotation() >= 0) {
407 $textRotation = $pStyle->getAlignment()->getTextRotation();
408 } elseif ($pStyle->getAlignment()->getTextRotation() < 0) {
409 $textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
411 $objWriter->writeAttribute(
'textRotation', $textRotation);
413 $objWriter->writeAttribute(
'wrapText', ($pStyle->getAlignment()->getWrapText() ?
'true' :
'false'));
414 $objWriter->writeAttribute(
'shrinkToFit', ($pStyle->getAlignment()->getShrinkToFit() ?
'true' :
'false'));
416 if ($pStyle->getAlignment()->getIndent() > 0) {
417 $objWriter->writeAttribute(
'indent', $pStyle->getAlignment()->getIndent());
419 if ($pStyle->getAlignment()->getReadOrder() > 0) {
420 $objWriter->writeAttribute(
'readingOrder', $pStyle->getAlignment()->getReadOrder());
422 $objWriter->endElement();
425 if ($pStyle->getProtection()->getLocked() != Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != Protection::PROTECTION_INHERIT) {
426 $objWriter->startElement(
'protection');
427 if ($pStyle->getProtection()->getLocked() != Protection::PROTECTION_INHERIT) {
428 $objWriter->writeAttribute(
'locked', ($pStyle->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED ?
'true' :
'false'));
430 if ($pStyle->getProtection()->getHidden() != Protection::PROTECTION_INHERIT) {
431 $objWriter->writeAttribute(
'hidden', ($pStyle->getProtection()->getHidden() == Protection::PROTECTION_PROTECTED ?
'true' :
'false'));
433 $objWriter->endElement();
436 $objWriter->endElement();
448 $objWriter->startElement(
'dxf');
451 $this->
writeFont($objWriter, $pStyle->getFont());
454 $this->
writeNumFmt($objWriter, $pStyle->getNumberFormat());
457 $this->
writeFill($objWriter, $pStyle->getFill());
460 $objWriter->startElement(
'alignment');
461 if ($pStyle->getAlignment()->getHorizontal() !== null) {
462 $objWriter->writeAttribute(
'horizontal', $pStyle->getAlignment()->getHorizontal());
464 if ($pStyle->getAlignment()->getVertical() !== null) {
465 $objWriter->writeAttribute(
'vertical', $pStyle->getAlignment()->getVertical());
468 if ($pStyle->getAlignment()->getTextRotation() !== null) {
470 if ($pStyle->getAlignment()->getTextRotation() >= 0) {
471 $textRotation = $pStyle->getAlignment()->getTextRotation();
472 } elseif ($pStyle->getAlignment()->getTextRotation() < 0) {
473 $textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
475 $objWriter->writeAttribute(
'textRotation', $textRotation);
477 $objWriter->endElement();
480 $this->
writeBorder($objWriter, $pStyle->getBorders());
483 if (($pStyle->getProtection()->getLocked() !== null) || ($pStyle->getProtection()->getHidden() !== null)) {
485 $pStyle->getProtection()->getLocked() !== Protection::PROTECTION_INHERIT ||
486 $pStyle->getProtection()->getHidden() !== Protection::PROTECTION_INHERIT
488 $objWriter->startElement(
'protection');
490 ($pStyle->getProtection()->getLocked() !== null) &&
491 ($pStyle->getProtection()->getLocked() !== Protection::PROTECTION_INHERIT)
493 $objWriter->writeAttribute(
'locked', ($pStyle->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED ?
'true' :
'false'));
496 ($pStyle->getProtection()->getHidden() !== null) &&
497 ($pStyle->getProtection()->getHidden() !== Protection::PROTECTION_INHERIT)
499 $objWriter->writeAttribute(
'hidden', ($pStyle->getProtection()->getHidden() == Protection::PROTECTION_PROTECTED ?
'true' :
'false'));
501 $objWriter->endElement();
505 $objWriter->endElement();
519 $objWriter->startElement($pName);
523 $objWriter->startElement(
'color');
524 $objWriter->writeAttribute(
'rgb', $pBorder->
getColor()->getARGB());
525 $objWriter->endElement();
527 $objWriter->endElement();
544 if ($formatCode !== null) {
545 $objWriter->startElement(
'numFmt');
546 $objWriter->writeAttribute(
'numFmtId', ($pId + 164));
547 $objWriter->writeAttribute(
'formatCode', $formatCode);
548 $objWriter->endElement();
573 for (
$i = 0;
$i < $sheetCount; ++
$i) {
574 foreach ($spreadsheet->
getSheet(
$i)->getConditionalStylesCollection() as $conditionalStyles) {
575 foreach ($conditionalStyles as $conditionalStyle) {
576 $aStyles[] = $conditionalStyle;
603 $aStyles = $this->
allStyles($spreadsheet);
605 foreach ($aStyles as
$style) {
606 if (!isset($aFills[$style->getFill()->getHashCode()])) {
607 $aFills[$style->getFill()->getHashCode()] = $style->getFill();
623 $aStyles = $this->
allStyles($spreadsheet);
626 foreach ($aStyles as
$style) {
627 if (!isset($aFonts[$style->getFont()->getHashCode()])) {
628 $aFonts[$style->getFont()->getHashCode()] = $style->getFont();
640 public function allBorders(
Spreadsheet $spreadsheet)
644 $aStyles = $this->
allStyles($spreadsheet);
647 foreach ($aStyles as
$style) {
648 if (!isset($aBorders[$style->getBorders()->getHashCode()])) {
649 $aBorders[$style->getBorders()->getHashCode()] = $style->getBorders();
661 public function allNumberFormats(
Spreadsheet $spreadsheet)
665 $aStyles = $this->
allStyles($spreadsheet);
668 foreach ($aStyles as
$style) {
669 if ($style->getNumberFormat()->getBuiltInFormatCode() ===
false && !isset($aNumFmts[$style->getNumberFormat()->getHashCode()])) {
670 $aNumFmts[$style->getNumberFormat()->getHashCode()] = $style->getNumberFormat();
getColor()
Get Border Color.
getSheet($pIndex)
Get sheet by index.
const FILL_PATTERN_GRAY125
writeCellStyleDxf(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Style $pStyle)
Write Cell Style Dxf.
allConditionalStyles(Spreadsheet $spreadsheet)
Get an array of all conditional styles.
const FILL_GRADIENT_LINEAR
getDiagonalDirection()
Get DiagonalDirection.
writeBorderPr(XMLWriter $objWriter, $pName, Border $pBorder)
Write BorderPr.
getStartColor()
Get Start Color.
getDefaultStyle()
Get default style.
getUnderline()
Get Underline.
getNumFmtHashTable()
Get NumberFormat HashTable.
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.
getCellXfCollection()
Get the workbook collection of cellXfs.
writeCellStyleXf(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Style $pStyle, Spreadsheet $spreadsheet)
Write Cell Style Xf.
getFillHashTable()
Get Fill HashTable.
getDiagonal()
Get Diagonal.
writeStyles(Spreadsheet $spreadsheet)
Write styles to XML format.
getParentWriter()
Get parent Xlsx object.
getStrikethrough()
Get Strikethrough.
getFillType()
Get Fill Type.
getSuperscript()
Get Superscript.
getSubscript()
Get Subscript.
getBorderStyle()
Get Border style.
writeGradientFill(XMLWriter $objWriter, Fill $pFill)
Write Gradient Fill.
writeFont(XMLWriter $objWriter, Font $pFont)
Write Font.
writeBorder(XMLWriter $objWriter, Borders $pBorders)
Write Border.
writePatternFill(XMLWriter $objWriter, Fill $pFill)
Write Pattern Fill.
getFontHashTable()
Get HashTable.
getBordersHashTable()
Get Borders HashTable.
getUseDiskCaching()
Get use disk caching where possible?
getRotation()
Get Rotation.
getStylesConditionalHashTable()
Get Conditional HashTable.
writeNumFmt(XMLWriter $objWriter, NumberFormat $pNumberFormat, $pId=0)
Write NumberFormat.
getEndColor()
Get End Color.
allStyles(Spreadsheet $spreadsheet)
Get an array of all styles.
writeFill(XMLWriter $objWriter, Fill $pFill)
Write Fill.
getSheetCount()
Get sheet count.