Reading up on the issue suggested that similar bugs have been reported, once a given spreadsheet is copied and modified, excel returns an error on opening about the file being too damaged to open. Experimenting with they issue lead me to the conclusion it was only doing on certain spreadsheets, while others would work perfectly, specifically once I deleted the 'comments' from the spreadsheet in question (i'll attach it) it worked correctly. public void testModify(String filename) { try { in = new FileInputStream("exists.xls"); fs = new POIFSFileSystem(in); HSSFWorkbook wb = new HSSFWorkbook(fs); FileOutputStream stream = new FileOutputStream("exists-copy.xls"); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(5); HSSFCell cell = row.getCell(( short ) 5); cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(9999); wb.write(stream); stream.close(); } catch (Exception e) { e.printStackTrace(); } } Both 2.5.1-final and poi-bin-3.0-alpha1-20050704 appear to have the same problem.
Created attachment 16603 [details] XLS file causing the problem
The problem seems to be fixed in poi-3.1-beta1. Yegor