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

ExcelWriter unwanted Worksheet (feature request) #263

Open
stevegroom opened this issue Sep 21, 2015 · 1 comment
Open

ExcelWriter unwanted Worksheet (feature request) #263

stevegroom opened this issue Sep 21, 2015 · 1 comment

Comments

@stevegroom
Copy link

When using the excelWriter class and naming the worksheet:

$writer = new ExcelWriter($file,'Named Sheet');

The resulting Excel file includes an empty worksheet called 'worksheet' to the left of 'Named Sheet'.

In my file explorer, the preview is showing the empty 'worksheet'

Can you expose a method to remove it ? In the phpoffice/phpexcel the function is described:

$sheetIndex = $objPHPExcel->getIndex(
    $objPHPExcel->getSheetByName('Worksheet 1')
);
$objPHPExcel->removeSheetByIndex($sheetIndex);
@fbdnl
Copy link
Contributor

fbdnl commented Oct 14, 2015

The additional worksheet is created automatically in the construct of the PHPExcel class.
The issue can be solved editing the function 'prepare' in the ExcelWriter class.

public function prepare()
    {
        $reader = PHPExcel_IOFactory::createReader($this->type);
        if ($reader->canRead($this->filename)) {
            $this->excel = $reader->load($this->filename);
        } else {
            $this->excel = new PHPExcel();
            /********* Fix start *********/
            if(null !== $this->sheet && !$this->excel->sheetNameExists($this->sheet))
            {
                $this->excel->removeSheetByIndex(0);
            }
            /********* Fix end *********/
        }

        if (null !== $this->sheet) {
            if (!$this->excel->sheetNameExists($this->sheet)) {
                $this->excel->createSheet()->setTitle($this->sheet);
            }
            $this->excel->setActiveSheetIndexByName($this->sheet);
        }

        return $this;
    }

A pull request has been opened: #273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants