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

Unnecessarily enforces maximum of 31 characters in sheet titles #176

Closed
2 of 3 tasks
MikkelPaulson opened this issue Jun 14, 2017 · 3 comments
Closed
2 of 3 tasks
Labels

Comments

@MikkelPaulson
Copy link
Contributor

MikkelPaulson commented Jun 14, 2017

This is:

Summary

XLSX files (at the very least) support sheet titles over 31 characters, but PhpSpreadsheet enforces a 31-character limit regardless of file format. This would be annoying if it only affected sheet creation, but the validation code is also run on load. This means that PhpSpreadsheet is unable to load any valid XLSX file (or file of any other format) containing a sheet with a name over 32 characters.

What is the expected behavior?

A worksheet title containing 32 characters is set correctly. An exception should only be thrown when saving to a format that doesn't support longer titles.

What is the current behavior?

An exception is thrown with the message "Maximum 31 characters allowed in sheet code name.".

What are the steps to reproduce?

(Shows creating a new file, but the same behaviour is encountered when loading an existing file with a sheet title over 31 chars.)

<?php

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

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getSheet();
$sheet->setTitle('ten chars ten chars ten chars +2');

Which versions of PhpSpreadsheet and PHP are affected?

PHPExcel 1.8, PhpSpreadsheet develop

@PowerKiKi
Copy link
Member

Thanks for this contribution of quality. Would you be able to find official specs for a few formats about sheet title length ? I'd say at least XLSX and ODS would be nice

@MikkelPaulson
Copy link
Contributor Author

Reviewing the ODS spec, the relevant XML property is table:name. It specifies the data type as "string" without additional constraints. Obviously applications will impose their own limits in terms of what they'll render, but LibreOffice happily opened a file containing an entire paragraph of lorem ipsum.

screen shot 2017-06-14 at 20 33 46

@PowerKiKi
Copy link
Member

See #177 (comment)

PowerKiKi pushed a commit that referenced this issue Jul 14, 2017
Add option to suppress validation of sheet titles

Based on a "lowest common denominator" approach to compatibility,
we will continue to enforce a 31-character limit for sheet titles.
However, this limit should not be enforced when loading an existing
file.

Added a new optional parameter to Worksheet::setTitle() and
Worksheet::setCodeName() to suppress validation and massaging,
based on the premise that existing files should be given a
best-effort approach to loading and parsing. Unfortunately, it's
not possible with the current architecture to prevent users from
making use of this functionality, aside from with a strongly-worded
warning.

Added test coverage. I didn't see any existing unit tests of the
Worksheet class, so I created a new test to cover these methods.

Fixes #176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants