PHP_XLSXWriter
PHP_XLSXWriter copied to clipboard
Cache Issue
@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;
@mk-j Please help
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;