This is possible if you create a new action that extends from Excel Action (How to create custom action) and use the collapsed attribute of the Column instead of the visible attribute.
Create an action class and add the @ActionType annotation with the desired type name:
Very nice solution, indeed.
The problem is the column is not in the container (is not a property), I added it manually in order to print it (is about many to many relation).
In conclusion when I try to add collapsed attribute to column I have: IllegalArgumentException: Property 'myCol' was not found in the container.
I created an action new package in mycomp.web, made a new class CustomExcelAction
but when I try to open Transaction Browse Table I have
Unable to get constructor for 'class mycomp.web.actions.CustomExcelAction' action
NoSuchMethodException:mycomp.web.actions.CustomExcelAction.<init>(java.lang.String)
@ActionType(CustomExcelAction.ID)
public class CustomExcelAction extends ExcelAction {
public static final String ID = "customExcel";
public CustomExcelAction() {
this(ID);
}
public CustomExcelAction(String id) {
super(id);
}
@Override
protected void export(ExcelExporter.ExportMode exportMode) {
ExcelExporter exporter = new ExcelExporter();
exporter.setExportAggregation(exportAggregation);
Window window = ComponentsHelper.getWindowNN(target);
ExportDisplay display = beanLocator.get(ExportDisplay.NAME);
display.setFrame(window);
if (target instanceof Table) {
@SuppressWarnings("unchecked")
Table<Entity> table = (Table<Entity>) target;
// print all Table columns
exporter.exportTable(table, new ArrayList<>(table.getColumns()), false, display, null, fileName, exportMode);
}
if (target instanceof DataGrid) {
@SuppressWarnings("unchecked")
DataGrid<Entity> dataGrid = (DataGrid<Entity>) target;
// print all DataGrid columns
exporter.exportDataGrid(dataGrid, new ArrayList<>(dataGrid.getColumns()), display, null, fileName, exportMode);
}
if (exporter.isXlsMaxRowNumberExceeded()) {
Notifications notifications = ComponentsHelper.getScreenContext(target).getNotifications();
notifications.create(Notifications.NotificationType.WARNING)
.withCaption(messages.getMainMessage("actions.warningExport.title"))
.withDescription(messages.getMainMessage("actions.warningExport.message"))
.show();
}
}
}
If you want to use the generated column when exporting to an XLS file than you should use the Table#PrintableColumnGenerator interface (link to the documentation). The value for a cell in an XLS document is defined in the getValue() method of this interface.