PhpSpreadsheet/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php

44 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class ColumnWidthTest extends AbstractFunctional
{
public function providerFormats()
{
return [
['Xlsx'],
];
}
/**
* @dataProvider providerFormats
*
* @param $format
*/
2020-05-18 04:49:57 +00:00
public function testReadColumnWidth($format): void
{
// create new sheet with column width
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$sheet->getColumnDimension('A')->setWidth(20);
$this->assertColumn($spreadsheet);
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
$this->assertColumn($reloadedSpreadsheet);
}
2020-05-18 04:49:57 +00:00
private function assertColumn(Spreadsheet $spreadsheet): void
{
$sheet = $spreadsheet->getActiveSheet();
$columnDimensions = $sheet->getColumnDimensions();
self::assertArrayHasKey('A', $columnDimensions);
$column = array_shift($columnDimensions);
self::assertEquals(20, $column->getWidth());
}
}