Accueil > > > AUTOMATION EXCEL PAR JAVASCRIPT
AUTOMATION EXCEL PAR JAVASCRIPT
Information sur la source
Description
Quelques lignes de codes javascript pour utiliser l'activex EXCEL. J'ai utilisé ça pour obtenir la fonctionnalité excel qui permet, lors d'une impression, d'adapter l'état sur une page en hauteur et en largeur. Ainsi le tableau encours est imprimé sur une page quelque soit sa taille (dans les limites acceptées par excel). Je suis parti d'une source trouvée sur le net en y ajoutant les diverses fonctionnalités que je recherchais.(par ex : http://www.yaduk.co.uk/2009/07/22/javascript-expor t-html-table-excel-jscript/) L'intérêt de ce source réside dans les instructions (certaines ne sont pas tés faciles à trouver sur le net) qu'il contient. Son fonctionnement est spécifique à l'application dans lequel est utilisée la fonction. Dernière chose : ca ne fonctionne qu'AVEC IE !!! (Activex oblige !)
Source
- <html>
- <head>
- <script type="text/javascript">
- function Print_xl() {
- // déclaration de l'objet activeX
- var xlApp = new ActiveXObject("Excel.Application");
- // Silent-mode:
- //xlApp.Visible = true;
- xlApp.DisplayAlerts = false;
- var xlBook = xlApp.Workbooks.Add(); // déclaration du classeur
- xlBook.worksheets("feuil1").activate;
- var xlSheet = xlBook.activeSheet;// déclaration de la feuille
- xlSheet.Name="JavaScript Export to Excel";//on peu nommer le feuille
- //Declarations des constantes utilisées dans l'activex
- // les alignements dans les cellules
- var xlVAlignBottom = -4107;
- var xlVAlignTop = -4160;
- var xlVAlignCenter = -4108;
- var xlVAlignDistributed = -4117;
- var xlVAlignJustify = -4130;
-
- var xlHAlignCenter = -4108;
- var xlHAlignCenterAcrossSelection = 7;
- var xlHAlignDistributed = -4117;
- var xlHAlignFill = 5;
- var xlHAlignGeneral = 1;
- var xlHAlignJustify = -4130;
- var xlHAlignLeft = -4131;
- var xlHAlignRight = -4152;
-
- // les bordures des cellules
- var xlSolid=1;
-
- var xlContinuous = 1;
- var xlThin = 2;
- // les cotés des cellules
- var xlBottom = -4107;
- var xlLeft = -4131;
- var xlTop = -4160;
- var xlRight =-4152;
- // orientation de la page
- var xlPortrait=1;
-
- // on stock les lignes du tableau html dans un tableau de données. on aura ainsi le nombre de lignes
- var rows = tableau.getElementsByTagName("tr");
- var columns = 4;// parce que mon tableau a 4 colonnes
- var data = tableau.getElementsByTagName("td"); // les données du tableau html sont stockées dans data
-
- //Mise en forme de l'entete
- //ligne 1 et 2 hautes de 20 px
- xlSheet.Rows(1).RowHeight = 20;
- xlSheet.Rows(2).RowHeight = 20;
- //Fusion des cellules A1 et A2
- xlSheet.Range(xlSheet.Cells(2, 1),xlSheet.Cells(1,1)).mergecells=true;
- //xlSheet.Range("A1:A2").Select;
- // Insertion d'un logo en haut et a gauche de la feuille
- // ce logo est dans le meme dossier que la page courante
- var chemin=document.referrer;// on récupère le chemin d'accés au la page courante et son nom
- chemin=chemin.substring(0,chemin.lastIndexOf("/")+1); // on ne garde que le chemin
- xlSheet.Pictures.Insert (chemin +"votrelogo.jpg");
- // on modifie la taille du logo
- xlSheet.Pictures.ShapeRange.LockAspectRatio = true;
- xlSheet.Pictures.ShapeRange.Height = 27.75;
- xlSheet.Pictures.ShapeRange.Width = 110.25;
- xlSheet.Pictures.ShapeRange.Rotation = "0";
- // on le place précisement à 9 points du haut gauche
- xlSheet.Pictures.ShapeRange.Top=xlSheet.Pictures.ShapeRange.Top+9;
- // et 39 du coté gauche xlSheet.Pictures.ShapeRange.Left=xlSheet.Pictures.ShapeRange.Left+39;
-
- // Recup des textes d'entete du tableau HTML pour les mettres dans les cellules
- xlSheet.Cells(1, 4).Value = data[1].innerText;;
- xlSheet.Cells(1, 4).VerticalAlignment = xlVAlignCenter;// alignement centrer vertical dans la cellule
- xlSheet.Cells(1, 4).HorizontalAlignment = xlHAlignRight; // et centrer horizontal
- xlSheet.Cells(1, 4).Font.Size = 9; // taille de police 9
- xlSheet.Cells(1, 4).Font.Bold = "False" ;// pas de mise en gras
-
- xlSheet.Cells(2, 4).Value = data[3].innerText;
- xlSheet.Cells(2, 4).VerticalAlignment = xlVAlignCenter;
- xlSheet.Cells(2, 4).HorizontalAlignment = xlHAlignCenter;
- xlSheet.Cells(2, 4).Interior.ColorIndex = 5;
- xlSheet.Cells(2, 4).Interior.Pattern = xlSolid ;
- xlSheet.Cells(2, 4).Font.ColorIndex = 2;
- xlSheet.Cells(2, 4).Font.Size = 12;
- xlSheet.Cells(2, 4).Font.Bold = "True";
-
-
- xlSheet.Range("B1:D1").Mergecells=true;
- xlSheet.Range("B2:C2").Mergecells=true;
- xlSheet.Cells(3, 1).Value = data[4].innerText;
- xlSheet.Cells(3, 1).Font.Bold = "True";
-
- xlSheet.Cells(3, 2).Value = data[5].innerText;
- xlSheet.Cells(3, 2).Font.Bold = "True" ;
- xlSheet.Cells(3, 2).Interior.ColorIndex = 6;
- xlSheet.Cells(3, 2).Interior.Pattern = xlSolid ;
-
-
-
- xlSheet.Columns("B").WrapText = "True";
- xlSheet.Columns("B").VerticalAlignment = xlVAlignCenter;
-
-
- xlSheet.Cells(3, 3).Value = data[6].innerText;;
- xlSheet.Cells(3, 3).Font.Bold = "True";
- xlSheet.Cells(3, 3).Interior.ColorIndex = 6 ;
- xlSheet.Cells(3, 3).Interior.Pattern = xlSolid ;
-
-
- xlSheet.Cells(2, 2).Value = data[2].innerText;;
- xlSheet.Cells(2, 2).VerticalAlignment = xlVAlignCenter;
- xlSheet.Cells(2, 2).Font.Bold = "False";
-
-
- xlSheet.Columns("A").ColumnWidth = 50;
- xlSheet.Columns("A").VerticalAlignment = xlVAlignCenter;
-
-
- xlSheet.Columns("B").ColumnWidth = 15;
- xlSheet.Columns("B").VerticalAlignment = xlVAlignCenter;
- xlSheet.Columns("B").HorizontalAlignment = xlHAlignCenter;
-
- xlSheet.Columns("C").ColumnWidth = 15 ;
- xlSheet.Columns("C").VerticalAlignment = xlVAlignCenter;
- xlSheet.Columns("C").HorizontalAlignment = xlHAlignCenter;
- xlSheet.Columns("C").WrapText = "True";
-
-
-
- xlSheet.Columns("D").VerticalAlignment = xlVAlignTop;
- xlSheet.Columns("D").ColumnWidth = 50 ;
- xlSheet.Columns("D").WrapText = "True";
-
-
- xlSheet.Cells(3, 4).Value = data[7].innerText;
- xlSheet.Cells(3, 4).Font.Bold = "True" ;
- xlSheet.Cells(3, 4).VerticalAlignment = xlVAlignCenter;
- xlSheet.Cells(3, 4).HorizontalAlignment = xlHAlignCenter;
- xlSheet.Cells(3, 4).Interior.ColorIndex = 6;
- xlSheet.Cells(3, 4).Interior.Pattern = xlSolid;
-
-
- //Parcourt du tableau pour compléter les cellules
- var d = 8;
- for (r=3;r<rows.length;r++) { // début en ligne 3 - a cause de l'entete du tableau
- for (c=1;c<=4;c++) { // parcours des colonnes
- var Maligne= rows[r].className;
- var Num_ligne=r+1;
- // mise en forme de la ligne en fonction de la classe de la ligne
- if ((Maligne=="ligne_ge") || (Maligne=="ligne_obs") || (Maligne=="ligne_obs_droite") ) {
- xlSheet.Range("a" + Num_ligne + ":" + "d" + Num_ligne).Mergecells=true;
- xlSheet.Cells(Num_ligne, 1).value = data[d].innerText;
- xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignRight;
- if (Maligne=="ligne_ge") {
- xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignLeft;
- xlSheet.Cells(Num_ligne, 1).Font.ColorIndex = 2;
- xlSheet.Cells(Num_ligne, 1).Font.Size = 12;
- xlSheet.Cells(Num_ligne, 1).Font.Bold = "False";
- xlSheet.Range("a" + Num_ligne + ":" + "d" + Num_ligne).Interior.ColorIndex = 3;
- xlSheet.Range("a" + Num_ligne + ":" + "d" + Num_ligne).Interior.Pattern = xlSolid;
- }
- if (Maligne=="ligne_obs") {
- xlSheet.Cells(Num_ligne, 1).VerticalAlignment = xlVAlignTop;
- xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignLeft;
- xlSheet.Cells(Num_ligne, 1).WrapText = "True";
- xlSheet.Cells(Num_ligne, 1).RowHeight = 90;
- xlSheet.Cells(Num_ligne, 1).Font.Name = "Arial";
- xlSheet.Cells(Num_ligne, 1).Font.Size = 8;
- xlSheet.Cells(Num_ligne, 1).Font.Italic = "True";
- }
- if (Maligne=="ligne_obs_droite") {
- xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignRight;
- xlSheet.Cells(Num_ligne, 1).Font.Name = "Arial";
- xlSheet.Cells(Num_ligne, 1).Font.Size = 8;
- xlSheet.Cells(Num_ligne, 1).Font.Italic = "True";
- }
- d=d+1;
- break;
- } else {
- xlSheet.cells(Num_ligne,c).value = data[d].innerText;
- }
- d = d + 1;
- }
- }
- // Encadrement du tableau
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlTop).LineStyle = xlContinuous;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlTop).Weight = xlThin;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlBottom).LineStyle = xlContinuous;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlBottom).Weight = xlThin;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlLeft).LineStyle = xlContinuous;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlLeft).Weight = xlThin;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlRight).LineStyle = xlContinuous;
- xlSheet.Range("a1:d" + Num_ligne).Borders(xlRight).Weight = xlThin;
-
- // parametrage de la mise en page
- xlSheet.PageSetup.PrintTitleRows = "";
- xlSheet.PageSetup.PrintTitleColumns = "";
- xlSheet.PageSetup.CenterHorizontally = 1;
- xlSheet.PageSetup.CenterVertically = 1;
- xlSheet.PageSetup.Orientation = xlPortrait;
- xlSheet.PageSetup.CenterHeader = "";
- xlSheet.PageSetup.CenterFooter = "";
- xlSheet.PageSetup.RightFooter = "";
- xlSheet.PageSetup.LeftMargin = xlApp.InchesToPoints(0);
- xlSheet.PageSetup.RightMargin = xlApp.InchesToPoints(0);
- xlSheet.PageSetup.TopMargin = xlApp.InchesToPoints(0.5);
- xlSheet.PageSetup.BottomMargin = xlApp.InchesToPoints(0.5);
- xlSheet.PageSetup.HeaderMargin = xlApp.InchesToPoints(0.25);
- xlSheet.PageSetup.FooterMargin = xlApp.InchesToPoints(0.25);
- xlSheet.PageSetup.PrintArea = "A1:D" + Num_ligne;
- // pour ajuster sur une seule page en hauteur et en largeur
- xlSheet.PageSetup.Zoom = false;
- xlSheet.PageSetup.FitToPagesWide = 1;
- xlSheet.PageSetup.FitToPagesTall = 1;
- //Impression sur l'imprimante par défaut
- xlSheet.PrintOut ;
- // On fait croire que l'on a sauvegardé le tableau
- // et éviter le message de demande de sauvegarde
- xlBook.Saved=true;
-
- // Nettoyage des variable
- CollectGarbage();
- //Sortie de Excel
- xlApp.Quit();
-
- }
- </script>
- </head>
- <body>
- <button onclick='Print_xl();'>Impression</button> <br /><br /><Table id='tableau' border='1px'>
- <Tr>
- <Td rowspan='2'><img border='0' width='220' height='55' src='logo.jpg'><Td colspan='3' align=Right><Font size='1'>du texte</font></Td></TR>
- <TR class='ligne_titre1'><Td colspan='2' align=center>Titre</Td><Td bgcolor='#0000FF'><B><Center><font color='#FFFFFF'><font size='4'>Titre</font></Center></B></Td></Tr>
- <TR class='ligne_titre2' align=center>
- <TD> Titre </TD>
- <TD bgcolor='yellow'> Titre</TD>
- <TD bgcolor='yellow'> Titre </TD>
- <TD bgcolor='yellow'> Titre </TD>
- </TR>
- <TR class='ligne_ge'><TD colspan='4' bgcolor='red'><font color='#FFFFFF'><Font face='Arial'>Regroupement 1</font></TD></TR>
- <TR class='ligne_acte'><TD>
- Ligne 1</td><TD align=center >yzeuia </td>
- <TD align=center >kdflmk </td>
- <TD align=Left > </td>
- </TR>
- <TR class='ligne_acte'><TD>Ligne2</td><TD align=center >kmdfksm </td>
- <TD align=center >dkfjsl </td>
- <TD align=Left > </td>
- </TR>
- <TR class='ligne_acte'><TD>Ligne3/td><TD align=center >dlmskflm </td>
- <TD align=center >dslmfksdml </td>
- <TD align=Left > </td>
- </TR>
- <TR class='ligne_acte'><TD>ligne4</td><TD align=center > </td>
- <TD align=center >jdlk </td>
- <TD align=Left >kmlgkmfdkgmdfkgmkgmkd kgdfmlkg mlkkg mk mk dmlkd gkmdflkgm k </td>
- </TR>
- <TR class='ligne_ge'><TD colspan='4' bgcolor='red'><font color='#FFFFFF'><Font face='Arial'>Autre regrgoupement</font></TD></TR>
- <TR class='ligne_acte'><TD>
- Ligne 1</td><TD align=center >70% </td>
- <TD align=center >kmdflkml </td>
- <TD align=Left > </td>
- </TR>
- <TR class='ligne_acte'><TD>Ligne 2</td><TD align=center >mdslfkmsdl </td>
- <TD align=center >flmsdkmlkf </td>
- <TD align=Left > </td>
- </TR>
- <TR class='ligne_acte'><TD>Ligne 3</td><TD align=center >mdlskfml </td>
- <TD align=center >dlkjslkd </td>
- <TD align=Left > </td>
- </TR>
- <TR class='ligne_acte'><TD>Ligne4</td><TD align=center >kdfmsl </td>
- <TD align=center >sdfdf </td>
- <TD align=Left > </td>
- </TR>
- <Tr class='ligne_obs_droite'><Td colspan='4' align='right'><p style='margin-top: 0; margin-bottom: 0'>du texte encore0</td></Tr>
- <Tr class='ligne_obs'><Td colspan='4'><p style='margin-top: 0; margin-bottom: 0'>et enfin du texte <B></p></td></Tr>
- </TABLE><BR>
-
- </body>
-
- </html>
<html>
<head>
<script type="text/javascript">
function Print_xl() {
// déclaration de l'objet activeX
var xlApp = new ActiveXObject("Excel.Application");
// Silent-mode:
//xlApp.Visible = true;
xlApp.DisplayAlerts = false;
var xlBook = xlApp.Workbooks.Add(); // déclaration du classeur
xlBook.worksheets("feuil1").activate;
var xlSheet = xlBook.activeSheet;// déclaration de la feuille
xlSheet.Name="JavaScript Export to Excel";//on peu nommer le feuille
//Declarations des constantes utilisées dans l'activex
// les alignements dans les cellules
var xlVAlignBottom = -4107;
var xlVAlignTop = -4160;
var xlVAlignCenter = -4108;
var xlVAlignDistributed = -4117;
var xlVAlignJustify = -4130;
var xlHAlignCenter = -4108;
var xlHAlignCenterAcrossSelection = 7;
var xlHAlignDistributed = -4117;
var xlHAlignFill = 5;
var xlHAlignGeneral = 1;
var xlHAlignJustify = -4130;
var xlHAlignLeft = -4131;
var xlHAlignRight = -4152;
// les bordures des cellules
var xlSolid=1;
var xlContinuous = 1;
var xlThin = 2;
// les cotés des cellules
var xlBottom = -4107;
var xlLeft = -4131;
var xlTop = -4160;
var xlRight =-4152;
// orientation de la page
var xlPortrait=1;
// on stock les lignes du tableau html dans un tableau de données. on aura ainsi le nombre de lignes
var rows = tableau.getElementsByTagName("tr");
var columns = 4;// parce que mon tableau a 4 colonnes
var data = tableau.getElementsByTagName("td"); // les données du tableau html sont stockées dans data
//Mise en forme de l'entete
//ligne 1 et 2 hautes de 20 px
xlSheet.Rows(1).RowHeight = 20;
xlSheet.Rows(2).RowHeight = 20;
//Fusion des cellules A1 et A2
xlSheet.Range(xlSheet.Cells(2, 1),xlSheet.Cells(1,1)).mergecells=true;
//xlSheet.Range("A1:A2").Select;
// Insertion d'un logo en haut et a gauche de la feuille
// ce logo est dans le meme dossier que la page courante
var chemin=document.referrer;// on récupère le chemin d'accés au la page courante et son nom
chemin=chemin.substring(0,chemin.lastIndexOf("/")+1); // on ne garde que le chemin
xlSheet.Pictures.Insert (chemin +"votrelogo.jpg");
// on modifie la taille du logo
xlSheet.Pictures.ShapeRange.LockAspectRatio = true;
xlSheet.Pictures.ShapeRange.Height = 27.75;
xlSheet.Pictures.ShapeRange.Width = 110.25;
xlSheet.Pictures.ShapeRange.Rotation = "0";
// on le place précisement à 9 points du haut gauche
xlSheet.Pictures.ShapeRange.Top=xlSheet.Pictures.ShapeRange.Top+9;
// et 39 du coté gauche xlSheet.Pictures.ShapeRange.Left=xlSheet.Pictures.ShapeRange.Left+39;
// Recup des textes d'entete du tableau HTML pour les mettres dans les cellules
xlSheet.Cells(1, 4).Value = data[1].innerText;;
xlSheet.Cells(1, 4).VerticalAlignment = xlVAlignCenter;// alignement centrer vertical dans la cellule
xlSheet.Cells(1, 4).HorizontalAlignment = xlHAlignRight; // et centrer horizontal
xlSheet.Cells(1, 4).Font.Size = 9; // taille de police 9
xlSheet.Cells(1, 4).Font.Bold = "False" ;// pas de mise en gras
xlSheet.Cells(2, 4).Value = data[3].innerText;
xlSheet.Cells(2, 4).VerticalAlignment = xlVAlignCenter;
xlSheet.Cells(2, 4).HorizontalAlignment = xlHAlignCenter;
xlSheet.Cells(2, 4).Interior.ColorIndex = 5;
xlSheet.Cells(2, 4).Interior.Pattern = xlSolid ;
xlSheet.Cells(2, 4).Font.ColorIndex = 2;
xlSheet.Cells(2, 4).Font.Size = 12;
xlSheet.Cells(2, 4).Font.Bold = "True";
xlSheet.Range("B1:D1").Mergecells=true;
xlSheet.Range("B2:C2").Mergecells=true;
xlSheet.Cells(3, 1).Value = data[4].innerText;
xlSheet.Cells(3, 1).Font.Bold = "True";
xlSheet.Cells(3, 2).Value = data[5].innerText;
xlSheet.Cells(3, 2).Font.Bold = "True" ;
xlSheet.Cells(3, 2).Interior.ColorIndex = 6;
xlSheet.Cells(3, 2).Interior.Pattern = xlSolid ;
xlSheet.Columns("B").WrapText = "True";
xlSheet.Columns("B").VerticalAlignment = xlVAlignCenter;
xlSheet.Cells(3, 3).Value = data[6].innerText;;
xlSheet.Cells(3, 3).Font.Bold = "True";
xlSheet.Cells(3, 3).Interior.ColorIndex = 6 ;
xlSheet.Cells(3, 3).Interior.Pattern = xlSolid ;
xlSheet.Cells(2, 2).Value = data[2].innerText;;
xlSheet.Cells(2, 2).VerticalAlignment = xlVAlignCenter;
xlSheet.Cells(2, 2).Font.Bold = "False";
xlSheet.Columns("A").ColumnWidth = 50;
xlSheet.Columns("A").VerticalAlignment = xlVAlignCenter;
xlSheet.Columns("B").ColumnWidth = 15;
xlSheet.Columns("B").VerticalAlignment = xlVAlignCenter;
xlSheet.Columns("B").HorizontalAlignment = xlHAlignCenter;
xlSheet.Columns("C").ColumnWidth = 15 ;
xlSheet.Columns("C").VerticalAlignment = xlVAlignCenter;
xlSheet.Columns("C").HorizontalAlignment = xlHAlignCenter;
xlSheet.Columns("C").WrapText = "True";
xlSheet.Columns("D").VerticalAlignment = xlVAlignTop;
xlSheet.Columns("D").ColumnWidth = 50 ;
xlSheet.Columns("D").WrapText = "True";
xlSheet.Cells(3, 4).Value = data[7].innerText;
xlSheet.Cells(3, 4).Font.Bold = "True" ;
xlSheet.Cells(3, 4).VerticalAlignment = xlVAlignCenter;
xlSheet.Cells(3, 4).HorizontalAlignment = xlHAlignCenter;
xlSheet.Cells(3, 4).Interior.ColorIndex = 6;
xlSheet.Cells(3, 4).Interior.Pattern = xlSolid;
//Parcourt du tableau pour compléter les cellules
var d = 8;
for (r=3;r<rows.length;r++) { // début en ligne 3 - a cause de l'entete du tableau
for (c=1;c<=4;c++) { // parcours des colonnes
var Maligne= rows[r].className;
var Num_ligne=r+1;
// mise en forme de la ligne en fonction de la classe de la ligne
if ((Maligne=="ligne_ge") || (Maligne=="ligne_obs") || (Maligne=="ligne_obs_droite") ) {
xlSheet.Range("a" + Num_ligne + ":" + "d" + Num_ligne).Mergecells=true;
xlSheet.Cells(Num_ligne, 1).value = data[d].innerText;
xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignRight;
if (Maligne=="ligne_ge") {
xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignLeft;
xlSheet.Cells(Num_ligne, 1).Font.ColorIndex = 2;
xlSheet.Cells(Num_ligne, 1).Font.Size = 12;
xlSheet.Cells(Num_ligne, 1).Font.Bold = "False";
xlSheet.Range("a" + Num_ligne + ":" + "d" + Num_ligne).Interior.ColorIndex = 3;
xlSheet.Range("a" + Num_ligne + ":" + "d" + Num_ligne).Interior.Pattern = xlSolid;
}
if (Maligne=="ligne_obs") {
xlSheet.Cells(Num_ligne, 1).VerticalAlignment = xlVAlignTop;
xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignLeft;
xlSheet.Cells(Num_ligne, 1).WrapText = "True";
xlSheet.Cells(Num_ligne, 1).RowHeight = 90;
xlSheet.Cells(Num_ligne, 1).Font.Name = "Arial";
xlSheet.Cells(Num_ligne, 1).Font.Size = 8;
xlSheet.Cells(Num_ligne, 1).Font.Italic = "True";
}
if (Maligne=="ligne_obs_droite") {
xlSheet.Cells(Num_ligne, 1).HorizontalAlignment = xlHAlignRight;
xlSheet.Cells(Num_ligne, 1).Font.Name = "Arial";
xlSheet.Cells(Num_ligne, 1).Font.Size = 8;
xlSheet.Cells(Num_ligne, 1).Font.Italic = "True";
}
d=d+1;
break;
} else {
xlSheet.cells(Num_ligne,c).value = data[d].innerText;
}
d = d + 1;
}
}
// Encadrement du tableau
xlSheet.Range("a1:d" + Num_ligne).Borders(xlTop).LineStyle = xlContinuous;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlTop).Weight = xlThin;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlBottom).LineStyle = xlContinuous;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlBottom).Weight = xlThin;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlLeft).LineStyle = xlContinuous;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlLeft).Weight = xlThin;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlRight).LineStyle = xlContinuous;
xlSheet.Range("a1:d" + Num_ligne).Borders(xlRight).Weight = xlThin;
// parametrage de la mise en page
xlSheet.PageSetup.PrintTitleRows = "";
xlSheet.PageSetup.PrintTitleColumns = "";
xlSheet.PageSetup.CenterHorizontally = 1;
xlSheet.PageSetup.CenterVertically = 1;
xlSheet.PageSetup.Orientation = xlPortrait;
xlSheet.PageSetup.CenterHeader = "";
xlSheet.PageSetup.CenterFooter = "";
xlSheet.PageSetup.RightFooter = "";
xlSheet.PageSetup.LeftMargin = xlApp.InchesToPoints(0);
xlSheet.PageSetup.RightMargin = xlApp.InchesToPoints(0);
xlSheet.PageSetup.TopMargin = xlApp.InchesToPoints(0.5);
xlSheet.PageSetup.BottomMargin = xlApp.InchesToPoints(0.5);
xlSheet.PageSetup.HeaderMargin = xlApp.InchesToPoints(0.25);
xlSheet.PageSetup.FooterMargin = xlApp.InchesToPoints(0.25);
xlSheet.PageSetup.PrintArea = "A1:D" + Num_ligne;
// pour ajuster sur une seule page en hauteur et en largeur
xlSheet.PageSetup.Zoom = false;
xlSheet.PageSetup.FitToPagesWide = 1;
xlSheet.PageSetup.FitToPagesTall = 1;
//Impression sur l'imprimante par défaut
xlSheet.PrintOut ;
// On fait croire que l'on a sauvegardé le tableau
// et éviter le message de demande de sauvegarde
xlBook.Saved=true;
// Nettoyage des variable
CollectGarbage();
//Sortie de Excel
xlApp.Quit();
}
</script>
</head>
<body>
<button onclick='Print_xl();'>Impression</button> <br /><br /><Table id='tableau' border='1px'>
<Tr>
<Td rowspan='2'><img border='0' width='220' height='55' src='logo.jpg'><Td colspan='3' align=Right><Font size='1'>du texte</font></Td></TR>
<TR class='ligne_titre1'><Td colspan='2' align=center>Titre</Td><Td bgcolor='#0000FF'><B><Center><font color='#FFFFFF'><font size='4'>Titre</font></Center></B></Td></Tr>
<TR class='ligne_titre2' align=center>
<TD> Titre </TD>
<TD bgcolor='yellow'> Titre</TD>
<TD bgcolor='yellow'> Titre </TD>
<TD bgcolor='yellow'> Titre </TD>
</TR>
<TR class='ligne_ge'><TD colspan='4' bgcolor='red'><font color='#FFFFFF'><Font face='Arial'>Regroupement 1</font></TD></TR>
<TR class='ligne_acte'><TD>
Ligne 1</td><TD align=center >yzeuia </td>
<TD align=center >kdflmk </td>
<TD align=Left > </td>
</TR>
<TR class='ligne_acte'><TD>Ligne2</td><TD align=center >kmdfksm </td>
<TD align=center >dkfjsl </td>
<TD align=Left > </td>
</TR>
<TR class='ligne_acte'><TD>Ligne3/td><TD align=center >dlmskflm </td>
<TD align=center >dslmfksdml </td>
<TD align=Left > </td>
</TR>
<TR class='ligne_acte'><TD>ligne4</td><TD align=center > </td>
<TD align=center >jdlk </td>
<TD align=Left >kmlgkmfdkgmdfkgmkgmkd kgdfmlkg mlkkg mk mk dmlkd gkmdflkgm k </td>
</TR>
<TR class='ligne_ge'><TD colspan='4' bgcolor='red'><font color='#FFFFFF'><Font face='Arial'>Autre regrgoupement</font></TD></TR>
<TR class='ligne_acte'><TD>
Ligne 1</td><TD align=center >70% </td>
<TD align=center >kmdflkml </td>
<TD align=Left > </td>
</TR>
<TR class='ligne_acte'><TD>Ligne 2</td><TD align=center >mdslfkmsdl </td>
<TD align=center >flmsdkmlkf </td>
<TD align=Left > </td>
</TR>
<TR class='ligne_acte'><TD>Ligne 3</td><TD align=center >mdlskfml </td>
<TD align=center >dlkjslkd </td>
<TD align=Left > </td>
</TR>
<TR class='ligne_acte'><TD>Ligne4</td><TD align=center >kdfmsl </td>
<TD align=center >sdfdf </td>
<TD align=Left > </td>
</TR>
<Tr class='ligne_obs_droite'><Td colspan='4' align='right'><p style='margin-top: 0; margin-bottom: 0'>du texte encore0</td></Tr>
<Tr class='ligne_obs'><Td colspan='4'><p style='margin-top: 0; margin-bottom: 0'>et enfin du texte <B></p></td></Tr>
</TABLE><BR>
</body>
</html>
Conclusion
Voilà amusez vous bien avec EXCEL et JAVA.
Historique
- 12 juillet 2010 13:48:03 :
- Ajout d'un lien vers le source de base original
- 15 juillet 2010 12:02:59 :
- Ajout de quels commentaires et un peu d'HTML
- 16 juillet 2010 13:26:51 :
- Pas de mise à jour, mais seulement un complément.
Contrôlez dans les paramètres avancés d'IE que les options en rapport avec l'exécution des activex sont autorisées. Sinon vous aurez droit au message "création de l'objet impossible !!"
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
ouverture de fichier excel en javascript [ par joan ]
Bonjour,Je développe actuellement une application en ASP dans laquelle je dois ouvrir un fichier excel que je pourrais modifier et enregistrer sur le
Numéroter des pages lors d'une impression [ par lock07 ]
Bonjour à tous, j'ai un petit problème javascript.Je suis en train de faire un site de vente en ligne et je travaille sur l'édition des factures. J'ai
Problème pour ouvrir Excel en asp/javascript [ par jakata ]
Bonjour,j'ai un petit problème qui m'énerve fortement. Je n'arrive pas à ouvrir Excel.Voici mon code: <%@LANGUAGE=JavaScript%> &l
formater une colonne Excel [ par jakata ]
Bonjour,j'ai un petit souci. J'ai fait une fonction javascript qui rempli une page Excel, jusque là pas de problème.Le fait est que quand je
Impression Javascript [ par syl2 ]
Bonsoir,depuis quelques jour, j'essaye de me lancer dans l'impression d'une page en Javascript, mais sans réel résultat. En effet, si vous regarder mo
problèmes d'impression [ par billy21121 ]
Bonjour a tous, Je voudrais simplement un petit renseignement à propos des impressions en javascript. Est il possible de forcer les propriét
impression paramétrée [ par Niles ]
hello, Je ne suis pas un pro du javascript, en fait je ne connait presque rien à la conception web, je programe en C++ et en Windev. Anyway: je do
Adaptation formulaire en javascript... [ par sylvie86 ]
j'arrive pas à adapter vos scripts javascript sur mon formulaire pour la vérification des champs... est-ce que qqun pourrait m'aider ? Je su
javascript & Excel [ par RugbyOne ]
Bonjour, Je souhaite pouvoir ouvrir un fichier Excel à partir d'un lien ! Jusque là pas de problème... Dans ce fichier Excel, j'ai une colonne qui s
Erreur Javascript lors de l'impression [ par darb66 ]
Bonjour,J'ai une erreur javascript qui apparait lorsque j'essaie d'imprimer une page depuis IExplorer (en utilisant les functionalites du navigateur f
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
UTILISER UN .JSUTILISER UN .JS par zaikoe
Cliquez pour lire la suite par zaikoe
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|