Copy code The code is as follows:
//Template storage directory
$dir = $DOCUMENT_ROOT.'/backoffice/ admin/oemcheck/';
$templateName = '1.xlsx';
$outputFileName = 'template.xlsx';
$txt='test';
/ /Instantiate Excel reading 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;
}
}
//Read Excel
$PHPExcel = $PHPReader->load($dir.$templateName);
//Read Get worksheet 1
$currentSheet = $PHPExcel->getSheet(0);
$currentSheet->setCellValue('B13',iconv('gbk','utf-8',$ txt));//Header assignment//
//Instantial Excel writing 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');
http://www.bkjia.com/PHPjc/736841.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736841.htmlTechArticleCopy the code as follows: //Template storage directory $dir = $DOCUMENT_ROOT.'/backoffice/admin/oemcheck/ '; $templateName = '1.xlsx'; $outputFileName = 'template.xlsx'; $txt='test'; //Instantiation...