• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to merge the two Excel files?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
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 org.apache.poi.ss.util.Region;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

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
e.printStackTrace();
}
}
}

}


Thanks and Regards
Umesh Annegirikar
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic