begin process at 2012 02 11 15:33:37
  Trouver un code source :
 
dans
 

2 commentaire(s) de chezeu sur des sources sur tout CodeS-SourceS

Déposé sur Exporter un tableau sous excel (bis)

Ok Merci ça marche bien avec un tableau statique, mais le probléme c'est que j'ai un tableau dynamique qui est rempli avec les données de la BD, et dans ce cas ci ça ne marche plus. comment faire alors? Merci d'avance!
Posté le : 04/10/2008 13:08:49

Déposé sur Exporter un tableau sous excel (bis)

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>&nbsp;</p>
<div id="tableau">
<table width="200" border="1" id="tableau">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</div>
<div align="center">
  <input name="Submit2" type="button" class="InEo" onClick="exportToExcel(tableau)" value="EXPORTER" />
</div>
<p>&nbsp;</p>
</body>
</html>
Posté le : 03/10/2008 14:11:42

1


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,437 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales