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

Reader\Xlsx::setLoadSheetsOnly() has an impact on getPrintArea() #371

Closed
Dfred opened this issue Feb 12, 2018 · 0 comments
Closed

Reader\Xlsx::setLoadSheetsOnly() has an impact on getPrintArea() #371

Dfred opened this issue Feb 12, 2018 · 0 comments

Comments

@Dfred
Copy link

Dfred commented Feb 12, 2018

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?

Both readers should have the same behaviour: getPrintArea() should report expected values regardless of previous call to setLoadSheetsOnly().

What is the current behavior?

Using setLoadSheetsOnly() for the Xlsx reader makes getPrintArea() return print areas of unloaded sheets.

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';
const FILENAME = 'printArea_bug';
const FORMATS  = ['Xls', 'Xlsx'];

# Create new workbook with 3 sheets and different print areas
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$worksheet1 = $spreadsheet->getActiveSheet()->setTitle('W1');
$worksheet1->getPageSetup()->setPrintArea('A1:B1');
for ($i = 2; $i < 5; $i++) {
  $worksheet = $spreadsheet->createSheet()->setTitle("W$i");
  $worksheet->getPageSetup()->setPrintArea("A$i:B$i");
}
# save the file in various formats
foreach (FORMATS as $fileFormat) {
  $writerClass = "\\PhpOffice\\PhpSpreadsheet\\Writer\\$fileFormat";
  $writer = new $writerClass($spreadsheet);
  $path = FILENAME . ".$fileFormat";
  $writer->save($path);                   // the file is as expected with Excel.
}

# Read the same content in Xls and Xlsx formats, showing discrepancy with getPrintArea()
foreach (FORMATS as $fileFormat)
{
  $path = FILENAME . ".$fileFormat";
  $reader = PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($path);

  # load only sheets that name meet our criteria
  $reader->setLoadSheetsOnly(['W1', 'W3']);
  $workbook = $reader->load($path);

  # display print areas
  foreach ($workbook->getWorksheetIterator() as $index => $sheet) {
    echo get_class($reader)." > {$sheet->getTitle()} print area: {$sheet->getPageSetup()->getPrintArea()}\n";
  }
}

Which versions of PhpSpreadsheet and PHP are affected?

branch develop, PHP 5.6

@Dfred Dfred changed the title ReaderXlsx Reader\Xlsx::setLoadSheetsOnly() have an impact on getPrintArea() Feb 12, 2018
@Dfred Dfred changed the title Reader\Xlsx::setLoadSheetsOnly() have an impact on getPrintArea() Reader\Xlsx::setLoadSheetsOnly() has an impact on getPrintArea() Feb 12, 2018
@PowerKiKi PowerKiKi reopened this Feb 12, 2018
Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this issue Nov 20, 2018
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