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

Error when passing blank string as sheetname #3910

Closed
1 of 8 tasks
xiaopig1234 opened this issue Feb 20, 2024 · 2 comments
Closed
1 of 8 tasks

Error when passing blank string as sheetname #3910

xiaopig1234 opened this issue Feb 20, 2024 · 2 comments

Comments

@xiaopig1234
Copy link

This is:

- [x] a bug report

What is the expected behavior?

The xls success output

What is the current behavior?

PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort(): Argument #1 ($textValue) must be of type string, null given, called in /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xls/Workbook.php on line 482

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...
$sheetname = ""; //pass in blank as sheetname cause the issue
$table1worksheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet,$sheetname);
$spreadsheet->addSheet($table1worksheet,0);
$sheetIndex = $spreadsheet->getIndex($spreadsheet->getSheetByName('Worksheet'));
$spreadsheet->removeSheetByIndex($sheetIndex);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls($spreadsheet,'XLS');
$writer->save("php://output");exit();

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

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

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

Haven't tested, but confirmed that xls are affected.

Which versions of PhpSpreadsheet and PHP are affected?

"phpoffice/phpspreadsheet": "^1.18",php8.1

@oleibman
Copy link
Collaborator

It seems clear that this is a user error. Furthermore, although I can duplicate your result with 1.18.0, we are now many releases past that (we are on 2.0, which followed 1.29.0). With the current release, I ran your code, and saved an xls without problem. I get an error when Excel tries to open the spreadsheet (invalid sheet name), which seems perfectly reasonable. It is arguable whether we are better off throwing an exception rather than producing an unusable spreadsheet, but that is the opposite of this problem. If you want to restore having an exception when we try to write out a spreadsheet to which the user has assigned an invalid title, please open a new issue, and we can discuss that possibility there. For now, I am closing this ticket.

@xiaopig1234
Copy link
Author

Sorry i give a wrong info on the phpspreadsheet version that i used. The correct version that i use is
phpoffice/phpspreadsheet 1.29.0
i will update to version 2.0 and tryout

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