Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to merge the two excel files  RSS feed

umesh annegirikar
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Team
I am working on one of the requirement in which i have to merge more than one excel files but the restriction is that all the excel sheets should be merged in one sheet.My Source code for the merging the two files is as below.Also i have an issue in which when i put the data in the InputStream for writing that into new file and then for next file i.e for 1st,2nd,3rd,etc the merging file the data would be overwritten.So how should i write the merge method?...please tell me

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;

public class ExcelReader
public static int maxColumn=0;
public static String sourcePath="C:/Books";
public static int i=0;
public static String fileName="C:/Books/umesh.xls";
public static String fileName2="C:/Books/geotech.xls";
public static String targetPath="C:/Books";
public static String mergedFile="C:/Books/Merged.xls";
public static ArrayList<String> aList=new ArrayList<String>();

public void mergeExcel()
for(int j=0;j<aList.size();j++)

try {
HSSFWorkbook workbook=new HSSFWorkbook();
HSSFSheet sheet=workbook.createSheet("sheet1");
HSSFSheet sheet2=workbook.createSheet("sheet 2");
FileOutputStream fileOutputStream=new FileOutputStream(mergedFile);

FileInputStream inputStream=new FileInputStream(fileName);
FileInputStream inputStream2=new FileInputStream(fileName2);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block


Thanks and Regards
Umesh Annegirikar
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!