Apache poi --> write xls and make it open in openOffice or tools associed with type xlsx

20 views
Skip to first unread message

Gadille Lionel

unread,
May 6, 2020, 10:40:04 AM5/6/20
to sparkjava
hello,

i try to use apache poi to return a xls
...finaly i solve by myself i write here to help other


in my main.java
...
get("/consultation/groupeExpXls",Consultation::groupeExpXls);
...

Consultation.java
public static ByteArrayInputStream groupeExpXls(Request req, Response res) throws ClassNotFoundException, SQLException, IOException {
res.header("Content-Disposition", "attachment; filename=tata.xlsx");
res.type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return (new ByteArrayInputStream(UtilXls.getPointageGroupe("tata").toByteArray()));
}

see apache poi doc for stuf inside  
UtilXls.getPointageGroupe("tata")


//here a point not weel documented d to convert the workbook to stream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
xssWb.write(bos);  //XSSFWorkbook
bos.close();
return bos;
Reply all
Reply to author
Forward
0 new messages