Merci pour le code mais la fonction ne s'execute pas chez moi. Qu'est qu'il faut faire? y'a t'il quelque chose à faire sur le tableau. SVP j'attend votre reponse
voici mon code.
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Export</title>
<style type="text/css">
<!--
.InEo {visibility:hidden; font-size: 9px; }
.InEo {visibility:visible; font-size: 9px }
-->
</style>
<SCRIPT type="text/javascript">
function exportToExcel(tableau) {
oExcel = new ActiveXObject('Excel.Application');
oWkBooks = oExcel.Workbooks.Add;
oExcelSheet = oWkBooks.Worksheets(1);
oExcelSheet.Activate();
nbrCellules = tableau.cells.length;
for (i = 0; i < tableau.cells.length; i++) {
nbrCellules = nbrCellules + (tableau.cells(i).colSpan * tableau.cells(i).rowSpan) - 1;
}
nbrColonnes = Math.ceil(nbrCellules / tableau.rows.length);
tab = new Array();
for (j = 0; j < nbrCellules; j++) {
tab.push('*');
}
decal = 0;
for (k = 0; k < tableau.cells.length; k++) {
if ((tableau.cells(k).colSpan == 1) && (tableau.cells(k).rowSpan == 1)) {
if (k != (tableau.cells.length - 1)) {
while (tab.slice((k + decal), (k + decal + 1)) == '') {
decal = decal + 1;
}
}
tab.splice((k + decal),1,tableau.cells(k).innerText);
} else if ((tableau.cells(k).colSpan > 1) && (tableau.cells(k).rowSpan == 1)) {
tab.splice((k + decal),1,tableau.cells(k).innerText);
for (l = 0; l < (tableau.cells(k).colSpan - 1); l++) {
tab.splice((k + decal + l + 1),1,'');
}
decal = decal + tableau.cells(k).colSpan - 1;
} else if ((tableau.cells(k).colSpan == 1) && (tableau.cells(k).rowSpan > 1)) {
tab.splice((k + decal),1,tableau.cells(k).innerText);
for (m = 0; m < (tableau.cells(k).rowSpan - 1); m++) {
tab.splice((k + decal + ((m + 1) * nbrColonnes)),1,'');
}
} else if ((tableau.cells(k).colSpan > 1) && (tableau.cells(k).rowSpan > 1)) {
tab.splice((k + decal),1,tableau.cells(k).innerText);
for (n = 0; n < tableau.cells(k).rowSpan ; n++) {
for (o = 0; o < tableau.cells(k).colSpan ; o++) {
if ((n == 0) && (o != 0)) {
tab.splice((k + decal + n + 1),1,'');
decal = decal + 1;
} else if (n != 0) {
tab.splice(k + decal + (nbrColonnes - tableau.cells(k).colSpan) + o + 1 + ((n - 1) * nbrColonnes),1,'');
}
}
}
}
}
for (m = 0; m < tab.length; m++) {
r = Math.ceil((m + 1) / nbrColonnes);
c = (m + 1) - ((r - 1) * nbrColonnes);
oExcel.ActiveSheet.Cells(r,c).Value = tab.slice(m,(m + 1));
}
oExcelSheet.Application.Visible = true;
}
</SCRIPT>
</head>
<body>
<p> </p>
<div id="tableau">
<table width="200" border="1" id="tableau">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
<div align="center">
<input name="Submit2" type="button" class="InEo" onClick="exportToExcel(tableau)" value="EXPORTER" />
</div>
<p> </p>
</body>
</html>