Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To add Worksheet to a new Excel file using Aspose.Cells Java for PHP, simply call add_worksheet method of MangingWorksheets module.
PHP Code
//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");
To remove worksheet by sheet name using Aspose.Cells Java for PHP, simply call remove_worksheet_by_name method of MangingWorksheets module.
PHP Code
//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();
To remove worksheet by sheet index using Aspose.Cells Java for PHP, simply call remove_worksheet_by_index method of MangingWorksheets module.
PHP Code
//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();
Download Managing Worksheets (Aspose.Cells) from any of the below mentioned social coding sites:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.