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.

****************************************************************************************

Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you.

****************************************************************************************

Reply via email to