Export currency to excel

Export currency to excel

mauriciolederermauriciolederer Posts: 4Questions: 2Answers: 0

I have a problem transforming a string in the format of the Brazilian real currency to export as a number to excel. Following is the code I tried to use, to no avail. Could you help me? Thanks in advance

                   <div class="card-body">
                          <table id="table" class="table table-bordered table-striped">
                              <thead>
                                  <tr>
                                      <th style="text-align:center">UG</th>                                      
                                      <th style="text-align:center">VALOR</th>
                                      <th style="text-align:center">VALOR TOTAL</th>
                                  </tr>
                              </thead>
                              <tbody>
                             <tr>
                                      <td align='center'>CASA</td>
                                      <td align='center'>R$ 1.233.666,76</td>
                                      <td align='center'>R$ 5.611.900,91</td>
                                      </tr>
                      ...

$(function() {

        var buttonCommon = {
            exportOptions: {
                format: {
                    body: function ( data, row, column, node ) {
                        if (column === [1,2]){
                            var data = data.replace("R$", "");
                            var data = data.replace(".", "");
                            return data;

                        }
                    }
                }
            }
        };

        $("#table").DataTable({
            ...
            buttons: [{                    
                    $.extend( true, {}, buttonCommon, {
                    extend: 'excelHtml5',
                    className: 'btn btn-outline-secondary glyphicon glyphicon-duplicate',
                    text: 'Gerar Planilha',
                        } ),
            ],       
            "bDestroy": true
        });
    });

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.