Submission_Export_XLS::generate_export_from_data( array $columns, array $rows, awsmug\Torro_Forms\DB_Objects\Forms\Form $form )

Generates the actual export from given data.

Description

Parameters

$columns

(array) (Required) Associative columns array of $column_slug => $column_label pairs.

$rows

(array) (Required) Rows array where each row is an associative array of $column_slug => $column_value pairs.

$form

(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form for which submissions are being exported.

Source

File: src/components/submission-export-xls.php

	protected function generate_export_from_data( $columns, $rows, $form ) {
		$filename = sanitize_title( $form->title ) . '.xls';

		header( 'Content-Type: application/vnd.ms-excel' );
		header( 'Content-Disposition: attachment;filename="' . $filename . '"' );
		header( 'Cache-Control: max-age=0' );
		header( 'Cache-Control: max-age=1' ); // For IE9.
		header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
		header( 'Last-Modified: ' . gmdate('D, d M Y H:i:s' ) . ' GMT' );
		header( 'Cache-Control: cache, must-revalidate' ); // For HTTP 1.1.
		header( 'Pragma: public'); // For HTTP 1.0.

		$php_excel = new \PHPExcel();

		$php_excel->setActiveSheetIndex( 0 );

		$i = 0;
		foreach ( $columns as $slug => $label ) {
			$php_excel->getActiveSheet()->setCellValueByColumnAndRow( $i, 1, $label );
			$i++;
		}

		$php_excel->getActiveSheet()->fromArray( $rows, null, 'A2' );

		$writer = \PHPExcel_IOFactory::createWriter( $php_excel, 'Excel5' );
		$writer->save( 'php://output' );
		exit;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.