PHP Update modify content examples in Excel

Source: Internet
Author: User

 //Template storage directory
$dir = $DOCUMENT _root. ' /backoffice/admin/oemcheck/';
 
 
$templateName = ' 1.xlsx ';
$outputFileName = ' template. xlsx ';
$txt = ' test ';
 
//Real To instantiate an 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;
 }
}
//read Excel
$PHPExcel = $PHPReader->load ($dir. $templateName);
//Read 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 ');

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.