PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Sheet cloning is time consuming
This is:
- [х] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
What is the expected behavior?
Every time I clone a sheet it should take the same amount of time.
What is the current behavior?
Every new clone is more time consuming. In the example below echo starts from 0.1528263092041 and ends near 7.2238445281982 If template has much more data, then it can ends even at 113.48509788513 in 200th sheet
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
require __DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$template = $spreadsheet->getActiveSheet();
$template->setCellValue('A1', 'some big data and styles');
$template->getStyle('A1:A5')->getFont()->setBold(true);
for ($i = 0; $i < 1000; $i++) {
$t1 = microtime(true);
$cloned = clone $template;
$cloned->setTitle('Sheet ' . $i);
$t2 = microtime(true);
echo ($t2 - $t1) * 1000 . "\n";
$sheet = $spreadsheet->addSheet($cloned);
$sheet->setCellValue('A4', 'unique per sheet data');
}
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
- [ ] Formula Calculations
- [ ] Charts
- [ ] AutoFilter
- [ ] Form Elements
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Which versions of PhpSpreadsheet and PHP are affected?
I tested on PhpSpreadsheet v1.25 and v2.0.0 PHP v8.1