如何在不加载xlsx文件的情况下设置活动工作表? [英] How to set active sheet without loading an xlsx file?
问题描述
我正在使用PHPExcel
使用php生成xl.我不是在加载xl工作表,而是使用
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");
我想使用$phpExcel->setActiveSheetIndexByName("2");
但我收到错误setActiveSheetIndexByName not defined function.
请帮助
推荐答案
当然,您需要创建/添加其他工作表才能更改活动表:使用新的PHPExcel()只会创建一个包含以下内容的工作簿一张纸.
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.
您可以使用工作表索引(工作表从0开始索引)来设置活动工作表;
You can set the active sheet using either the sheet index (sheets are indexed from 0);
$objPHPExcel->setActiveSheetIndex(2);
或按名称
$objPHPExcel->setActiveSheetIndexByName('My Second Sheet');
使用createSheet()或addSheet()方法添加新工作表将自动将该新工作表设置为活动工作表.默认情况下,在使用setTitle()进行更改之前,所有新工作表都将被赋予一个名称,该名称包含单词"Worksheet"和一个数字.
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.
这篇关于如何在不加载xlsx文件的情况下设置活动工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!