$row_id++;
        }
    }
    // create new sheet
    $objPHPExcel->createSheet(NULL, $sheetId);
    // Rename worksheet
    $question_number = $sheetId + 1;
    $objPHPExcel->getActiveSheet()->setTitle("Group" . $sheetId);
    // increase sheet id
    $sheetId++;
}
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $question->getTitle() . '.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// always modified
header('Cache-Control: cache, must-revalidate');
// HTTP/1.1
header('Pragma: public');
// HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
Example #2
0
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/Sofia');
if (PHP_SAPI == 'cli') {
    die('This example should only be run from a Web Browser');
}
/** Include PHPExcel */
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("SU Survey")->setLastModifiedBy("SU Survey")->setTitle("SU Survey - Question report")->setSubject("SU Survey - Question report")->setDescription("SU Survey - Question report")->setKeywords("Sofia University,Survey,Question,System,Results")->setCategory("Question Report");
// set sheet id
$sheetId = 0;
$objPHPExcel->setActiveSheetIndex($sheetId)->mergeCells('A1:N1');
$objPHPExcel->setActiveSheetIndex($sheetId)->setCellValue('A1', $question->getTitle());
// spread answers throught columns
function divideBy26($numberColumns)
{
    global $alphas;
    if ($numberColumns > 0) {
        $reminder = $numberColumns % 26;
        if ($reminder != 0) {
            $reminderChar = $alphas[$reminder];
            $floor = floor($numberColumns / 26);
        } else {
            $reminder = 26;
            $reminderChar = $alphas[$reminder];
            $floor = floor($numberColumns / 26);
            $floor--;
        }