Add a way to disable text wrapping (Fix #247)

This commit is contained in:
hastegan 2016-09-10 01:18:22 +02:00
parent 3e0afd858f
commit ba6c4c7b78
4 changed files with 20 additions and 11 deletions

View File

@ -209,7 +209,7 @@ Font | Bold | `StyleBuilder::setFontBold()`
| Font name | `StyleBuilder::setFontName('Arial')` | Font name | `StyleBuilder::setFontName('Arial')`
| Font size | `StyleBuilder::setFontSize(14)` | Font size | `StyleBuilder::setFontSize(14)`
| Font color | `StyleBuilder::setFontColor(Color::BLUE)`<br>`StyleBuilder::setFontColor(Color::rgb(0, 128, 255))` | Font color | `StyleBuilder::setFontColor(Color::BLUE)`<br>`StyleBuilder::setFontColor(Color::rgb(0, 128, 255))`
Alignment | Wrap text | `StyleBuilder::setShouldWrapText()` Alignment | Wrap text | `StyleBuilder::setShouldWrapText(true|false)`
#### New sheet creation #### New sheet creation

View File

@ -122,7 +122,7 @@ abstract class AbstractStyleHelper
protected function applyWrapTextIfCellContainsNewLine($style, $dataRow) protected function applyWrapTextIfCellContainsNewLine($style, $dataRow)
{ {
// if the "wrap text" option is already set, no-op // if the "wrap text" option is already set, no-op
if ($style->shouldWrapText()) { if ($style->hasSetWrapText()) {
return $style; return $style;
} }

View File

@ -269,15 +269,24 @@ class Style
} }
/** /**
* @param boolean $shouldWrap Should the text be wrapped
* @return Style * @return Style
*/ */
public function setShouldWrapText() public function setShouldWrapText($shouldWrap = true)
{ {
$this->shouldWrapText = true; $this->shouldWrapText = $shouldWrap;
$this->hasSetWrapText = true; $this->hasSetWrapText = true;
return $this; return $this;
} }
/**
* @return boolean
*/
public function hasSetWrapText()
{
return $this->hasSetWrapText;
}
/** /**
* @return bool Whether specific font properties should be applied * @return bool Whether specific font properties should be applied
*/ */

View File

@ -109,15 +109,15 @@ class StyleBuilder
} }
/** /**
* Makes the text wrap in the cell if it's too long or * Makes the text wrap in the cell if requested
* on multiple lines.
* *
* @api * @api
* @param boolean $shouldWrap Should the text be wrapped
* @return StyleBuilder * @return StyleBuilder
*/ */
public function setShouldWrapText() public function setShouldWrapText($shouldWrap = true)
{ {
$this->style->setShouldWrapText(); $this->style->setShouldWrapText($shouldWrap);
return $this; return $this;
} }