PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 5, 2022

[FIXED] How to delete worksheet in PHPExcel

 October 05, 2022     phpexcel, worksheet     No comments   

Issue

In PHPExcel how can I delete a sheet with the name worksheet?

I have this, but it does not work:

$objWorkSheet->removeSheetByIndex("Worksheet");

Solution

Worksheet is the name of a worksheet, not its index (position within the collection of worksheets). You need to identify its index position and use that as the argument to removeSheetByIndex()

Something like:

$objWorkSheet->setActiveSheetIndexByName('Worksheet');
$sheetIndex = $objWorkSheet->getActiveSheetIndex();
$objWorkSheet->removeSheetByIndex($sheetIndex);

or

$objWorkSheet->removeSheetByIndex(
    $objWorkSheet->getIndex(
        $objWorkSheet->getSheetByName('Worksheet')
    )
);


Answered By - Mark Baker
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing