Html cellwrapping (#1075)
* When <br> appears in a table cell, set the cell to wrap. If the cell is not set to wrap, it appears as a single line when first displayed in Excel, although editing the cell will cause Excel to wrap it. * fix whitespace Upstream has a coding standard that includes whitespace * Add Unit tests for cell wrapping * Update changelog
This commit is contained in:
parent
de3f948b27
commit
bf59cf0cbc
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- When <br> appears in a table cell, set the cell to wrap [Issue #1071](https://github.com/PHPOffice/PhpSpreadsheet/issues/1071) and [PR #1070](https://github.com/PHPOffice/PhpSpreadsheet/pull/1070)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- COUPNUM should not return zero when settlement is in the last period - [Issue #1020](https://github.com/PHPOffice/PhpSpreadsheet/issues/1020) and [PR #1021](https://github.com/PHPOffice/PhpSpreadsheet/pull/1021)
|
- COUPNUM should not return zero when settlement is in the last period - [Issue #1020](https://github.com/PHPOffice/PhpSpreadsheet/issues/1020) and [PR #1021](https://github.com/PHPOffice/PhpSpreadsheet/pull/1021)
|
||||||
|
|
|
@ -374,8 +374,9 @@ class Html extends BaseReader
|
||||||
// no break
|
// no break
|
||||||
case 'br':
|
case 'br':
|
||||||
if ($this->tableLevel > 0) {
|
if ($this->tableLevel > 0) {
|
||||||
// If we're inside a table, replace with a \n
|
// If we're inside a table, replace with a \n and set the cell to wrap
|
||||||
$cellContent .= "\n";
|
$cellContent .= "\n";
|
||||||
|
$sheet->getStyle($column . $row)->getAlignment()->setWrapText(true);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise flush our existing content and move the row cursor on
|
// Otherwise flush our existing content and move the row cursor on
|
||||||
$this->flushCell($sheet, $column, $row, $cellContent);
|
$this->flushCell($sheet, $column, $row, $cellContent);
|
||||||
|
|
|
@ -266,6 +266,39 @@ class HtmlTest extends TestCase
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanApplyCellWrapping()
|
||||||
|
{
|
||||||
|
$html = '<table>
|
||||||
|
<tr>
|
||||||
|
<td>Hello World</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Hello<br />World</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Hello<br>World</td>
|
||||||
|
</tr>
|
||||||
|
</table>';
|
||||||
|
$filename = $this->createHtml($html);
|
||||||
|
$spreadsheet = $this->loadHtmlIntoSpreadsheet($filename);
|
||||||
|
$firstSheet = $spreadsheet->getSheet(0);
|
||||||
|
|
||||||
|
$cellStyle = $firstSheet->getStyle('A1');
|
||||||
|
self::assertFalse($cellStyle->getAlignment()->getWrapText());
|
||||||
|
|
||||||
|
$cellStyle = $firstSheet->getStyle('A2');
|
||||||
|
self::assertTrue($cellStyle->getAlignment()->getWrapText());
|
||||||
|
$cellValue = $firstSheet->getCell('A2')->getValue();
|
||||||
|
$this->assertContains("\n", $cellValue);
|
||||||
|
|
||||||
|
$cellStyle = $firstSheet->getStyle('A3');
|
||||||
|
self::assertTrue($cellStyle->getAlignment()->getWrapText());
|
||||||
|
$cellValue = $firstSheet->getCell('A3')->getValue();
|
||||||
|
$this->assertContains("\n", $cellValue);
|
||||||
|
|
||||||
|
unlink($filename);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $html
|
* @param string $html
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue