Bonjour,

J'ai récupérer ce script JS pour exporter les données d'un tableau HTML
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	<div id="dvData">
	<table id="table_result" border="2">   
		<tr bgcolor="oldlace">	
			<th class=""></th>
			<th colspan="2">Distribution for all categories entityX by sphereN / all sphere all entities</th> 		 
			<th colspan="2">distribution for all categories for each entity by sphereN</th>    
		</tr> 
		<tr bgcolor="oldlace">		  
			<th class=""><div class=“highlight_rankEntity”><a href="index.php?id=recherche_ent">Entity</a></div></th> 		 
			<th class="">Inside</th>  
			<th class="">Outside</th>	
			<th class="">Inside</th>  
			<th class="">Outside</th>	
		</tr> 
                <tr>
                         <td> contruction dynamique </td>
                </tr>
	</table>  	  
	</div>
	<a href="#" class="export">Export Table data into Excel</a>

Et coté JS :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$(document).ready(function () {
 
    function exportTableToCSV($table, filename) {
 
        var $rows = $table.find('tr:has(td)'),
 
            // Temporary delimiter characters unlikely to be typed by keyboard
            // This is to avoid accidentally splitting the actual contents
            tmpColDelim = String.fromCharCode(11), // vertical tab character
            tmpRowDelim = String.fromCharCode(0), // null character
 
            // actual delimiter characters for CSV format
            colDelim = '";"',
            rowDelim = '"\r\n"',
 
            // Grab text from table into CSV formatted string
            csv = '"' + $rows.map(function (i, row) {
                var $row = $(row),			 
					//$cols = $row.find('th');
                    $cols = $row.find('td');
 
                return $cols.map(function (j, col) {
                    var $col = $(col),
                        text = $col.text();
 
                    return text.replace(/"/g, '""'); // escape double quotes
 
                }).get().join(tmpColDelim);
 
            }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"',
 
            // Data URI
            csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
 
        $(this)
            .attr({
            'download': filename,
                'href': csvData,
                'target': '_blank'
        });
    }
 
    // This must be a hyperlink
    $(".export").on('click', function (event) {
        // CSV
        exportTableToCSV.apply(this, [$('#dvData>table'), 'export.csv']);
 
        // IF CSV, don't do event.preventDefault() or return false
        // We actually need this to be a typical hyperlink
    });
});

2 problèmes :

1/ les balise "titre" <th> ne sont pas prise en compte, comment faire pour les prendre en compte ?
2/ comment faire pour utiliser ce script sur plusieurs tableau dans la même page ?

Merci