Skip to content

Duplicating worksheet is not copying styling #2494

@vce-wabbott

Description

@vce-wabbott

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?

Expecting a worksheet to be fully duplicated using this code

$clonedWorksheet = clone $spreadsheet->getSheetByName('Worksheet 1');
$clonedWorksheet->setTitle('Copy of Worksheet 1');
$spreadsheet->addSheet($clonedWorksheet);

What is the current behavior?

Some cell styles like fills and font colors are not copied over

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
	$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
	$spreadsheet = $reader->load('Elevation.xlsx');

	$new_elevation = clone $spreadsheet->getActiveSheet();
	$new_elevation->setTitle('Max Potential');
	$spreadsheet->addSheet($new_elevation);

	$spreadsheet->setActiveSheetIndexByName('Max Potential');

	$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
	$writer->save('php://output');

Which versions of PhpSpreadsheet and PHP are affected?

1.21
Elevation.xlsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions