Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Trying to add vertical alignment and fix textWrap for XLSXWriter #868

Closed
jonnott opened this issue Feb 10, 2022 · 1 comment
Closed

Trying to add vertical alignment and fix textWrap for XLSXWriter #868

jonnott opened this issue Feb 10, 2022 · 1 comment

Comments

@jonnott
Copy link

jonnott commented Feb 10, 2022

I'm trying to create a PR to add cellVerticalAlignment (in addition to cellAlignment) [top/bottom/justify/center] etc, and to fix setShouldWrapText so that wrapText can be explicitly set as false by default, as well as true.

Hoping in the process to fix these issues:
#829
#737

But things are a little unclear to me.. if I create a writer, without any configuration..

$writer = WriterEntityFactory::createXLSXWriter();

..and then var_dump($registeredStyles) and var_dump($content) (the output) during StyleManager's getCellXfsSectionContent() method, I get:

object(Box\Spout\Common\Entity\Style\Style)#3836 (32) {
  ["id":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(0)
  ["fontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(12)
  ["hasSetFontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["fontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(6) "000000"
  ["hasSetFontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(7) "Calibri"
  ["hasSetFontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyFont":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["cellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["shouldApplyCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["cellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["shouldWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["hasSetWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["border":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["shouldApplyBorder":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["backgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetBackgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["format":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetFormat":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["isRegistered":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["isEmpty":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
}
object(Box\Spout\Common\Entity\Style\Style)#7035 (32) {
  ["id":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(1)
  ["fontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(12)
  ["hasSetFontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["fontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(6) "000000"
  ["hasSetFontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(7) "Calibri"
  ["hasSetFontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyFont":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["cellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["shouldApplyCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["cellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["shouldWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["hasSetWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["border":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["shouldApplyBorder":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["backgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetBackgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["format":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetFormat":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["isRegistered":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["isEmpty":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
}
string(315) "<cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyFont="1" applyBorder="0" applyAlignment="1"><alignment wrapText="true"/></xf><xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1" applyBorder="0" applyAlignment="1"><alignment wrapText="true"/></xf></cellXfs>"

What I don't understand is, why are there two styles defined by default, and why therefore a count of 2 for <cellXfs> ?

Then if I apply the styles I want:

				$writer->setDefaultRowStyle(
					(new StyleBuilder)
					->setFontName('Arial')
					->setFontSize(10)
					->setShouldWrapText(FALSE)
					->setCellAlignment(CellAlignment::LEFT)
					->setCellVerticalAlignment(CellVerticalAlignment::TOP)
					->build()
				);

These same dumps change to:

object(Box\Spout\Common\Entity\Style\Style)#7018 (32) {
  ["id":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(0)
  ["fontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(10)
  ["hasSetFontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["fontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(6) "000000"
  ["hasSetFontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(5) "Arial"
  ["hasSetFontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyFont":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["cellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(4) "left"
  ["hasSetCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["cellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(3) "top"
  ["hasSetCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["border":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["shouldApplyBorder":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["backgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetBackgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["format":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetFormat":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["isRegistered":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["isEmpty":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
}
object(Box\Spout\Common\Entity\Style\Style)#7175 (32) {
  ["id":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(1)
  ["fontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontBold":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontItalic":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontUnderline":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["hasSetFontStrikethrough":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  int(10)
  ["hasSetFontSize":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["fontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(6) "000000"
  ["hasSetFontColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["fontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(5) "Arial"
  ["hasSetFontName":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["shouldApplyFont":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["cellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  string(4) "left"
  ["hasSetCellAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["shouldApplyCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["cellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetCellVerticalAlignment":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["shouldWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["hasSetWrapText":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["border":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["shouldApplyBorder":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["backgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetBackgroundColor":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["format":"Box\Spout\Common\Entity\Style\Style":private]=>
  NULL
  ["hasSetFormat":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
  ["isRegistered":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(true)
  ["isEmpty":"Box\Spout\Common\Entity\Style\Style":private]=>
  bool(false)
}
string(367) "<cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyFont="1" applyBorder="0" applyAlignment="1"><alignment horizontal="left" vertical="top" wrapText="false"/></xf><xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1" applyBorder="0" applyAlignment="1"><alignment horizontal="left" wrapText="true"/></xf></cellXfs>"

So, some of my desired style stipulations (font: Arial and size: 10) are getting applied to BOTH of the $registeredStyles, but the horizontal=left, vertical=top and wrapText=false are only being applied in the first style, and therefore the output contains the correct styling in the first <xf> tag, but not in the 2nd.

If I completely manually override the output of getCellXfsSectionContent() to return a manual string with what I want, i.e.:

<cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyFont="1" applyBorder="0" applyAlignment="1"><alignment horizontal="left" vertical="top" wrapText="false"/></xf><xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1" applyBorder="0" applyAlignment="1"><alignment horizontal="left" vertical="top" wrapText="false"/></xf></cellXfs>

..then the resulting .xlsx file's cells are all formatted how I expect.

Any ideas what's not working right here?

@jonnott
Copy link
Author

jonnott commented Feb 10, 2022

@alamirault @adrilo

@jonnott jonnott closed this as completed Feb 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant