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
|
public class ExcelServlet extends HttpServlet {
protected static Logger log = Logger.getLogger(ExcelServlet.class.getName());
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
response.setContentType("application/vnd.ms-excel");
HSSFWorkbook wb = new HSSFWorkbook();
//Creation du classeur;
HSSFSheet sheet = wb.createSheet("feuille");
//Creation d'une ligne et insertion des cellules;
HSSFRow row = sheet.createRow((short)0);
//creation d'une cellule est insertion d'une valeur
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1);
//Meme chose en une ligne
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("TEXTE BLALALLAL");
row.createCell((short)3).setCellValue(true);
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();
//response.getOutputStream().write(b);
log.debug("fin!!!");
}
catch(Exception e){
log.error(e);
}
}
} |
Partager