|
//模板存放目錄
$dir = $DOCUMENT_ROOT.'/backoffice/admin/oemcheck/';
$templateName = '1.xlsx';
$outputFileName = '模板.xlsx';
$txt='test';
//實例化Excel讀取類
$phpReader = new phpExcel_Reader_Excel2007();
if(!$phpReader->canRead($dir.$templateName)){
$phpReader = new phpExcel_Reader_Excel5();
if(!$phpReader->canRead($dir.$templateName)){
echo '無法識別的Excel文件!';
return false;
}
}
//讀取Excel
$phpExcel = $phpReader->load($dir.$templateName);
//讀取工作表1
$currentSheet = $phpExcel->getSheet(0);
$currentSheet->setCellValue('B13',iconv('gbk','utf-8',$txt));//表頭賦值//
//實例化Excel寫入類
$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. '"');//輸出模板名稱
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');
php技術(shù):php更新修改excel中的內(nèi)容實例代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。