How to add a row in an existing Excel file using Java? -


How to add a line to an existing Excel file using Java? I tried to use this code but it is not working. Please tell me what I need to improve.

  Try {string s1, s2, s3, s4; S1 = jTextField1.getText (); S2 = jTextField2.getText (); S3 = jTextField3.getText (); S4 = jTextField4.getText (); FileInputStream fis = null; File excel = new file ("e: \\ two \\ record.xlsx"); Fis = new FileInputStream (excel); XSSFWorkbook wb = New XSSFWorkbook (fis); XSSFSheet ws = wb.getSheet ("cmss"); Int rowNum = ws.getLastRowNum () + 1; Line line = ws.createRow (4); String [] s = new string [4]; S [0] = s1; S [1] = S2; S [2] = S3; S [3] = s4; {Cell cell = row.ctetate (i); for (int i = 0; i & lt; 4; i ++); Cell.setCellValue (s [i]); } JTextField1.setText (""); JTextField2.setText (""); JTextField3.setText (""); JTextField4.setText (""); } Hold (FileNotFoundException pre) {Logger.getLogger (Addxl.class.getName ()). Logs (level SESEE, blank, east); } Hold (IOException pre) {Logger.getLogger (Addxl.class.getName ()). Log (Level.SEVERE, null, ex); }  

Have you written the file after adding the rows? For example:

  wb.write (new FileOutputStream (excel));  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -