mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 14:38:36 +00:00
92a50d134f
Initial implementation of Excel's tables feature (i.e. Select Home >
Format as Table in Excel App).
Tables are similar to AutoFilter but tables have other advantages like
named ranges, easy formatting, totals row and header row with filter.
Tables can also be converted to charts and pivot tables easily.
Usage:
$table = new Table();
$table->setName('Sales_Data');
$table->setRange('A1:D17');
$spreadsheet->getActiveSheet()->addTable($table);
In this Commit:
- Added Table API with initial support for header and totals row.
- Added complete styling options for Table.
- Added Xlsx Writer for Table.
- Added samples.
- Covered with unit tests.
To be done:
- Filter expressions similar to AutoFilter.
- Precalucate formulas for totals row (Check sample 2).
- Table named ranges in formulas and calculation.
48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Worksheet\Table;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Table\TableStyle;
|
|
|
|
class TableStyleTest extends SetupTeardown
|
|
{
|
|
private const INITIAL_RANGE = 'H2:O256';
|
|
|
|
public function testVariousSets(): void
|
|
{
|
|
$sheet = $this->getSheet();
|
|
$table = new Table(self::INITIAL_RANGE, $sheet);
|
|
$style = $table->getStyle();
|
|
|
|
$result = $style->setTheme(TableStyle::TABLE_STYLE_DARK1);
|
|
self::assertInstanceOf(TableStyle::class, $result);
|
|
self::assertEquals(TableStyle::TABLE_STYLE_DARK1, $style->getTheme());
|
|
|
|
$result = $style->setShowFirstColumn(true);
|
|
self::assertInstanceOf(TableStyle::class, $result);
|
|
self::assertTrue($style->getShowFirstColumn());
|
|
|
|
$result = $style->setShowLastColumn(true);
|
|
self::assertInstanceOf(TableStyle::class, $result);
|
|
self::assertTrue($style->getShowLastColumn());
|
|
|
|
$result = $style->setShowRowStripes(true);
|
|
self::assertInstanceOf(TableStyle::class, $result);
|
|
self::assertTrue($style->getShowRowStripes());
|
|
|
|
$result = $style->setShowColumnStripes(true);
|
|
self::assertInstanceOf(TableStyle::class, $result);
|
|
self::assertTrue($style->getShowColumnStripes());
|
|
}
|
|
|
|
public function testTable(): void
|
|
{
|
|
$sheet = $this->getSheet();
|
|
$table = new Table(self::INITIAL_RANGE, $sheet);
|
|
$style = new TableStyle();
|
|
$style->setTable($table);
|
|
self::assertEquals($table, $style->getTable());
|
|
}
|
|
}
|