1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public void download() throws IOException{
System.out.println("you clicked download");
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("C:\\Users\\Info\\Desktop\\Annexe 30.xlsx"));
XSSFSheet sheet = wb.getSheetAt(1);
XSSFCell cell = sheet.getRow(50).getCell(8);
if(cell == null)
{ System.out.println(" if(cell == null)");
cell= sheet.getRow(50).createCell(8);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// System.out.println(" cell.setCellValue(\"a test\"); done successfully !!");
}
//System.out.println(" the (cell is not null)");
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
System.out.println("cell.setCellValue(\"a test\"); done successfully !!");
FileOutputStream fileOut= new FileOutputStream ("C:\\Users\\Info\\Desktop\\Annexe 30.xlsx");
wb.write(fileOut);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseContentType("application/projet");
externalContext.setResponseHeader("Content-Disposition","attachment; filename=\""+ fileOut +"\"" );
externalContext.getResponseOutputStream();
facesContext.responseComplete();
System.out.println(" facesContext.responseComplete(); done succussfully !! ");
} |
Partager