I have got a problem when I try to write an Excel file using the POI framework.
I fetch the data from a Jtable. It's really slow, if the jtable has around 100
records, the process takes around 5 seconds but if the jtable has around 2000
record takes around 3 hours! Please see the code below the way I use POI in
order to write the excel file, maybe there is somethings wrong.
code
private HSSFCell createHSSFCell(HSSFSheet sheet, Object value, int row, int
col) {
// create row if not yet created
HSSFRow hssfRow = sheet.getRow(row);
hssfRow = (hssfRow == null) ? sheet.createRow(row) : hssfRow;
HSSFCell cell = null;
try {
// create cell if not yet created
cell = hssfRow.getCell((short) col);
cell = (cell == null) ? hssfRow.createCell((short) col) : cell;
sheet.autoSizeColumn((short)col);
}catch(Exception e){
}
// HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("dd/mm/yyyy"));
cell.setCellStyle(cellStyle);
// set the cell value
Object cellValue;
if (types[col].equalsIgnoreCase("NUMERIC")){
cellValue = Double.parseDouble(value.toString().replaceAll(" ",
""));
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue((Double) cellValue);
}else
if (types[col].equalsIgnoreCase("NUMERICINT")){
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cellValue = Integer.parseInt(value.toString().replaceAll(" ",
"").substring(0, value.toString().replaceAll(" ", "").lastIndexOf(".")));
cell.setCellValue((Integer) cellValue);
}else
if (types[col].equalsIgnoreCase("DATE")){
if (value.toString().replaceAll(" ", "").length()==8)
cellValue =
DateUtils.formatDate(value.toString().replaceAll(" ", ""));
else
cellValue = "";
cell.setCellValue((String)cellValue);
}else
if (types[col].equalsIgnoreCase("TIME")){
if ((value.toString().replaceAll(" ",
"").length()>=4)&&(value.toString().replaceAll(" ", "").length()<=6))
cellValue =
DateUtils.formatTime(value.toString().replaceAll(" ",
""));
else
cellValue = "";
cell.setCellValue((String)cellValue);
}else{
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cellValue = (value == null) ? "" : value.toString();
cell.setCellValue((String)cellValue);
}
return cell;
Thanks to eveybody, I really appreciate your help!
Regards,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]