How to set active sheet without loading an xlsx file?

前端 未结 4 734
执笔经年
执笔经年 2021-02-09 15:48

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-&g         


        
4条回答
  •  长发绾君心
    2021-02-09 16:19

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

    $objPHPExcel->setActiveSheetIndex(2);
    

    or by name

    $objPHPExcel->setActiveSheetIndexByName('My Second Sheet');
    

    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.

提交回复
热议问题