mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-02 13:41:21 +00:00
2d9375f847
Fix #4584. As discussed there, MS has implemented this situation in a way that I frankly do not understand. Marking a row with a wrapped cell to *not* use the default row height seems to affect every other populated row. Very odd. Nevertheless, adding a new `customFormat` boolean property to RowDimension seems to be a way to resolve this problem. Note that the Xml generated by Excel already outputs a `customFormat` attribute when a style is applied to a row. This PR just adds that property for when it is needed for rowHeight. It need not, and should not, be set by the application when a style is applied to the row; PhpSpreadsheet will take care of that on its own. Although the problem was raised for Xlsx format (I think), I investigated other relevant output formats as well. Html tends to do its own cell wrapping. I think the results after this change match the results before. Xls already handled the output side of this situation without difficulty. A change was needed on the input side, and is included as part of this PR. Ods did not handle default row height at all. As with other style properties, it is difficult to handle this on the input side, and this PR does nothing to improve that situation. However, we are, at least, able to provide some relief on the output side. Not complete relief - in order to apply the default size to unpopulated rows, we'd need to at least populate them with the `table:number-rows-repeated` attribute, and that has often been a source of problems, so I'm not willing to go there yet. This PR just ensures that all populated rows will have the correct height.
45 lines
2.0 KiB
PHP
45 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Ods;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Ods as OdsWriter;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class Issue4584Test extends TestCase
|
|
{
|
|
public function testWriteRowDimensions(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->getDefaultRowDimension()->setRowHeight(20);
|
|
$sheet->setCellValue('A1', 'hello there world 1');
|
|
$sheet->getStyle('A1')->getAlignment()->setWrapText(true);
|
|
$sheet->getRowDimension(1)->setCustomFormat(true);
|
|
$sheet->setCellValue('A2', 'hello there world 2');
|
|
$sheet->setCellValue('A4', 'hello there world 4');
|
|
$writer = new OdsWriter($spreadsheet);
|
|
$writerWorksheet = new OdsWriter\Content($writer);
|
|
$data = $writerWorksheet->write();
|
|
self::assertStringContainsString(
|
|
'<style:style style:family="table-row" style:name="ro0"><style:table-row-properties style:row-height="0.706cm" style:use-optimal-row-height="false" fo:break-before="auto"/></style:style>',
|
|
$data
|
|
);
|
|
self::assertStringContainsString(
|
|
'<table:table-row><table:table-cell table:style-name="ce1" office:value-type="string"><text:p>hello there world 1</text:p></table:table-cell></table:table-row>',
|
|
$data
|
|
);
|
|
self::assertStringContainsString(
|
|
'<table:table-row table:style-name="ro0"><table:table-cell table:style-name="ce0" office:value-type="string"><text:p>hello there world 2</text:p></table:table-cell></table:table-row>',
|
|
$data
|
|
);
|
|
self::assertStringContainsString(
|
|
'<table:table-row table:number-rows-repeated="1"/><table:table-row table:style-name="ro0"><table:table-cell table:style-name="ce0" office:value-type="string"><text:p>hello there world 4</text:p></table:table-cell></table:table-row>',
|
|
$data
|
|
);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|