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

XLSX writer: code names are not always respected #1357

Closed
kgilden opened this issue Feb 11, 2020 · 1 comment
Closed

XLSX writer: code names are not always respected #1357

kgilden opened this issue Feb 11, 2020 · 1 comment

Comments

@kgilden
Copy link

kgilden commented Feb 11, 2020

This is:

- [ ] a bug report
- [x] 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?

If a spreadsheet has worksheets with a code names, then code names are respected and written to the generated file.

What is the current behavior?

Code names are not written to the generated file unless the spreadsheet has any macros.

What are the steps to reproduce?

<?php

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

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$spreadsheet->getActiveSheet()->setCodeName($expected = 'foo');

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($path = tempnam(sys_get_temp_dir(), 'example'));

$reader = PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');

$actual = $reader
    ->load($path)
    ->getActiveSheet()
    ->getCodeName()
;

if ($actual !== $expected) {
    printf("Expected code name of active sheet to be 'foo', got '%s'.\n", $actual);
    exit(1);
}

Which versions of PhpSpreadsheet and PHP are affected?

  • PHP: any version
  • PhpSpreadsheet: 1.10.1

Dear maintainer, would you consider always setting the code name regardless of whether macros exist in the spreadsheet or not? Currently this block controls whether or not to add code names to the generated file. I would propose removing the if-guard so that code names would always be written.

The specific use case I have is to provide the user with a template, which they could fill and then submit back to the same system. Using code names would make the template more flexible and resistant to changes to worksheet names (i.e. downloading a template in one locale & submitting it back in a different one).

Would you accept such a contribution, if I made a PR? Any implementation gotcha-s (i.e. other formats etc.)?

Thanks,
Kristen

kgilden added a commit to kgilden/PhpSpreadsheet that referenced this issue Feb 11, 2020
Previously the XLSX writer would only add code names to worksheets, if
the spreadsheet had any macros. However, sometimes code names are useful
on their own.
kgilden added a commit to kgilden/PhpSpreadsheet that referenced this issue Feb 11, 2020
Previously the XLSX writer would only add code names to worksheets, if
the spreadsheet had any macros. However, sometimes code names are useful
on their own.
@kgilden
Copy link
Author

kgilden commented Feb 11, 2020

Ok, discard that. Looks like most tools out in the wild don't respect code names either so there's really no point to encourage using code names for this use case. Closing the PR.

@kgilden kgilden closed this as completed Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant