Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2.     if (isset($_POST["all"])) {
  3.         $id = $_POST["all"];
  4.     } else {
  5.         $id = "";
  6.     }
  7.  
  8.     use PhpOffice\PhpSpreadsheet\Helper\Sample;
  9.     use PhpOffice\PhpSpreadsheet\IOFactory;
  10.     use PhpOffice\PhpSpreadsheet\Spreadsheet;
  11.  
  12.     $helper = new Sample();
  13.     if ($helper->isCli()) {
  14.         $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
  15.  
  16.         return;
  17.     }
  18.     // Create new Spreadsheet object
  19.     $spreadsheet = new Spreadsheet();
  20.  
  21.     // Set document properties
  22.     $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
  23.         ->setLastModifiedBy('Maarten Balliauw')
  24.         ->setTitle('Office 2007 XLSX Test Document')
  25.         ->setSubject('Office 2007 XLSX Test Document')
  26.         ->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
  27.         ->setKeywords('office 2007 openxml php')
  28.         ->setCategory('Test result file');
  29.  
  30.     // Add some data
  31.     // ( 略 )
  32.  
  33.     // Rename worksheet
  34.     $spreadsheet->getActiveSheet()->setTitle('Simple');
  35.  
  36.     // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  37.     $spreadsheet->setActiveSheetIndex(0);
  38.  
  39.     // Redirect output to a client’s web browser (Xlsx)
  40.     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  41.     header('Content-Disposition: attachment; filename="搜尋匯出-' . $time . '.xlsx"');
  42.     header('Cache-Control: max-age=0');
  43.  
  44.     $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  45.     $writer->save('php://output');
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement