mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-04 06:33:33 +00:00
4b3b0d45ad
This is the second recent occasion where style for whole row or column is behaving unexpectedly (see issue #4285). For the earlier issue, a documentation update was made to show the preferred method of styling. Setting styles for row(s) or column(s) in that way will work just fine, however retrieving the style doesn't yield the expected result. Although that problem can be overcome with existing code, simpler methods are needed, and this PR adds methods getRowStyle and getColumnStyle to Worksheet. I will continue to investigate why this problem and the one from 4285 have unexpected results.
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ColumnRowStyleTest extends TestCase
|
|
{
|
|
public function testColumnStyle(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$columnStyle = $sheet->getStyle('B:C');
|
|
$columnStyle->applyFromArray([
|
|
'font' => ['name' => 'Who knows'],
|
|
]);
|
|
self::assertSame(
|
|
'Who knows',
|
|
$sheet->getColumnStyle('B')?->getFont()->getName()
|
|
);
|
|
self::assertSame(
|
|
'Who knows',
|
|
$sheet->getColumnStyle('C')?->getFont()->getName()
|
|
);
|
|
self::assertNull(
|
|
$sheet->getColumnStyle('A')?->getFont()->getName()
|
|
);
|
|
self::assertNull(
|
|
$sheet->getColumnStyle('D')?->getFont()->getName()
|
|
);
|
|
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function testRowStyle(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$rowStyle = $sheet->getStyle('2:3');
|
|
$rowStyle->applyFromArray([
|
|
'font' => ['name' => 'Who knows'],
|
|
]);
|
|
self::assertSame(
|
|
'Who knows',
|
|
$sheet->getRowStyle(2)?->getFont()->getName()
|
|
);
|
|
self::assertSame(
|
|
'Who knows',
|
|
$sheet->getRowStyle(3)?->getFont()->getName()
|
|
);
|
|
self::assertNull(
|
|
$sheet->getRowStyle(1)?->getFont()->getName()
|
|
);
|
|
self::assertNull(
|
|
$sheet->getRowStyle(4)?->getFont()->getName()
|
|
);
|
|
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|