Add setCellVerticalAlignment() & allow setShouldWrapText() to be explicitly set as false
- add Common\Entity\Style\CellVerticalAlignment - duplicate get/set/hasSet/shouldApply methods for CellAlignment in Common\Entity\Style\Style for CellVerticalAlignment instead, plus corresponding properties - add setCellVerticalAlignment method to Common\Creator\Style\StyleBuilder - add vertical alignment to StyleMerger:: mergeCellProperties() - adjust wrapText logic in mergeCellProperties() to fix issue https://github.com/box/spout/issues/829 - apply vertical cell styling for both XLSX and ODS, via corresponding StyleManager classes - transform vertical alignment ‘center’ to ‘middle’ for ODS - fix logic around wrapText such that the choice whether to include wrapping styles depends on hasSetWrapText() being true, and then use shouldWrapText() thereafter to either set wrapping or no wrapping (for XLSX, wrapText=“1” or wrapText=“0”, for ODS, wrap-option=wrap or wrap-option=no-wrap). previously there was no way to set wrapping to be OFF, only to set it to be ON. - add new tests to ensure shouldWrapText(false) results in the correct negated wrapText (XLSX) / wrap-option (ODS) styles - add new tests to StyleBuilderTest for vertical alignment - add vertical alignment to documentation.md
This commit is contained in:
1 parent
cc42c1d29f
commit
887d6ef033
11 files changed
+229
-24
No files matched your search
@@ -4,6 +4,7 @@ namespace Box\Spout\Writer\ODS\Manager\Style;
|
||||
|
||||
use Box\Spout\Common\Entity\Style\BorderPart;
|
||||
use Box\Spout\Common\Entity\Style\CellAlignment;
|
||||
use Box\Spout\Common\Entity\Style\CellVerticalAlignment;
|
||||
use Box\Spout\Writer\Common\Entity\Worksheet;
|
||||
use Box\Spout\Writer\ODS\Helper\BorderHelper;
|
||||
|
||||
@@ -277,12 +278,13 @@ EOD;
|
||||
*/
|
||||
private function getParagraphPropertiesSectionContent($style)
|
||||
{
|
||||
if (!$style->shouldApplyCellAlignment()) {
|
||||
if (!$style->shouldApplyCellAlignment() && !$style->shouldApplyCellVerticalAlignment()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '<style:paragraph-properties '
|
||||
. $this->getCellAlignmentSectionContent($style)
|
||||
. $this->getCellVerticalAlignmentSectionContent($style)
|
||||
. '/>';
|
||||
}
|
||||
|
||||
@@ -301,6 +303,21 @@ EOD;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the cell vertical alignment definition for the "<style:paragraph-properties>" section
|
||||
*
|
||||
* @param \Box\Spout\Common\Entity\Style\Style $style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCellVerticalAlignmentSectionContent($style)
|
||||
{
|
||||
return \sprintf(
|
||||
' fo:vertical-align="%s" ',
|
||||
$this->transformCellVerticalAlignment($style->getCellVerticalAlignment())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Even though "left" and "right" alignments are part of the spec, and interpreted
|
||||
* respectively as "start" and "end", using the recommended values increase compatibility
|
||||
@@ -319,6 +336,21 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spec uses 'middle' rather than 'center'
|
||||
* http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1420236_253892949
|
||||
*
|
||||
* @param string $cellAlignment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function transformCellVerticalAlignment($cellVerticalAlignment)
|
||||
{
|
||||
return ($cellVerticalAlignment === CellVerticalAlignment::CENTER)
|
||||
? 'middle'
|
||||
: $cellVerticalAlignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the "<style:table-cell-properties>" section, inside "<style:style>" section
|
||||
*
|
||||
@@ -329,8 +361,8 @@ EOD;
|
||||
{
|
||||
$content = '<style:table-cell-properties ';
|
||||
|
||||
if ($style->shouldWrapText()) {
|
||||
$content .= $this->getWrapTextXMLContent();
|
||||
if ($style->hasSetWrapText()) {
|
||||
$content .= $this->getWrapTextXMLContent($style->shouldWrapText());
|
||||
}
|
||||
|
||||
if ($style->shouldApplyBorder()) {
|
||||
@@ -349,11 +381,12 @@ EOD;
|
||||
/**
|
||||
* Returns the contents of the wrap text definition for the "<style:table-cell-properties>" section
|
||||
*
|
||||
* @param boolean $shouldWrapText
|
||||
* @return string
|
||||
*/
|
||||
private function getWrapTextXMLContent()
|
||||
private function getWrapTextXMLContent($shouldWrapText)
|
||||
{
|
||||
return ' fo:wrap-option="wrap" style:vertical-align="automatic" ';
|
||||
return ' fo:wrap-option="' . ($shouldWrapText ? '' : 'no-') . 'wrap" style:vertical-align="automatic" ';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user