|
Hi Friends, I am trying to add a new sheet in already existing excel file, but I
get the above error (Damage to excel file and recovery and all) as well as all
the old formatting are lost. I have written the following code: FileInputStream inputStream = new FileInputStream(getFilePath());
poiFileSystem = new POIFSFileSystem(inputStream);
workBook = new HSSFWorkbook(poiFileSystem,true);
sheet = workBook.createSheet("MPI Errors");//create error sheet
currentRowNum++;
HSSFRow addInfoRow = sheet.createRow(currentRowNum);
addInfoRow.setHeight((short)((4 * 8)/((double)1/20)));
Region region = new Region(currentRowNum, (short)0, currentRowNum, (short)1);
sheet.addMergedRegion(region);
HSSFCellStyle addInfoCellStyle = createCellStyle (borderThick,
"Arial",(short)12, HSSFFont.BOLDWEIGHT_BOLD,
(short)0, false, HSSFCellStyle.ALIGN_LEFT);
//create Error Header
createCell(addInfoRow, (short)0, "MPI Errors",
addInfoCellStyle);
createCell(addInfoRow, (short)1, "",
addInfoCellStyle); inputStream.close(); FileOutputStream fout = new FileOutputStream(getFilePath());
workBook.write(fout);
fout.flush();
fout.close(); Any ideas where am I wrong, again if I create new excel and then create
a sheet formatting comes fine but this is not my requirement. Thanks Garima.
|
