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();
}
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();
}
Aggregations