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