Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixed] Excel Export #266

Open
geo782 opened this issue Aug 13, 2018 · 0 comments
Open

[Fixed] Excel Export #266

geo782 opened this issue Aug 13, 2018 · 0 comments

Comments

@geo782
Copy link

geo782 commented Aug 13, 2018

Hi,
Im sharing my solution to make excel export to work, as i was getting a white screen. For fixing this im using phpspreadsheet, phpexcel is abandoned.

  1. cd folderofphpreportscript
  2. composer require phpoffice/phpspreadsheet
  3. cd classes/report_formats/
    -----Where the old files for excel exist
  4. /var/www/html/ticket/phpreport/vendor/phpoffice/phpspreadsheet/bin/migrate-from-phpexcel
    -----Run the script to change old phpexcel commands to phpspreadsheet's commands
    If succesfull, you will get the following lines :
/var/www/html/ticket/phpreport/classes/report_formats/XlsReportBase.php converted
/var/www/html/ticket/phpreport/classes/report_formats/XlsReportFormat.php converted
/var/www/html/ticket/phpreport/classes/report_formats/XlsxReportFormat.php converted
  1. Make sure that XlsxReportFormat.php in classes/report_formats/ is like :
<?php
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class XlsxReportFormat extends XlsReportBase {
	public static function display(&$report, &$request) {
		// First let set up some headers
		$spreadsheet = new Spreadsheet();
		$file_name = preg_replace(array('/[\s]+/','/[^0-9a-zA-Z\-_\.]/'),array('_',''),$report->options['Name']);
		//always use cache for Excel reports
		$report->use_cache = true;
		//run the report
		$report->run();
		if(!$report->options['DataSets']) return;
		$objPHPExcel = parent::getExcelRepresantation($report);
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="'.$file_name.'.xlsx"');
		header('Pragma: public');
		header('Expires: 0');
		$objWriter = IOFactory::createWriter($objPHPExcel, 'Xlsx');
		$objWriter->save('php://output');
	}
}
schtritoff added a commit to schtritoff/php-reports that referenced this issue Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant