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

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

Closed
danielcherrington opened this issue Aug 1, 2018 · 0 comments

Comments

@danielcherrington
Copy link

danielcherrington commented Aug 1, 2018

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)

Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this issue Nov 20, 2018
…Existing

Rowspans/colspans are now 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`.

Fixes PHPOffice#619
Fixes PHPOffice#620
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

1 participant