Copy Code code as follows:
Template Storage Directory
$dir = $DOCUMENT _root. ' /backoffice/admin/oemcheck/';
$templateName = ' 1.xlsx ';
$outputFileName = ' template. xlsx ';
$txt = ' Test ';
Instantiate Excel Read class
$PHPReader = new phpexcel_reader_excel2007 ();
if (! $PHPReader->canread ($dir. $templateName)) {
$PHPReader = new Phpexcel_reader_excel5 ();
if (! $PHPReader->canread ($dir. $templateName)) {
echo ' Unrecognized Excel file! ';
return false;
}
}
Reading Excel
$PHPExcel = $PHPReader->load ($dir. $templateName);
reading worksheet 1
$currentSheet = $PHPExcel->getsheet (0);
$currentSheet->setcellvalue (' B13 ', iconv (' GBK ', ' utf-8 ', $txt));//table header assignment//
Instantiate Excel Write Class
$PHPWriter = new phpexcel_writer_excel2007 ($PHPExcel);
Ob_start ();
Header ("Content-type:application/force-download");
Header ("Content-type:application/octet-stream");
Header ("Content-type:application/download");
Header (' Content-disposition:attachment;filename= '. $outputFileName. ' "');//Output template name
Header ("Content-transfer-encoding:binary");
Header ("last-modified:". Gmdate ("D, D M Y h:i:s"). " GMT ");
Header (' Pragma:public ');
Header (' expires:30 ');
Header (' Cache-control:public ');
$PHPWriter->save (' php://output ');