Skip to content

The bug of transferring the list formula when inserting rows with the xlsx format #3056

Closed
@ShinkarenkoMaksim

Description

This is:

- [+ ] 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?

When inserting n rows, the cells with the contents (including formulas and styles) should move correctly n rows below

What is the current behavior?

When inserting n rows of the cell with the contents of the "DropDownList formula" remains on the same row. Also, when trying to install dropDownCell on any row below the inserted cells, the insertion occurs on the incorrect row

What are the steps to reproduce?

Execute the attached code

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

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

use PhpOffice\PhpSpreadsheet\IOFactory;

$xlsx = IOFactory::load('Template.xlsx');
$xlsx->setActiveSheetIndex(0);
$sheet = $xlsx->getActiveSheet();

$sheet->insertNewRowBefore(5, 2);

$validation = $sheet->getCell('A8')->getDataValidation();
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST);
$validation->setFormula1('F1:F3');

$writer = IOFactory::createWriter($xlsx, 'Xlsx');
$writer->save('Result.xlsx');

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Xlsx - affected, xls works fine

Which versions of PhpSpreadsheet and PHP are affected?

checked for php81 & php80, spreadsheet 1.24.1 (can confirm this bug at least from version 1.20, on version 1.18 bug doesn't manifest)
Result.xlsx
Template.xlsx

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions