Skip to content

rowspans/colspans not reset when adding a new worksheet using loadIntoExisting #619

Closed
@danielcherrington

Description

@danielcherrington

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

rowspans/colspans are respected for each HTML document added to an existing spreadsheet as a new worksheet. The protected $rowspan class property should be emptied on each call to "loadIntoExisting"

What is the current behavior?

rowspans/colspans are cached by column reference across the entire spreadsheet meaning additional sheets added to the spreadsheet start at the wrong column index

What are the steps to reproduce?

You will need two html files containing tables with rowspans/colspans defined

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';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$inputFileType = 'Html';

$inputFileNames = [
    "1.html",
    "2.html"
];

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$inputFileName = array_shift($inputFileNames);
$spreadsheet = $reader->load($inputFileName);
$spreadsheet->getActiveSheet()
    ->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));

foreach ($inputFileNames as $sheet => $inputFileName) {
    $reader->setSheetIndex($sheet+1);
    $reader->loadIntoExisting($inputFileName, $spreadsheet);
    $spreadsheet->getActiveSheet()
        ->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
}

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
$writer->save("merged.xlsx");

Which versions of PhpSpreadsheet and PHP are affected?

Latest (1.3.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