Excel export button: how to setup differing / multiple "exportOptions" for individual columns?

Excel export button: how to setup differing / multiple "exportOptions" for individual columns?

ASWSASWS Posts: 43Questions: 4Answers: 0
edited November 2022 in Editor

(.net)
button excelHtml5 export:

Question:
I need to modify export data of columns let's say A B C and columns D E F differently, and it can't be done in one go.

Therefore in export options I need to parse and substitute data column by column!

I would need to define something like this:

buttons: [{
extend: 'excelHtml5', 
messageTop: 'your exported excel data looks like...',
exportOptions: {
                            {
                            columns: [1, 2],
                            stripHtml: true,
                                format: {
                                    body: function (data) {
                                        data = data.replace(/[K]/g, 'O');
                                        return data;
                                    }}
                                },
                           {
                            columns: [3, 4],
                            stripHtml: true,
                                format: {
                                    body: function (data) {
                                        data = data.replace(/[O]/g, 'K');
                                        return data;
                                    }}
                                }
                        },

Above obviously doesn't work, just for explanation...
Is sequentially modifying data somehow possible at all here?
Thanks in advance !

Replies

  • ASWSASWS Posts: 43Questions: 4Answers: 0
    edited November 2022

    ok, I answer my own questions now.
    should have tested this earlier.

    so here's how to modify & export data to excel, column by column, before export:

    buttons: [{
    extend: 'excelHtml5',
    messageTop: 'your exported excel data looks better now...',
     exportOptions: {
          format: {
             body: function (data, row, column, node) {
             if (column === 6 || column === 7) 
             {
             data = data.replace(/[€.]/g, '');
             data = data.replace(/[,]/g, '.');
             return $(data).find('.title').remove().end().text();
             }
             else
             {
             data = data.replace(/[.]/g, '/');
             return $(data).find('.title').remove().end().text();
             }
             }
             }
    ...
    
    
Sign In or Register to comment.