Advertisement
AlexWebDevelop

Untitled

Mar 8th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. /* Include the Composer autoload (PhpSpreadsheet must be installed via Composer) */
  4. require_once '/path_to_composer/vendor/autoload.php';
  5.  
  6. /* Namespace use */
  7. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  8. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  9.  
  10. /* Create a new Spreadsheet object, for XLS files */
  11. $spreadsheet = new Spreadsheet();
  12.  
  13. /* Select the active sheet */
  14. $sheet = $spreadsheet->getActiveSheet();
  15.  
  16. /* This is how you set cell values */
  17. $sheet->setCellValue('A1', 'Cell A1 content');
  18. $sheet->setCellValue('B1', 'Cell B1 content');
  19. $sheet->setCellValue('A2', 'Cell A2 content');
  20. $sheet->setCellValue('B2', 'Cell B2 content');
  21.  
  22. /* HTTP headers to tell the browser we are sending an XLS file */
  23. header( 'Pragma: public' );
  24. header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
  25. header( 'Content-Type: application/vnd.ms-excel' );
  26. header( 'Content-Transfer-Encoding: binary' );
  27. header( 'Expires: Mon, 1 Apr 1974 05:00:00 GMT' );
  28. header( 'Last-Modified: ' . gmdate( 'D,d M YH:i:s' ) . ' GMT' );
  29.  
  30. /* Create the Xlsx object */
  31. $writer = new Xlsx($spreadsheet);
  32.  
  33. /* Output the XLS file */
  34. $writer->save('php://output');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement