mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

Cache Issue #294

Closed yogeshsaroya closed 1 year ago

yogeshsaroya commented 3 years ago

@mk-j

Hi I am using this code but its using cache. how to fix cache ?

// $arr - records 
            include_once("xlsxwriter.class.php");
            $writer = new XLSXWriter();
            $writer->setTempDir("/tmp");
            $header = ['Product ID'=>'integer', 'Brand'=>'string','Product name'=>'@'];
            $w = [];
            for ( $i = 1; $i <= count($header); $i++ ){ $w[]= 30; }
            $writer->writeSheetHeader('Sheet1', $header,['widths'=>$w,'font'=>'Heebo','font-size'=>9,'font-style'=>'bold', 'fill'=>'#eee', 'halign'=>'center', 'border'=>'left,right,top,bottom','freeze_rows'=>1] );
            foreach($arr as $row){ $writer->writeSheetRow('Sheet1', $row, ['font'=>'Heebo','font-size'=>9,'halign'=>'center','collapsed'=>true]); }
            $filename = "products.xlsx";
            header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
            header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            header('Content-Transfer-Encoding: binary');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            $writer->writeToStdOut();
            exit;
yogeshsaroya commented 3 years ago

@mk-j Please help

uhlyarikp commented 3 years ago

Hi yogeshsaroya!

I use this code and it works fine

$filecontent=$writer->writeToString();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.XLSXWriter::sanitize_filename($filename).'');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($filecontent));
echo $filecontent;
exit;