Dear all,
I am working to exporting our data model into Excel 2007 and the export a
very slow in production for yet unknown reason.
I used profiler and it showed that most of the time is being spent in
XSSFCell.setCellType and XSSFCell.setCellValue (I attached screenshots of
the profiler). The context of the problem: we take existing excel from
file, populate it with our data and send it to browser.
Code excerpt:
private static void exportObjects(Workbook workBook, Model model,
List<CustomFieldConfig> fields,
Map<String, Statistics> statisticMap) {
Sheet sheet = workBook.getSheet("objects");
setHeader(sheet, null, fields, "Type", "Subject Area", "Object
Name",
"Description", "Source of Records", "Used By");
int i=1;
for (Table table : model.getTables()) {
Row row = sheet.getRow(i);
if (row==null){
row = sheet.createRow(i);
}
setValue(row, 0, "Table");
String subjectArea = getSubjectArea(table);
Statistics statistics = getStatistics(statisticMap,
subjectArea);
statistics.countTables++;
setValue(row, 1, subjectArea);
setValue(row, 2, table.getName());
Object description = table.getCustomData("Description");
if (description!=null && description.toString().length()>0) {
statistics.countTablesDescribed++;
}
setValue(row, 3, description);
setValue(row, 4, table.getCustomData("Source of Records"));
setValue(row, 5, table.getCustomData("Used By"));
i++;
}
:.
private static void setValue(Row row, int j, Object value) {
Cell cell = row.getCell(j);
if (cell == null) {
cell = row.createCell(j);
}
if (value instanceof String) {
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue((String)value);
} else if (value instanceof Integer) {
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellValue((Integer)value);
} else if (value instanceof Long) {
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellValue((Long)value);
} else if (value instanceof Boolean) {
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue((Boolean)value ? "yes" : "no");
} else if (value instanceof Date) {
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue((Date)value);
}
}
Please point me to possible improvements. Thanks, Slava!
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]