PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/act_generate.php

https://gitlab.com/pra34/excel-parse
PHP | 48 lines | 29 code | 11 blank | 8 comment | 0 complexity | 8804970ee1fc8d2a897656ebac30ea71 MD5 | raw file
  1. <?php
  2. include '/PHPExcel/Classes/PHPExcel.php';
  3. include '/PHPExcel/Classes/PHPExcel/IOFactory.php';
  4. $excel = new PHPExcel();
  5. $worksheet = $excel->getActiveSheet();
  6. // Set the column styles as the first thing
  7. // from A1 to D1, for 4 column
  8. $worksheet->getStyle('A1:D1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
  9. $worksheet->getStyle('A1:D1')->getFill()->getStartColor()->setRGB('E0E0E0');
  10. // Some nice styles for the header (ordinary cell styles)
  11. $worksheet->getCell('A1')->setValue($_POST['first_column_name']);
  12. $worksheet->getCell('B1')->setValue($_POST['second_column_name']);
  13. $worksheet->getCell('C1')->setValue($_POST['third_column_name']);
  14. $worksheet->getCell('D1')->setValue($_POST['fourth_column_name']);
  15. // record need to be inserted from second row only
  16. $row = 2;
  17. // Cell data
  18. $worksheet->getCell("A{$row}")->setValue($_POST['first_column_record']);
  19. $worksheet->getCell("B{$row}")->setValue($_POST['second_column_record']);
  20. $excel->getActiveSheet()->getStyle("C{$row}")->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
  21. $worksheet->getCell("C{$row}")->setValue($_POST['third_column_record']);
  22. $excel->getActiveSheet()->getStyle("D{$row}")->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
  23. $worksheet->getCell("D{$row}")->setValue($_POST['fourth_column_record']);
  24. // Redirect output to a client’s web browser (Excel2007)
  25. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  26. header('Content-Disposition: attachment;filename=generated_excel'.date('Ymdhis').'.xls');
  27. header('Cache-Control: max-age=0');
  28. // If you're serving to IE 9, then the following may be needed
  29. header('Cache-Control: max-age=1');
  30. // If you're serving to IE over SSL, then the following may be needed
  31. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  32. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  33. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  34. header ('Pragma: public'); // HTTP/1.0
  35. $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
  36. $writer->save('php://output');
  37. exit;