Export to Excel - How to duplicate row and replace some data?
Export to Excel - How to duplicate row and replace some data?
markzzz
Posts: 49Questions: 8Answers: 1
I export a DataTable to Excel in this way:
$.extend(true, $.fn.dataTable.defaults, {
buttons: {
buttons: [
{
extend: 'excel',
exportOptions: {
format: {
body: function (data, row, column, node) {
var result = data;
// cell Payments
if (column == GetColumnIndexByColumnName("Payments", true)) {
result = "";
var cellGrid = $(node).find('.cell-grid');
cellGrid.find('.cell-grid-row.active .cell-grid-col.amount').each(function (index, el) {
var elem = $(el);
// here's I've somethings like 2, 3 or 4 items
var distinctPayment = elem.text();
});
}
return result.trim();
}
}
},
customize: function (xlsx) {
var sheet1 = xlsx.xl.worksheets['sheet1.xml'];
var columnIndex = GetColumnIndexByColumnName("Payments", true);
var columnLetter = GetLetterByNumber(columnIndex).toUpperCase();
$('row c[r^="' + columnLetter + '"]', sheet1).attr('s', '55');
$('row:first c', sheet1).attr('s', '2');
}
}
]
}
});
What I'd like to do is this: within the foreach, I've more data to display.
Let say 4 different values.
I'd like to replicate to the excel the same row 4 times, and place the correct value (distinctPayment) on the column Payments.
So instead to output on the excel this:
26/11/2015 MyClinic MyPlace Mario Rossi 750,00 €
250,00 €
300,24 €
750,00 €
this:
26/11/2015 MyClinic MyPlace Mario Rossi 750,00 €
26/11/2015 MyClinic MyPlace Mario Rossi 250,00 €
26/11/2015 MyClinic MyPlace Mario Rossi 300,24 €
26/11/2015 MyClinic MyPlace Mario Rossi 750,00 €
How would you achieve this?
This discussion has been closed.
Answers
I've temporarily did it using
customizeData: function (data) { }
and replicate (in javascript) the data of the interessed row, which will be ouputted on excel.A bit "mechanic", but it seems to works