use of jxl.write.WritableSheet in project dhis2-core by dhis2.
the class GridUtils method toXlsInternal.
private static void toXlsInternal(Grid grid, WritableWorkbook workbook, String sheetName, int sheetNo) throws Exception {
if (grid == null) {
return;
}
int cols = grid.getVisibleHeaders().size();
if (cols > JXL_MAX_COLS) {
log.warn("Grid will be truncated, no of columns is greater than JXL max limit: " + cols + "/" + JXL_MAX_COLS);
}
WritableSheet sheet = workbook.createSheet(sheetName, sheetNo);
int rowNumber = 0;
int columnIndex = 0;
if (StringUtils.isNotEmpty(grid.getTitle())) {
sheet.addCell(new Label(0, rowNumber++, grid.getTitle(), XLS_FORMAT_TTTLE));
rowNumber++;
}
if (StringUtils.isNotEmpty(grid.getSubtitle())) {
sheet.addCell(new Label(0, rowNumber++, grid.getSubtitle(), XLS_FORMAT_TTTLE));
rowNumber++;
}
List<GridHeader> headers = ListUtils.subList(grid.getVisibleHeaders(), 0, JXL_MAX_COLS);
for (GridHeader header : headers) {
sheet.addCell(new Label(columnIndex++, rowNumber, header.getName(), XLS_FORMAT_LABEL));
}
rowNumber++;
for (List<Object> row : grid.getVisibleRows()) {
columnIndex = 0;
List<Object> colums = ListUtils.subList(row, 0, JXL_MAX_COLS);
for (Object column : colums) {
if (column != null && MathUtils.isNumeric(String.valueOf(column))) {
sheet.addCell(new Number(columnIndex++, rowNumber, Double.valueOf(String.valueOf(column)), XLS_FORMAT_TEXT));
} else {
String content = column != null ? String.valueOf(column) : EMPTY;
sheet.addCell(new Label(columnIndex++, rowNumber, content, XLS_FORMAT_TEXT));
}
}
rowNumber++;
}
}
Aggregations