require_once 'PHPExcel.php'; // Create a new PHPExcel object $objPHPExcel = new PHPExcel(); // Add a new sheet to the workbook $objPHPExcel->createSheet(); // Save the workbook to a file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('example.xlsx');
require_once 'PHPExcel.php'; // Create a new PHPExcel object $objPHPExcel = new PHPExcel(); // Add a custom-named sheet to the workbook $objPHPExcel->createSheet()->setTitle('New Sheet'); // Save the workbook to a file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('example.xlsx');In this example, we use the setTitle() method to give the new sheet a custom name. The rest of the code is the same as the first example, which saves the workbook to an Excel file using the PHPExcel_IOFactory package library.