3.5.5.2.6. ExcelAction
ExcelAction is a list action designed to export the table content to an XLS file.
If the user has selected some rows in the table, the action will ask whether they want to export the selected or all rows. You can override the title and message of the dialog by adding messages with actions.exportSelectedTitle
and actions.exportSelectedCaption
keys to your main message pack.
The action is implemented by com.haulmont.cuba.gui.actions.list.ExcelAction
class and should be defined in XML using type="excel"
action’s attribute. You can configure common action parameters using XML attributes of the action
element, see Declarative Actions for details. Below we describe parameters specific to the ExcelAction
class.
-
fileName
- the export file name. If not specified, it is generated automatically based on the entity name. -
exportAggregation
- whether to export aggregation rows if they exist in the table. True by default.
For example:
<action id="excel" type="excel">
<properties>
<property name="fileName" value="customers"/>
<property name="exportAggregation" value="false"/>
</properties>
</action>
Alternatively, you can inject the action into the screen controller and configure it using setters:
@Named("customersTable.excel")
private ExcelAction customersTableExcel;
@Subscribe
public void onInit(InitEvent event) {
customersTableExcel.setFileName("customers");
customersTableExcel.setExportAggregation(false);
}
If you want to perform some checks or interact with the user before the action is executed, subscribe to the action’s ActionPerformedEvent
and invoke execute()
method of the action when needed. In the example below, we show a custom confirmation dialog before executing the action:
@Named("customersTable.excel")
private ExcelAction customersTableExcel;
@Subscribe("customersTable.excel")
public void onCustomersTableExcel(Action.ActionPerformedEvent event) {
dialogs.createOptionDialog()
.withCaption("Please confirm")
.withMessage("Are you sure you want to print the content to XLS?")
.withActions(
new DialogAction(DialogAction.Type.YES)
.withHandler(e -> customersTableExcel.execute()), // execute action
new DialogAction(DialogAction.Type.NO)
)
.show();
}
You can also subscribe to ActionPerformedEvent
and instead of invoking the action’s execute()
method, use ExcelExporter
class directly.