Hi,
I'm using poi-3.0.1-Final and I try open a generated excel file in MS
Excel 2003, but I receive a "crash message error".
In my ReportUtils class
<code>
private byte[] getXLSFile() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = null;
sheet = wb.createSheet("Test-Plan");
int row = 0;
Iterator itCollection = dataReport.iterator(); // A ArrayList with
values;
while (itCollection.hasNext()) {
Object obj = itCollection.next();
if (this.getReportType().equals("eventos")) {
ElementoGerenciado elementoGerenciado = (ElementoGerenciado)
obj;
Collection eventos = elementoGerenciado.getEventoCollection
();
if (row == 0) {
HSSFRow rowTitle = sheet.createRow((short)row);
HSSFCell cellTitle = rowTitle.createCell((short)0);
HSSFRichTextString titleText = new
HSSFRichTextString(getReportTitle());
cellTitle.setCellValue(titleText);
HSSFRow rowName = sheet.createRow((short)++row);
HSSFCell cellName = rowName.createCell((short)0);
HSSFRichTextString nameText = new
HSSFRichTextString(getReportColumns().get("Nome").toString() + ": " +
elementoGerenciado.getNome());
cellName.setCellValue(nameText);
HSSFRow rowColluns = sheet.createRow((short)++row);
HSSFCell cellColluns0 = rowColluns.createCell((short)0);
HSSFRichTextString nameColluns0 = new
HSSFRichTextString(getReportColumns().get("Evento").toString());
cellColluns0.setCellValue(nameColluns0);
HSSFCell cellColluns1 = rowColluns.createCell((short)1);
HSSFRichTextString nameColluns1 = new
HSSFRichTextString(getReportColumns().get("Severidade").toString());
cellColluns1.setCellValue(nameColluns1);
HSSFCell cellColluns2 = rowColluns.createCell((short)2);
HSSFRichTextString nameColluns2 = new
HSSFRichTextString(getReportColumns().get("Data").toString());
cellColluns2.setCellValue(nameColluns2);
HSSFCell cellColluns3 = rowColluns.createCell((short)3);
HSSFRichTextString nameColluns3 = new
HSSFRichTextString(getReportColumns().get("Cartao").toString());
cellColluns3.setCellValue(nameColluns3);
HSSFCell cellColluns4 = rowColluns.createCell((short)4);
HSSFRichTextString nameColluns4 = new
HSSFRichTextString(getReportColumns().get("NumeroInterface").toString());
cellColluns4.setCellValue(nameColluns4);
}
Iterator itEventos = eventos.iterator();
while (itEventos.hasNext()) {
ReportEventosHelper helper = (ReportEventosHelper)
extractHelper(itEventos.next());
HSSFRow rowData = sheet.createRow((short)++row);
HSSFCell cellData0 = rowData.createCell((short)0);
HSSFRichTextString data0Text = new HSSFRichTextString(
helper.getEvento());
cellData0.setCellValue(data0Text);
HSSFCell cellData1 = rowData.createCell((short)1);
HSSFRichTextString data1Text = new HSSFRichTextString(
helper.getSeveridade());
cellData1.setCellValue(data1Text);
HSSFCell cellData2 = rowData.createCell((short)2);
HSSFRichTextString data2Text = new HSSFRichTextString(
helper.getData());
cellData2.setCellValue(data2Text);
HSSFCell cellData3 = rowData.createCell((short)3);
HSSFRichTextString data3Text = new HSSFRichTextString(
helper.getCartao());
cellData3.setCellValue(data3Text);
HSSFCell cellData4 = rowData.createCell((short)4);
HSSFRichTextString data4Text = new HSSFRichTextString(
helper.getNumeroInterface());
cellData4.setCellValue(data4Text);
}
}
ByteBuffer buffer = ByteBuffer.wrap(wb.getBytes());
return buffer.array();
</code>
In my Servlet class:
<code>
ServletOutputStream ouputStream = null;
byte[] buffer = reportUtils.getXLSFile();
.
.
.
.
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=
reporteventos.xls");
response.setContentLength(buffer.length);
ouputStream = response.getOutputStream();
ouputStream.write(buffer, 0, buffer.length);
ouputStream.flush();
ouputStream.close();
.
.
.
</code>
Well,
If I save and open this output with MS Excel 2000 or OpenOffice,
work's fine !, but if I try open with MS Excel 97 or MS Excel 2003 the MS
Excel "explode" and I receive a "crash error message".
Any Idea ?