Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to merge the two Excel files?  RSS feed

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
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!