PHP_XLSXWriter icon indicating copy to clipboard operation
PHP_XLSXWriter copied to clipboard

Cache Issue

Open yogeshsaroya opened this issue 4 years ago • 2 comments

@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 avatar Oct 19 '20 10:10 yogeshsaroya

@mk-j Please help

yogeshsaroya avatar Oct 20 '20 10:10 yogeshsaroya

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;

uhlyarikp avatar Nov 30 '20 10:11 uhlyarikp