Galera,
Uso uma planilha base para inserir os dados de uma consulta sql, como por exemplo abaixo o "arquivo.xls" e está funcionando perfeito, porém funciona apenas uma vez. Parece que quando vou reutilizar a planilha ela está bloqueada.... Quando reinicio o tomcat ela funciona novamente, porém apenas uma vez.
Alguém sabe como resolver?
vai ai meu código:
public static void exportarPOI(String caminho,String[] primeira, int coluna,int linha,int linha2, String nome) throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("arquivo.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = null;
int vai=1;
try {
for(int i=0; i<linha; i++){
row = sheet.getRow(vai);
row.createCell((short) coluna).setCellType(0);
row.getCell(coluna).setCellValue(primeira[i]);
vai++;
}
} catch (Exception e) { }
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse res = (HttpServletResponse) fc.getExternalContext().getResponse();
try {
OutputStream out = res.getOutputStream();
res.setContentType("application/vnd.ms-excel");
res.setHeader("Content-disposition", "inline; filename="+nome+".xls");
wb.write(out);
out.flush();
out.close();
} catch (FileNotFoundException fne) {} catch (IOException ioe) {}
}