Search in sources :

Example 21 with WritableSheet

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++;
    }
}
Also used : Number(jxl.write.Number) Label(jxl.write.Label) WritableSheet(jxl.write.WritableSheet) JasperPrint(net.sf.jasperreports.engine.JasperPrint) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

WritableSheet (jxl.write.WritableSheet)21 WritableCellFormat (jxl.write.WritableCellFormat)10 WritableWorkbook (jxl.write.WritableWorkbook)10 WriteException (jxl.write.WriteException)9 WorkbookSettings (jxl.WorkbookSettings)8 IOException (java.io.IOException)6 Constraint (com.cubrid.common.core.common.model.Constraint)5 Label (jxl.write.Label)5 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)4 SQLException (java.sql.SQLException)4 Number (jxl.write.Number)4 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 WritableFont (jxl.write.WritableFont)3 TableItem (org.eclipse.swt.widgets.TableItem)3 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 ExportDataFailedOneTableEvent (com.cubrid.common.ui.cubrid.table.event.ExportDataFailedOneTableEvent)2