Skip to content

Error when passing blank string as sheetname #3910

@xiaopig1234

Description

@xiaopig1234

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions