Skip to content
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

File corrupted when copy worksheet and performance issue #1554

Closed
polppol opened this issue Jun 27, 2020 · 3 comments
Closed

File corrupted when copy worksheet and performance issue #1554

polppol opened this issue Jun 27, 2020 · 3 comments

Comments

@polppol
Copy link

polppol commented Jun 27, 2020

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?

On v. 1.9.0 Script run just fine and process time is < 2 sec.
Script load
input.xlsx

and copy Sheet1 to COPY_SHEET
return Excel file with 2 worksheet
output_1.9.0.xlsx

What is the current behavior?

Script takes very long time to process (>10 sec)
and output corrupted Excel file
output_1.13.0.xlsx

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_once (__DIR__ .'/../vendor/autoload.php');

use PhpOffice\PhpSpreadsheet\IOFactory;

$objReader = IOFactory::createReader('Xlsx');
$objPHPExcel = $objReader->load("input.xlsx");
$fileTitle = "TEST";


$sheet = $objPHPExcel->setActiveSheetIndex(0);

$copySheet = $sheet->copy();
$copySheet->setTitle("COPY_SHEET");
$objPHPExcel->addSheet($copySheet);

$sheet = $objPHPExcel->setActiveSheetIndex(0);
$memory_get_peak_usage = (memory_get_peak_usage(true) / 1024 / 1024);
$outFileName = $fileTitle."_".date("Y-m-d").".xlsx";

//////////////////////////////////////////////////////////
// Redirect output to a client’s web browser (Excel2007)
//////////////////////////////////////////////////////////

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename=\"$outFileName\"");
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = IOFactory::createWriter($objPHPExcel, 'Xlsx');
$objWriter->setPreCalculateFormulas(true);
$objWriter->save('php://output');

exit;

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet : 1.13.0
(Last known working version is 1.9.0)
PHP : 7.3.19

@polppol
Copy link
Author

polppol commented Jun 27, 2020

Just found that maybe Duplicate of #1483

But I also have a issue with performance

@polppol polppol changed the title File corrupted when copy worksheet File corrupted when copy worksheet and performance issue Jun 27, 2020
@stale
Copy link

stale bot commented Aug 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Aug 29, 2020
@stale stale bot closed this as completed Sep 5, 2020
@oleibman
Copy link
Collaborator

Supplied code used with supplied spreadsheet now seems to work correctly.

@oleibman oleibman removed the stale label Jul 13, 2024
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