How To Merged or Combined Two or More Excel File(.xls) Using PHPExcel Library

This tutorial explains in a easy way to merged or combined multiple Excel File into a single File with multiple Sheet using PHPExcel Library.

Introduction

To combined multiple Excel File into a single Excel File with multiple Sheet in PHP, we need to rename all sheet name of all Excel File. Default Sheet name is Sheet1 but we will change this name, whatever you want. We will use PHPReport Library to merge Excel Sheet. Include this Library at the top of the file.

Rename Excel Sheet
Rename Excel Sheet

Download PHPReport Library

Don't Miss

We need to download PHPReport Library and extract this downloaded file. Include PHPReport.php Library into Project file.

PHP Code To Merge Excel File

<?php 
        require_once('PhpReport/PHPReport.php');

	// Files are loaded to PHPExcel using the IOFactory load() method
	$objPHPExcel1 = PHPExcel_IOFactory::load("/Your Excel File Path/example1.xlsx");
	$objPHPExcel2 = PHPExcel_IOFactory::load("/Your Excel File Path2/example2.xlsx");
	$objPHPExcel3 = PHPExcel_IOFactory::load("/Your Excel File Path2/example3.xlsx");

	// Copy worksheets from $objPHPExcel2 to $objPHPExcel1
	foreach($objPHPExcel2-?>getAllSheets() as $sheet) {
	   $objPHPExcel1-?>addExternalSheet($sheet);
	}

	// Copy worksheets from $objPHPExcel3 to $objPHPExcel1
	foreach($objPHPExcel3-?>getAllSheets() as $sheet1) {
	   $objPHPExcel1-?>addExternalSheet($sheet1);
	}

	// Save $objPHPExcel1 to browser as an .xls file
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel1, "Excel2007");

	$objWriter-?>save("/Your Excel File Path2/example3.xlsx");

?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

564FansLike

Recent Posts

Concept of Session in Laravel Tutorial

Sessions are used to store details about the user throughout the requests. Laravel supplies various drivers like file, cookie, apc, array, Memcached, Redis, and database to handle session data. By default, file driver is used as a result of it's light-weight....

Laravel Url Generation Tutorial

Our web application revolves around routes and URLs. After all, they're what direct our users to our pages. At the end of the day, serving pages is what any web application should do. Our users may...

Concept of Laravel Views Tutorial

In MVC framework, the letter "V" stands for Views. It separates the application logic and presentation logic. Views are saved in resources/views listing. Generally, the view contains the HTML which might be served by the application.

Related Articles

Concept of Session in Laravel Tutorial

Sessions are used to store details about the user throughout the requests. Laravel supplies various drivers like file, cookie, apc, array, Memcached, Redis, and database to handle session data. By default, file driver is used as a result of it's light-weight....

Laravel Url Generation Tutorial

Our web application revolves around routes and URLs. After all, they're what direct our users to our pages. At the end of the day, serving pages is what any web application should do. Our users may...

Concept of Laravel Views Tutorial

In MVC framework, the letter "V" stands for Views. It separates the application logic and presentation logic. Views are saved in resources/views listing. Generally, the view contains the HTML which might be served by the application.
WP2Social Auto Publish Powered By : XYZScripts.com