Writing data to Excel that has data in the first place will not overwrite the original data, just append the data. public class Excel { public Excel () { } public void Createworkbook (file file, double[] a) { try { if (!file.exists ()) {//determines if the file already exists and creates a new file if it does not exist jxl.write.writableworkbook WWB = Workbook.createworkbook (new file ("Result.xls" ); jxl.write.writablesheet ws = Wwb.createsheet ("Test Sheet 1", 0); &nbSp; int i = 0; ws.setcolumnview (0, 20); Set column widths Jxl.write.NumberFormat NF = new Jxl.write.NumberFormat ( "0.0000000000000000" ); Define numeric formats Writablecellformat WCFN = new Writablecellformat (NF); string str2 = "No." + 1 + "secondary test"; label label = new label (0, 0, str2); &Nbsp; ws.addcell (label); while (i < a.length) { Jxl.write.Number num = new Jxl.write.Number (0, i + 1, a[ I], WCFN); ws.addcell (num); i++; } //Write Exel Worksheets Wwb.write (); // Close the Excel Workbook object Wwb.close (); } else { workbook RWB = Workbook.getWorkbook (file); file Tempfile = new File (System.getproperty ("User.dir") + "\\tempfile.xls"); writableworkbook WWB = Workbook.createWorkbook ( Tempfile, RWB); Writablesheet ws = Wwb.getsheet (0); int num = rwb.getsheet (0). GetColumns (); int NUM1 = num + 1; ws.setcolumnview (num, 20); Set Column width string STR2 = "First" + NUM1 + "secondary test"; Add Column name label Label = new label (num, 0, str2); &nBsp;ws.addcell (label); int i = 0; jxl.write.numberformat NF = new Jxl.write.NumberFormat ( " 0.000000000000000 "); Define numeric formats Writablecellformat WCFN = new Writablecellformat (NF); while (i < a.length) { jxl.write.number number = new Jxl.write.Number (num, &nbsP; i + 1, a[i], WCFN); ws.addcell (number); i++; } wwb.write (); wwb.close (); rwb.close (); string filename = File.getpath (); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("FileName:" + filename); file.delete (); tempfile.renameto (file); system.out.println (" Tempfile: "+ Tempfile.getpath ()); system.out.println (Tempfile.exists ()); system.out.println (File.exists ()); } } catch (Exception e) { &Nbsp; e.printstacktrace (); } }}
Java JXL An example of appending data to Excel without overwriting the original data