This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes How to merge the two excel files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to merge the two excel files" Watch "How to merge the two excel files" New topic
Author

How to merge the two excel files

umesh annegirikar
Greenhorn

Joined: May 09, 2011
Posts: 28
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to merge the two excel files
 
Similar Threads
Copying a sheet from an excel file to another excel file using Apache POI
want to add data in excel but my code is overwriting the sheet
Removing duplicate
reading multiple sheets using apache POI
import data from excel files to database