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

WBOY
Release: 2016-07-13 10:36:53
Original
866 people have browsed it

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!