alguém pode me ajudar, tenho este método que gera um xls, mas o arquivo só abre no BROffice, no excel ele não abre…segue o método:
public void gerarArquivoXLS(@Parameter(key = "nomeArquivo") String nomeArquivo, @Parameter(key = "nomeCampo") List<String> nomeCampo, @Parameter(key = "registro") List<String> registro) {
this.nomeArquivo = nomeArquivo;
nomeArquivo = Utils.normalizaNomeArquivo(nomeArquivo, this.usuarioBd);
try {
//Escopo de criação da Planilha
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet planilha = wb.createSheet("Relatorio " + nomeArquivo);
HSSFFont fonte = wb.createFont();
fonte.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle estilo = wb.createCellStyle();
estilo.setFont(fonte);
estilo.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//Definindo o Titulo
HSSFRow titulo = planilha.createRow((short) 0);
HSSFCell colunaTitulo = titulo.createCell((short) 0);
colunaTitulo.setCellValue(nomeArquivo);
colunaTitulo.setCellStyle(estilo);
// Escopo de criação dos campos
HSSFRow row = planilha.createRow((short) 2);
for (int cont = 0; cont < nomeCampo.size(); cont++) {
planilha.setColumnWidth((short) (cont), (short) ((1 + (nomeCampo.get(cont).length() * 2)) * 256));
planilha.setColumnWidth((short) (cont), (short) ((1 + (nomeCampo.get(cont).length() * 2)) * 256));
HSSFCell coluna = row.createCell((short) (cont));
coluna.setCellValue(normalizaNomeCampo(nomeCampo.get(cont)));
coluna.setCellStyle(estilo);
}
//Escopo de criação dos registros
String camposTratados;
int contLinhas = 4;
for (int cont = 0; cont < registro.size(); cont++) {
camposTratados = registro.get(cont).toString().replace('[', ' ');
camposTratados = camposTratados.replace(']', ' ');
String[] campos = camposTratados.split(",", nomeCampo.size() + 1);
HSSFRow row2 = planilha.createRow((short) contLinhas++);
for (int cont2 = 1; cont2 < campos.length; cont2++) {
HSSFCell celula = row2.createCell((short) (cont2 - 1));
celula.setCellValue(limpaNulo(campos[cont2]));
}
}
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=" + nomeArquivo + ".xls");
ServletOutputStream os = response.getOutputStream();
os.write(wb.getBytes());
os.flush();
os.close();
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
}
alguém pode me ajudar???