From Athento trays (document queues), it is possible to export the visible data to Excel using the Excel button. By default, this export generates a flat output (without specific formatting), so there is the possibility of applying a custom Excel export format in Athento so that certain fields (for example, numeric ones) are correctly represented in the resulting file.
Export configuration: customize and export options
To customize the data output of a tray, the customize and export options fields are used. Both are found in the tray administration area, as shown below.
Using the “Table excel export customize” field, you can define display rules and apply styles according to the types available in the datatable.js component: https://datatables.net/reference/button/excelHtml5
Below is an example where the style with ordinal 59 is assigned to column “G”:
59– Euro currency values (automatically detected and used by buttons – since 1.2.3)
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:gt(1) c[r^="G"]', sheet).attr('s', 59);
In this way, the exported data will be displayed in currency format and with the Euro symbol.
For its part, the “Table excel export option” field allows applying transformations to a field’s data before applying the style. This helps to standardize the exported values (for example, to unify decimal separators).
In the following example, the data is normalized to display monetary values with the Euro symbol: the decimal separator is forced to “.” and the € character is removed to prevent it from being shown duplicated.
format: {
body: function(data, row, column, node) {
data = $('<p>' + data + '</p>').text();
if (data.includes('€')) data = data.replace('€', '');
if ($.isNumeric(data.replace(',', '.'))) data = data.replace(',', '.');
return data;
}
}
The configuration would look as follows:
Below is the difference between the original output and the output after applying the configuration of these two fields.
Tray:
Original output (without configuration):
Output after configuration:
Extended configuration
In the Excel export, it is also possible to apply a more advanced style configuration, such as font color, background color, or borders. To do this, the required styles are defined and then added using the addCustomExcelStyles method provided by Athento.
Once the styles are included, they can be applied using jQuery selectors on the elements of the exported table, according to the XML Spreadsheet format.
In addition, it is possible to set a fixed column width by indicating the column position and the width.
An example of extended formatting is shown below.
NOTE. It is important to keep the information about the positions of the styles that are created, since they will be used to apply the format to the corresponding rows or cells.
var sheet = xlsx.xl.worksheets['sheet1.xml'];
var myFontColors = [
'000000', // idx 0 - black
'ffffff' // idx 1 - white
];
var myFillColors = [
'ccffff', // idx 0 - cyan
'ffc000', // idx 1 - dark green
'0066cc' // idx 2 - blue
];
var myBorders = [
{ style: 'medium', color: '9999ff' }
];
var myCellStyles = [
{ fontIdx: 0, fillIdx: 2, vAlign: 'center', hAlign: 'left' }, // idx 0 - black on blue
{ fontIdx: 1, fillIdx: 2, vAlign: 'center', hAlign: 'left' }, // idx 1 - white on blue
{ fontIdx: 0, fillIdx: 0, vAlign: 'top', hAlign: 'left' } // idx 2 - black on cyan
];
// Add custom styles for Excel exportation
var stylesCount = addCustomExcelStyles(xlsx, myFontColors, myFillColors, myBorders, myCellStyles);
// Apply style with idx 0 (Black on Blue) to row number 1
$('row:eq(1) c', sheet).attr('s', getExcelStyle(stylesCount, 0));
// Apply style with idx 2 (Black on Cyan) to rows after position 1
$('row:lt(1) c', sheet).attr('s', getExcelStyle(stylesCount, 2));
// Apply width: 25 to first column (position 0) and width: 40 to second column (position 1)
$('col', sheet)[0].attr('width', 25);
$('col', sheet)[1].attr('width', 40);