Home >Backend Development >PHP Tutorial >PHP reading excel file example sharing (update and modify excel)_PHP tutorial

PHP reading excel file example sharing (update and modify excel)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:36:53912browse

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');

www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn