JAVA: Export ArrayLists into excel table with NEW sheet everytime -


i have 2 arrayslists (x , y) different number of elements. now, want export them among excel-table. x , y should have own columns side side.

example: x = [2 , 6 , 0], y = [5 , 8 , 3]

x | y  ------ 2 | 5  6 | 8  0 | 3  

everytime run program, arrays new elements. @ end of programm, has saved in excel table, , everytime in new sheet. when open pogramm 5 times, should have 5 sheets (the name of sheet actual time , date - saved in variable called date).

my questions: 1. how can arraylists own colums? 2. how supposed create new sheets , dont overwrite old ones?

hssfworkbook workbook = new hssfworkbook(); hssfsheet sheet = workbook.createsheet(date); //everytime, sheet overwritten, need new sheed. workbook.addsheet(date) perfect              map<string, object[]> data = new hashmap<string, object[]>();             data.put("1", new object[] {"column 1", "column 2"});              //maybe kind of for-loop arraylists? dont know              set<string> keyset = data.keyset();             int rownum = 0;             (string key : keyset) {                 row row = sheet.createrow(rownum++);                 object [] objarr = data.get(key);                 int cellnum = 0;                 (object obj : objarr) {                     cell cell = row.createcell(cellnum++);                     if(obj instanceof date)                          cell.setcellvalue((date)obj);                     else if(obj instanceof boolean)                         cell.setcellvalue((boolean)obj);                     else if(obj instanceof string)                         cell.setcellvalue((string)obj);                     else if(obj instanceof double)                         cell.setcellvalue((double)obj);                 }             }              try {                 fileoutputstream out =                          new fileoutputstream(new file(".//src//excel-table.xls"));                 workbook.write(out);                 out.close();                 system.out.println("excel written successfully..");              } catch (filenotfoundexception e) {                 e.printstacktrace();             } 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -