Skip to content

Removing a column with cells within a range of Table causes a type error #3310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adawolfa opened this issue Jan 20, 2023 · 2 comments
Closed

Comments

@adawolfa
Copy link

adawolfa commented Jan 20, 2023

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Worksheet::removeColumnByIndex() not crashing.

What is the current behavior?

Worksheet::removeColumnByIndex() crashes with:

Fatal error: Uncaught TypeError: PhpOffice\PhpSpreadsheet\Worksheet\Table\Column::updateStructuredReferences(): Argument #3 ($newTitle) must be of type string, null given, called in vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Cell\Cell.php on line 210 and defined in vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Table\Column.php:208
Stack trace:
#0 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Cell\Cell.php(210): PhpOffice\PhpSpreadsheet\Worksheet\Table\Column::updateStructuredReferences(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet), 'foo', NULL)
#1 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Cell\Cell.php(302): PhpOffice\PhpSpreadsheet\Cell\Cell::updateIfCellIsTableHeader(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet), Object(PhpOffice\PhpSpreadsheet\Cell\Cell), 'foo', NULL)
#2 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\ReferenceHelper.php(1011): PhpOffice\PhpSpreadsheet\Cell\Cell->setValueExplicit(NULL, 'null')
#3 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\ReferenceHelper.php(985): PhpOffice\PhpSpreadsheet\ReferenceHelper->clearStripCell(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet), 'C1')
#4 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\ReferenceHelper.php(403): PhpOffice\PhpSpreadsheet\ReferenceHelper->clearColumnStrips(2, 4, -1, Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet))
#5 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Worksheet.php(2528): PhpOffice\PhpSpreadsheet\ReferenceHelper->insertNewBefore('D1', -1, 0, Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet))
#6 vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Worksheet.php(2579): PhpOffice\PhpSpreadsheet\Worksheet\Worksheet->removeColumn('D', 1)
#7 test.php(16): PhpOffice\PhpSpreadsheet\Worksheet\Worksheet->removeColumnByIndex(3)
#8 {main}
  thrown in vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Table\Column.php on line 208

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Table;

require(__DIR__ . '/vendor/autoload.php');

$spreadsheet = new Spreadsheet;
$sheet = $spreadsheet->getActiveSheet();

$sheet->addTable(new Table('A1:D2'));

$sheet->setCellValue('C1', 'foo');
$sheet->setCellValue('C2', 'bar');

$sheet->removeColumnByIndex(3);

Which versions of PhpSpreadsheet and PHP are affected?

1.26 (tested on 8.2, but likely failing in 7.4 as well), I believe caused by #3236.

@MarkBaker
Copy link
Member

This should have been resolved by PR #3311

@adawolfa
Copy link
Author

Confirmed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants