您的位置:首页 > 编程语言 > PHP开发

PHPExcel sheet复制

2017-04-21 21:20 549 查看
1.百度千百篇,在bing搜索里找到答案

直接上内容

引用 http://www.guanggua.com/question/32712542-phpexcel-clone-sheet-and-keep-its-original-style.htmlhttp://stackoverflow.com/questions/35242339/phpexcel-copy-sheet-from-one-to-another-xls-document-with-style

error_reporting(E_ALL);

ini_set(‘display_errors’, TRUE);

ini_set(‘display_startup_errors’, TRUE);

date_default_timezone_set(‘Europe/London’);

define(‘EOL’,(PHP_SAPI == ‘cli’) ? PHP_EOL : ‘
’);

/* Include PHPExcel /

require_once dirname(FILE) . ‘/phpexcel/Classes/PHPExcel.php’;

$savepath= dirname(FILE);

objPHPExcel=PHPExcelIOFactory::load(savepath.”/”.”x.xlsx”);

//重要

objPHPExcel1=PHPExcelIOFactory::load(savepath.”/”.”x.xlsx”);

k=0;foreach(objPHPExcel1->getSheetNames() as sheetName)
{k++;

sheet=objPHPExcel1->getSheetByName(sheetName);sheet->setTitle('Sheet'.k);objPHPExcel->addExternalSheet(sheet);unset(sheet);

}

header(‘Content-Type: application/vnd.ms-excel’);

header(‘Content-Disposition: attachment;filename=”01simple.xlsx”’);

header(‘Cache-Control: max-age=0’);

// If you’re serving to IE 9, then the following may be needed

header(‘Cache-Control: max-age=1’);

// If you’re serving to IE over SSL, then the following may be needed

header (‘Expires: Mon, 26 Jul 1997 05:00:00 GMT’); // Date in the past

header (‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’).’ GMT’); // always modified

header (‘Cache-Control: cache, must-revalidate’); // HTTP/1.1

header (‘Pragma: public’); // HTTP/1.0

objWriter=PHPExcelIOFactory::createWriter(PHPExcel, ‘Excel2007’);

$objWriter->save(‘php://output’);

exit;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PHPExcel sheet-copy php