hi patel i just copied your Update Existing Excel File and run it in netbeans ide.when i run it shows the following error,
Exception in thread “main” java.lang.IllegalArgumentException: Sheet index (0) is out of range (0..-1)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.validateSheetIndex(HSSFWorkbook.java:429)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheetAt(HSSFWorkbook.java:825)
at com.infomindz.io.ReadXlFile.updateExistingFile(ReadXlFile.java:277)
at com.infomindz.io.ReadXlFile.main(ReadXlFile.java:308)
and the code is
String path = separator + "home" + separator + "santhanam" + separator+ "Contact list.xls"; FileInputStream inStream = new FileInputStream(path); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.getSheetAt(0); Cell cell = null; //going to update existing excel file cell = sheet.getRow(1).getCell(2); cell.setCellValue(cell.getNumericCellValue() * 2); cell = sheet.getRow(2).getCell(2); cell.setCellValue(cell.getNumericCellValue() * 2); cell = sheet.getRow(3).getCell(2); cell.setCellValue(cell.getNumericCellValue() * 2); inStream.close(); FileOutputStream out = new FileOutputStream(path); workbook.write(out); System.out.println("Updating Excell file successful");
and also i checked xl file values.it is contain same value as what you gave.
if i did anything wrong pls advice me.
thanks in advance