Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Include the Composer autoload (PhpSpreadsheet must be installed via Composer) */
- require_once '/path_to_composer/vendor/autoload.php';
- /* Namespace use */
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- /* Create a new Spreadsheet object, for XLS files */
- $spreadsheet = new Spreadsheet();
- /* Select the active sheet */
- $sheet = $spreadsheet->getActiveSheet();
- /* This is how you set cell values */
- $sheet->setCellValue('A1', 'Cell A1 content');
- $sheet->setCellValue('B1', 'Cell B1 content');
- $sheet->setCellValue('A2', 'Cell A2 content');
- $sheet->setCellValue('B2', 'Cell B2 content');
- /* HTTP headers to tell the browser we are sending an XLS file */
- header( 'Pragma: public' );
- header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
- header( 'Content-Type: application/vnd.ms-excel' );
- header( 'Content-Transfer-Encoding: binary' );
- header( 'Expires: Mon, 1 Apr 1974 05:00:00 GMT' );
- header( 'Last-Modified: ' . gmdate( 'D,d M YH:i:s' ) . ' GMT' );
- /* Create the Xlsx object */
- $writer = new Xlsx($spreadsheet);
- /* Output the XLS file */
- $writer->save('php://output');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement