$file = 'example.xlsx'; $reader = \PHPExcel_IOFactory::createReaderForFile($file); $objPHPExcel = $reader->load($file); $sheet = $objPHPExcel->getActiveSheet(); $rows = $sheet->toArray();
$data = array( array('Name', 'Email', 'Phone'), array('John', 'john@example.com', '1234567890'), array('Jane', 'jane@example.com', '9876543210'), ); $file = 'example.csv'; $writer = \PHPExcel_IOFactory::createWriter(new \PHPExcel(), 'CSV'); $writer->setDelimiter(','); $writer->setEnclosure('"'); $writer->setLineEnding("\r\n"); $writer->setSheetIndex(0); $writer->getActiveSheet()->fromArray($data, null, 'A1'); $writer->save($file);PHPExcel_IOFactory is part of the PHPExcel package library, which is no longer actively maintained. Users are encouraged to migrate to alternative libraries such as PhpSpreadsheet, which is a fork of PHPExcel with active development.