在 Php 中管理工作表

Aspose.Cells - 管理工作表

将工作表添加到新的 Excel 文件

使用以下方法将工作表添加到新的 Excel 文件Aspose.Cells Java for PHP 只需调用添加工作表的方法管理工作表模块。

PHP代码

 //Instantiating a Workbook object

$workbook = new Workbook();

//Adding a new worksheet to the Workbook object

$worksheets = $workbook->getWorksheets();

$sheetIndex = $worksheets->add();

$worksheet = $worksheets->get($sheetIndex);

//Setting the name of the newly added worksheet

$worksheet->setName("My Worksheet");

//Saving the Excel file

$workbook->save($dataDir . "book.out.xls");

使用工作表名称删除工作表

要使用工作表名称删除工作表Aspose.Cells Java for PHP 只需调用按名称删除工作表的方法管理工作表模块。

PHP代码

 //Creating a file stream containing the Excel file to be opened

$fstream = new FileInputStream($dataDir . "book.xls");

//Instantiating a Workbook object with the stream

$workbook = new Workbook($fstream);

//Removing a worksheet using its sheet name

$workbook->getWorksheets()->removeAt("Sheet1");

//Saving the Excel file

$workbook->save($dataDir . "book.out.xls");

//Closing the file stream to free all resources

$fstream->close();

使用工作表索引删除工作表

要按工作表索引删除工作表,请使用Aspose.Cells Java for PHP 只需调用按索引删除工作表的方法管理工作表模块。

PHP代码

 //Creating a file stream containing the Excel file to be opened

$fstream=new FileInputStream($dataDir . "book.xls");

//Instantiating a Workbook object with the stream

$workbook = new Workbook($fstream);

//Removing a worksheet using its sheet index

$workbook->getWorksheets()->removeAt(0);

//Saving the Excel file

$workbook->save($dataDir . "book.out.xls");

//Closing the file stream to free all resources

$fstream->close();

下载运行代码

下载**管理工作表 (Aspose.Cells)**来自以下任何社交编码网站: