// Create a PHPExcel object $objPHPExcel = new PHPExcel(); // Set some data $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->setCellValue('B1', 'World!'); // Create a CSV writer instance $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV'); // Save the file $objWriter->save('myfile.csv');
// Create a PHPExcel object $objPHPExcel = new PHPExcel(); // Set some data $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->setCellValue('B1', 'World!'); // Create an Excel2007 writer instance $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); // Save the file $objWriter->save('myfile.xlsx');In these examples, `createWriter` is used to create a writer instance for CSV and Excel files respectively. The function takes two arguments: the PHPExcel object containing the data to be written, and the file type to be written (specified as a string). The resulting `$objWriter` instance is then used to save the file to disk. Overall, `createWriter` is a powerful function in the PHPExcel library that enables the creation of spreadsheet files in a wide range of formats.