Implement basic autofilter ranges with Gnumeric Reader (#2057)
* Load basic autofilter ranges with Gnumeric Reader * Handle null values passed to row height/column with/merged cells/autofilters
This commit is contained in:
parent
4be9366722
commit
5ee4fbf090
|
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
### Added
|
||||
|
||||
- Implemented basic AutoFiltering for Ods Reader and Writer [PR #2053](https://github.com/PHPOffice/PhpSpreadsheet/pull/2053)
|
||||
- Implemented basic AutoFiltering for Gnumeric Reader [PR #2055](https://github.com/PHPOffice/PhpSpreadsheet/pull/2055)
|
||||
- Improved support for Row and Column ranges in formulae [Issue #1755](https://github.com/PHPOffice/PhpSpreadsheet/issues/1755) [PR #2028](https://github.com/PHPOffice/PhpSpreadsheet/pull/2028)
|
||||
- Implemented URLENCODE() Web Function
|
||||
- Implemented the CHITEST(), CHISQ.DIST() and CHISQ.INV() and equivalent Statistical functions, for both left- and right-tailed distributions.
|
||||
|
|
|
|||
|
|
@ -1314,7 +1314,7 @@
|
|||
<td style="text-align: center; color: orange;">●</td>
|
||||
<td></td>
|
||||
<td style="text-align: center; color: orange;">●</td>
|
||||
<td></td>
|
||||
<td style="text-align: center; color: orange;">●</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td style="text-align: center; color: orange;">●</td>
|
||||
|
|
|
|||
|
|
@ -482,6 +482,7 @@ class Gnumeric extends BaseReader
|
|||
$this->processColumnWidths($sheet, $maxCol);
|
||||
$this->processRowHeights($sheet, $maxRow);
|
||||
$this->processMergedCells($sheet);
|
||||
$this->processAutofilter($sheet);
|
||||
|
||||
++$worksheetID;
|
||||
}
|
||||
|
|
@ -514,10 +515,10 @@ class Gnumeric extends BaseReader
|
|||
}
|
||||
}
|
||||
|
||||
private function processMergedCells(SimpleXMLElement $sheet): void
|
||||
private function processMergedCells(?SimpleXMLElement $sheet): void
|
||||
{
|
||||
// Handle Merged Cells in this worksheet
|
||||
if (isset($sheet->MergedRegions)) {
|
||||
if ($sheet !== null && isset($sheet->MergedRegions)) {
|
||||
foreach ($sheet->MergedRegions->Merge as $mergeCells) {
|
||||
if (strpos($mergeCells, ':') !== false) {
|
||||
$this->spreadsheet->getActiveSheet()->mergeCells($mergeCells);
|
||||
|
|
@ -526,6 +527,20 @@ class Gnumeric extends BaseReader
|
|||
}
|
||||
}
|
||||
|
||||
private function processAutofilter(?SimpleXMLElement $sheet): void
|
||||
{
|
||||
if ($sheet !== null && isset($sheet->Filters)) {
|
||||
foreach ($sheet->Filters->Filter as $autofilter) {
|
||||
if ($autofilter !== null) {
|
||||
$attributes = $autofilter->attributes();
|
||||
if (isset($attributes['Area'])) {
|
||||
$this->spreadsheet->getActiveSheet()->setAutoFilter((string) $attributes['Area']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setColumnWidth(int $whichColumn, float $defaultWidth): void
|
||||
{
|
||||
$columnDimension = $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($whichColumn + 1));
|
||||
|
|
@ -564,9 +579,9 @@ class Gnumeric extends BaseReader
|
|||
return $whichColumn;
|
||||
}
|
||||
|
||||
private function processColumnWidths(SimpleXMLElement $sheet, int $maxCol): void
|
||||
private function processColumnWidths(?SimpleXMLElement $sheet, int $maxCol): void
|
||||
{
|
||||
if ((!$this->readDataOnly) && (isset($sheet->Cols))) {
|
||||
if ((!$this->readDataOnly) && $sheet !== null && (isset($sheet->Cols))) {
|
||||
// Column Widths
|
||||
$defaultWidth = 0;
|
||||
$columnAttributes = $sheet->Cols->attributes();
|
||||
|
|
@ -622,9 +637,9 @@ class Gnumeric extends BaseReader
|
|||
return $whichRow;
|
||||
}
|
||||
|
||||
private function processRowHeights(SimpleXMLElement $sheet, int $maxRow): void
|
||||
private function processRowHeights(?SimpleXMLElement $sheet, int $maxRow): void
|
||||
{
|
||||
if ((!$this->readDataOnly) && (isset($sheet->Rows))) {
|
||||
if ((!$this->readDataOnly) && $sheet !== null && (isset($sheet->Rows))) {
|
||||
// Row Heights
|
||||
$defaultHeight = 0;
|
||||
$rowAttributes = $sheet->Rows->attributes();
|
||||
|
|
@ -646,10 +661,10 @@ class Gnumeric extends BaseReader
|
|||
}
|
||||
}
|
||||
|
||||
private function processDefinedNames(SimpleXMLElement $gnmXML): void
|
||||
private function processDefinedNames(?SimpleXMLElement $gnmXML): void
|
||||
{
|
||||
// Loop through definedNames (global named ranges)
|
||||
if (isset($gnmXML->Names)) {
|
||||
if ($gnmXML !== null && isset($gnmXML->Names)) {
|
||||
foreach ($gnmXML->Names->Name as $definedName) {
|
||||
$name = (string) $definedName->name;
|
||||
$value = (string) $definedName->value;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AutoFilterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Spreadsheet
|
||||
*/
|
||||
private $spreadsheet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/Gnumeric/Autofilter_Basic.gnumeric';
|
||||
$reader = new Gnumeric();
|
||||
$this->spreadsheet = $reader->load($filename);
|
||||
}
|
||||
|
||||
public function testAutoFilterRange(): void
|
||||
{
|
||||
$worksheet = $this->spreadsheet->getActiveSheet();
|
||||
|
||||
$autoFilterRange = $worksheet->getAutoFilter()->getRange();
|
||||
|
||||
self::assertSame('A1:D57', $autoFilterRange);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue