Search in sources :

Example 1 with DBDAttributeBindingMeta

use of org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta in project dbeaver by serge-rider.

the class DataExporterXLSX method printHeader.

private void printHeader(DBCResultSet resultSet, Worksheet wsh) throws DBException {
    boolean hasDescription = false;
    if (showDescription) {
        // Read bindings to extract column descriptions
        boolean bindingsOk = true;
        DBDAttributeBindingMeta[] bindings = new DBDAttributeBindingMeta[columns.length];
        for (int i = 0; i < columns.length; i++) {
            if (columns[i] instanceof DBDAttributeBindingMeta) {
                bindings[i] = (DBDAttributeBindingMeta) columns[i];
            } else {
                bindingsOk = false;
                break;
            }
        }
        if (bindingsOk) {
            DBSEntity sourceEntity = null;
            if (getSite().getSource() instanceof DBSEntity) {
                sourceEntity = (DBSEntity) getSite().getSource();
            }
            DBExecUtils.bindAttributes(resultSet.getSession(), sourceEntity, resultSet, bindings, null);
        }
        for (DBDAttributeBinding column : columns) {
            if (!CommonUtils.isEmpty(column.getDescription())) {
                hasDescription = true;
                break;
            }
        }
    }
    SXSSFSheet sh = (SXSSFSheet) wsh.getSh();
    Row row = sh.createRow(wsh.getCurrentRow());
    int startCol = rowNumber ? 1 : 0;
    sh.trackAllColumnsForAutoSizing();
    for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
        DBDAttributeBinding column = columns[i];
        String colName = column.getLabel();
        if (CommonUtils.isEmpty(colName)) {
            colName = column.getName();
        }
        Cell cell = row.createCell(i + startCol, CellType.STRING);
        cell.setCellValue(colName);
        cell.setCellStyle(styleHeader);
    }
    if (hasDescription) {
        wsh.incRow();
        Row descRow = sh.createRow(wsh.getCurrentRow());
        for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
            Cell descCell = descRow.createCell(i + startCol, CellType.STRING);
            String description = columns[i].getDescription();
            if (CommonUtils.isEmpty(description)) {
                description = "";
            }
            descCell.setCellValue(description);
            descCell.setCellStyle(styleHeader);
        }
    }
    for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
        sh.autoSizeColumn(i);
    }
    wsh.incRow();
    try {
        sh.flushRows();
    } catch (IOException e) {
        throw new DBException("Error processing header", e);
    }
    sh.untrackAllColumnsForAutoSizing();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDAttributeBindingMeta(org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) IOException(java.io.IOException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Example 2 with DBDAttributeBindingMeta

use of org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta in project dbeaver by dbeaver.

the class DataExporterXLSX method printHeader.

private void printHeader(DBCResultSet resultSet, Worksheet wsh) throws DBException {
    boolean hasDescription = false;
    if (showDescription) {
        // Read bindings to extract column descriptions
        boolean bindingsOk = true;
        DBDAttributeBindingMeta[] bindings = new DBDAttributeBindingMeta[columns.length];
        for (int i = 0; i < columns.length; i++) {
            if (columns[i] instanceof DBDAttributeBindingMeta) {
                bindings[i] = (DBDAttributeBindingMeta) columns[i];
            } else {
                bindingsOk = false;
                break;
            }
        }
        if (bindingsOk) {
            DBSEntity sourceEntity = null;
            if (getSite().getSource() instanceof DBSEntity) {
                sourceEntity = (DBSEntity) getSite().getSource();
            }
            DBExecUtils.bindAttributes(resultSet.getSession(), sourceEntity, resultSet, bindings, null);
        }
        for (DBDAttributeBinding column : columns) {
            if (!CommonUtils.isEmpty(column.getDescription())) {
                hasDescription = true;
                break;
            }
        }
    }
    SXSSFSheet sh = (SXSSFSheet) wsh.getSh();
    Row row = sh.createRow(wsh.getCurrentRow());
    int startCol = rowNumber ? 1 : 0;
    sh.trackAllColumnsForAutoSizing();
    for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
        DBDAttributeBinding column = columns[i];
        String colName = column.getLabel();
        if (CommonUtils.isEmpty(colName)) {
            colName = column.getName();
        }
        Cell cell = row.createCell(i + startCol, CellType.STRING);
        cell.setCellValue(colName);
        cell.setCellStyle(styleHeader);
    }
    if (hasDescription) {
        wsh.incRow();
        Row descRow = sh.createRow(wsh.getCurrentRow());
        for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
            Cell descCell = descRow.createCell(i + startCol, CellType.STRING);
            String description = columns[i].getDescription();
            if (CommonUtils.isEmpty(description)) {
                description = "";
            }
            descCell.setCellValue(description);
            descCell.setCellStyle(styleHeader);
        }
    }
    for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
        sh.autoSizeColumn(i);
    }
    wsh.incRow();
    try {
        sh.flushRows();
    } catch (IOException e) {
        throw new DBException("Error processing header", e);
    }
    sh.untrackAllColumnsForAutoSizing();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDAttributeBindingMeta(org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) IOException(java.io.IOException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Aggregations

IOException (java.io.IOException)2 SXSSFSheet (org.apache.poi.xssf.streaming.SXSSFSheet)2 DBException (org.jkiss.dbeaver.DBException)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 DBDAttributeBindingMeta (org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta)2 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)2