Skip to content

Commit

Permalink
Issue #533: Fix bug with phpspreadsheet creating default worksheet
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislaick committed Feb 4, 2025
1 parent 74f730a commit 6a2455f
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\node\NodeInterface;
use Drupal\path_alias\AliasManagerInterface;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Writer\Csv;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -121,16 +120,12 @@ public function createFile(NodeInterface $node, string $format): BinaryFileRespo
// with stream wrappers.
$file_path = $this->fileSystem->getTempDirectory() . '/' . $filename;

// Generate the spreadsheet object and save to $file_path.
$spreadsheet = new Spreadsheet();
$worksheets = new Worksheet($spreadsheet);
$spreadsheet->addSheet($worksheets);
$worksheets->fromArray($results);
// Remove first blank worksheet.
$sheetIndex = $spreadsheet->getIndex(
$spreadsheet->getSheetByName('Worksheet')
);
$spreadsheet->removeSheetByIndex($sheetIndex);
// Get default sheet.
$worksheet = $spreadsheet->getActiveSheet();
// Rename it to avoid conflicts.
$worksheet->setTitle('Data');
$worksheet->fromArray($results);

switch ($format) {
case 'xlsx':
Expand Down

0 comments on commit 6a2455f

Please sign in to comment.