如何在不加载xlsx文件的情况下设置活动工作表? [英] How to set active sheet without loading an xlsx file?

查看:90
本文介绍了如何在不加载xlsx文件的情况下设置活动工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆