I am using PHPExcel
to generate an xl using php. I am not loading an xl sheet but creating new sheets using
$phpExcel = new PHPExcel();
$phpExcel->getActiveSheet()->setTitle("My Sheet");
I want to set active sheet using phpExcel using $phpExcel->setActiveSheetIndexByName("2");
but im getting an error setActiveSheetIndexByName not defined function.
Please help
You shouldn't need
ByName
. Try justsetActiveSheetIndex(2);
.Add below function into Excel.php class file:
then call that function like this :
If you are directly manipulating the xml in workbook.xml
You do, of course, need to create/add additional worksheets to be able to change the active sheet: using new PHPExcel() will only create a workbook containing a single sheet.
You can set the active sheet using either the sheet index (sheets are indexed from 0);
or by name
Adding a new sheet using either the createSheet() or addSheet() methods will automatically set that new worksheet to the active worksheet. By default, any new worksheet will be given a name comprising the word "Worksheet" and a number until you use setTitle() to change it.