PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.37k stars 3.47k forks source link

Hidden Rows in Excel File Saved with PhpSpreadsheet #4235

Open wenpinglee opened 2 days ago

wenpinglee commented 2 days ago

Hello,

I am experiencing an issue with PhpSpreadsheet when saving an Excel file. The problem is that some rows in the saved file are hidden, even though they are not supposed to be.

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

The data is displayed correctly in the Excel sheet.

What is the current behavior?

The rows are all hidden, only the title remains.

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();

// add code that show the issue here...
$templatePath = storage_path('app/public/Sample_Request.xlsx');
$spreadsheet = IOFactory::load($templatePath);

$spreadsheet1 = IOFactory::load($filePath);//copy other excel
$sheet1 = $spreadsheet1->getSheet(0);

$spreadsheet->addSheet($sheet1, 1);
$sheet2 = $spreadsheet->getSheet(1);
for ($k = 1; $k <= 1000; $k++) {
    $sheet2->getRowDimension($k)->setCollapsed(false);
    $sheet2->getRowDimension($k)->setVisible(true);
}
$newFilePath = storage_path('app/public/temp/test.xlsx');
$writer = new Xlsx($spreadsheet);
$writer->save($newFilePath);

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

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

After saving the file, some rows are hidden when I open it in Excel.I don't think this issue is caused by the file($filePath).

Which versions of PhpSpreadsheet and PHP are affected?

phpoffice/phpspreadsheet version 1.29.0 maatwebsite/excel version 3.1.55 laravel version 9.52.16 PHP version 8.0.24

oleibman commented 2 days ago

It is difficult to debug this problem without the file which demonstrates it. Is it possible to upload it? There are other factors affecting visibility besides the RowDimension property. Rows might, for example, be hidden due to an auto-filter, and the RowDimension property will not override that.