Export Excel data format

Export Excel data format

JFimexJFimex Posts: 5Questions: 3Answers: 0

suppose I have the table:

<html>
    <head>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.10,b-1.1.0,b-html5-1.1.0/datatables.min.css"/>

    <script type="text/javascript" src="https://cdn.datatables.net/s/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.10,b-1.1.0,b-html5-1.1.0/datatables.min.js"></script>
        <script>
        $(function() {
        $("#dat").DataTable( { buttons: ['excel'], dom: 'Bfrtip' } );
        });
        </script>
    </head>
    <body>
        <table id="dat">
            <thead>
                <tr>
                    <th>First Col</th>
                    <th>Second Col</th>
                    <th>Third Col</th>
                    <th>Fouth Col</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>First Row</td>
                    <td> 1 </td>
                    <td> 1,000,000 </td>
                    <td> 0.111111 </td>
                </tr>
                <tr>
                    <td>Second Row</td>
                    <td> 2 </td>
                    <td> 2,000,000 </td>
                    <td> 0.222222 </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

when I click the excel button, column 1 will format as a string, column 2 will format as a number, but columns 3 and 4 will be treated as strings, Is there any way to get columns 3 and 4 to format as numbers when I export to excel?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,765Questions: 1Answers: 10,510 Site admin
    Answer ✓

    You would need to deformat the data in some way:

    That last column should already be a number - it is probably the spaces that are stopping it.

    Allan

  • JFimexJFimex Posts: 5Questions: 3Answers: 0

    Thanks, It's actually the leading 0 that stops the last column being a number, not the space. so ".111111" and ".222222" exports as numbers.

  • tjurinectjurinec Posts: 5Questions: 2Answers: 0

    Is there any way to do the opposite? Format numbers as text withouth adding leading zeroes?

  • allanallan Posts: 63,765Questions: 1Answers: 10,510 Site admin

    Currently no - not without modifying the Buttons software. Type control is something I plan to add in a future version.

    Allan

This discussion has been closed.