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

Basic Geometry Math Formula List

Geometry is a department of mathematics that offers with shape, dimension, relative position of figures, and the properties of space. It emerges independently in variety of early cultures as a practical approach of dealing with lengths, area and volumes.

How to Sign in with Google in Android Tutorial

In this tutorial, we are going to explain how to sign in with Google in Android Application. Many apps want to...

Trigonometry Math Formulas List

Trigonometry is a department of mathematics that offers with triangles. Trigonometry is also called the study of relationships between lengths and angles of triangles. There is a gigantic variety of makes...

Related Articles

Basic Geometry Math Formula List

Geometry is a department of mathematics that offers with shape, dimension, relative position of figures, and the properties of space. It emerges independently in variety of early cultures as a practical approach of dealing with lengths, area and volumes.

How to Sign in with Google in Android Tutorial

In this tutorial, we are going to explain how to sign in with Google in Android Application. Many apps want to...

Trigonometry Math Formulas List

Trigonometry is a department of mathematics that offers with triangles. Trigonometry is also called the study of relationships between lengths and angles of triangles. There is a gigantic variety of makes...