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

Corrupt file since migrating to 1.3.0 for complex doc when using removeSheet #723

Closed
immobilia opened this issue Oct 17, 2018 · 1 comment · Fixed by #1462
Closed

Corrupt file since migrating to 1.3.0 for complex doc when using removeSheet #723

immobilia opened this issue Oct 17, 2018 · 1 comment · Fixed by #1462
Labels

Comments

@immobilia
Copy link

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?

Open the result .xlsx with Excel without warning (after the document was saved with PhpSpreadsheet)

Classeur_Empty.xlsx
Classeur_Empty.xlsxOUT.xlsx

What is the current behavior?

Open the result .xlsx with Excel ask a confirm notice to open :

Ask :

Microsoft Excel: Sorry ... We found a problem in the contents of "Class_Box - Copy.xlsxOUT.xlsx"
Microsoft Excel : Désolé... Nous avons trouvé un problème dans le contenu de "Classeur_Model - Copie.xlsxOUT.xlsx"

After confirm :

Excel has completed file level validation and repair. Some parts of the workbook may have been repaired or abandoned.
Deleted Part: Print Options.
Deleted part: Drawing form.
Excel a terminé la validation et la réparation de niveau fichier. Certaines parties du classeur peuvent avoir été réparées ou abandonnées.
Partie supprimée: Options d'impression.
Partie supprimée: Forme de dessin.

Classeur_Model.xlsx
Classeur_Model.xlsxOUT.xlsx

What are the steps to reproduce?

  • Updating phpoffice/phpspreadsheet (1.0.0 => 1.2.1)
    OK : no problem

  • Updating phpoffice/phpspreadsheet (1.2.1 => 1.3.0)
    KO : the problem appears

<?php

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

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// $model = __DIR__ . DIRECTORY_SEPARATOR . 'Classeur_Empty.xlsx';
$model = __DIR__ . DIRECTORY_SEPARATOR . 'Classeur_Model.xlsx';

$fileOut = $model . 'OUT.xlsx';

$spreadsheet = IOFactory::load($model);

$worksheet = $spreadsheet->setActiveSheetIndex(2);
$worksheet->setTitle('Mesures Avant');

$worksheet = $spreadsheet->setActiveSheetIndexByName('Mesures Avant');
$sheetIndex = $spreadsheet->getIndex($spreadsheet->getSheetByName('Mesures Avant'));
$spreadsheet->removeSheetByIndex($sheetIndex);	// without this removing, the output document is clean

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($fileOut);

// now try to open "Classeur_Model - Copie.xlsxOUT.xlsx" with Excel

Which versions of PhpSpreadsheet and PHP are affected?

All PhpSpreadsheet versions since 1.3.0 are affected.
(Used PHP Version 7.1.22)

@stale
Copy link

stale bot commented Dec 16, 2018

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 Dec 16, 2018
@stale stale bot closed this as completed Dec 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant