skip to Main Content

Testing online phpspreadsheet

use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;

class ReportExport extends CI_Controller
{
    public function download()
    {
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $sheet->setCellValue('A1', 'Hello World !');

        $writer = new Xlsx($spreadsheet);

        $filename = 'robert';

        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="'. $filename .'.xlsx"'); 
        header('Cache-Control: max-age=0');

        $writer->save('php://output'); // download file 
     }
}

I have tried to run that function in codeigniter and i get that response from the browser that File not Found (on the online server) yet when i run it offline(on localhost/) it returns the excel file that i have created.

Please any ideas i can use to fix the error!

I am using php version 7.3.14 on the online server.

2

Answers


  1. Save as file in a deticates Folder on Server

    //Path to the file on Server, eg /var/www/website/folder/name.xlsx
    $PATH = <PATH>;
    $writer->save($PATH);
    
    Login or Signup to reply.
  2. Firstly, I hope you already resolved this issue.

    If not, I was getting a similar message, as the online server did not have the ea-php73-php-zip extension installed and it was silently throwing a "PhpSpreadSheet Class ZipArchive not found" error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search