如何在不加載xlsx文件的情況下設置活動表?

[英]How to set active sheet without loading an xlsx file?


I am using PHPExcel to generate an xl using php. I am not loading an xl sheet but creating new sheets using

我正在使用PHPExcel生成一個使用php的xl。我不是在加載xl表格,而是使用

$phpExcel = new PHPExcel();
$phpExcel->getActiveSheet()->setTitle("My Sheet");

I want to set active sheet using phpExcel using $phpExcel->setActiveSheetIndexByName("2");

我想使用phpExcel使用$phpExcel->setActiveSheetIndexByName(“2”)設置活動表;

but im getting an error setActiveSheetIndexByName not defined function.

但是我得到一個錯誤setactivesetindexbyname未定義函數。

Please help

請幫助

3 个解决方案

#1


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.

當然,您需要創建/添加額外的工作表才能更改活動表:使用新的PHPExcel()只會創建包含單個工作表的工作簿。

You can set the active sheet using either the sheet index (sheets are indexed from 0);

您可以使用表索引來設置活動表(表從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.

使用createSheet()或addSheet()方法添加新工作表將自動將新工作表設置為活動工作表。默認情況下,任何新的工作表都將被賦予一個包含單詞“工作表”和一個數字的名稱,直到您使用setTitle()來更改它為止。

#2


4  

Add below function into Excel.php class file:

將下面的函數添加到Excel中。php類文件:

function setActiveSheet($sheetnumber) {
        $this->objPHPExcel->setActiveSheetIndex($sheetnumber);
    }

then call that function like this :

然后像這樣調用這個函數:

$phpExcel->setActiveSheet(0);

#3


0  

You shouldn't need ByName. Try just setActiveSheetIndex(2);.

你不應該需要別名。試只是setActiveSheetIndex(2);。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/08/16/725949b805abea23c05835211a993370.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com