testgen/export.php

20 lines
644 B
PHP
Raw Permalink Normal View History

2017-10-25 19:36:45 +00:00
<?php
require_once __DIR__ . "/vendor/autoload.php";
2017-10-25 19:50:27 +00:00
if (empty($_POST["test_cases"])) {
header("Location: /~ben/testgen/");
die();
}
2017-10-25 19:36:45 +00:00
// split input by line and place into template at cell B2
2017-10-25 19:36:45 +00:00
$cases = explode("\n", $_POST["test_cases"]);
$excel = PHPExcel_IOFactory::load("template.xlsx");
$excel->getActiveSheet()->fromArray(array_chunk($cases, 1), NULL, 'B2');
2017-10-25 19:36:45 +00:00
2017-10-25 19:50:27 +00:00
// set the right download headers
2017-10-25 19:36:45 +00:00
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="testcase-template.xls"');
header('Cache-Control: max-age=0');
PHPExcel_IOFactory::createWriter($excel, 'Excel5')->save('php://output');