Bonjour,
J'aimerai savoir si vous connaissez des scritps d'export de résultats de requetes sql dans des fichiers Excel
Je cherche un script simple d'installation, pour éviter tout problème lors de l'intégration sur un serveur
Merci d'avance
<?php
$name = "fichier-".date("ymd-Hi");
header( 'Pragma: public' );
header( 'Content-Type: application/excel' );
header( 'Content-Disposition: attachment; filename="'.$name.'.xls"' );
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="Classeur2_fichiers/filelist.xml">
<link rel=Edit-Time-Data href="Classeur2_fichiers/editdata.mso">
<link rel=OLE-Object-Data href="Classeur2_fichiers/oledata.mso">
<style>
<!--
table {mso-displayed-decimal-separator:"\,"; mso-displayed-thousand-separator:" ";}
@page {margin:.98in .79in .98in .79in; mso-header-margin:.49in; mso-footer-margin:.49in;}
tr {mso-height-source:auto;}
col {mso-width-source:auto;}
br {mso-data-placement:same-cell;}
.style0 {mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap;
mso-rotate:0; mso-background-source:auto; mso-pattern:auto; color:windowtext;
font-size:8.0pt; font-weight:400; font-style:normal; text-decoration:none;
font-family:Arial; mso-generic-font-family:auto; mso-font-charset:0;
border:none; mso-protection:locked visible; mso-style-name:Normal;
mso-style-id:0;}
td {mso-style-parent:style0; padding-top:1px; padding-right:1px; padding-left:1px;
mso-ignore:padding; color:windowtext; font-size:8.0pt; font-weight:400;
font-style:normal; text-decoration:none; font-family:Arial; mso-generic-font-family:auto;
mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom;
border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible;
white-space:nowrap; mso-rotate:0;}
.xl24 {mso-style-parent:style0; mso-number-format:"\@";}
.xl25 {mso-style-parent:style0; font-weight:700; mso-number-format:"\@";}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Feuil1</x:Name>
<x:WorksheetOptions>
<x:DefaultColWidth>10</x:DefaultColWidth>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:RangeSelection>$A$1:$A$1</x:RangeSelection>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>8850</x:WindowHeight>
<x:WindowWidth>18795</x:WindowWidth>
<x:WindowTopX>120</x:WindowTopX>
<x:WindowTopY>135</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<table x:str border=0 cellpadding=0 cellspacing=0 width=160 style='border-collapse:collapse;table-layout:fixed;width:120pt'>
<tr height=17 style='height:12.75pt'>
<?php
//Affichage des entêtes de colonne
while (list($key, $val) = each($cols)) {
echo "<td height=17 class=xl25 width=80 style='height:12.75pt;width:60pt'>$val</td>";
}
?>
</tr>
<?
//Affichage des valeurs dans les cellules
while (list($key, $ligne) = each($rs)) {
set_time_limit(30);
echo " <tr height=17 style='height:12.75pt'>";
while (list($key, $val) = each($ligne)) {
echo "<td height=17 class=xl24 width=80 style='height:12.75pt;width:60pt'>$val</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
Seul bémol. Malgré son extension xls, ce n'est pas un vrai fichier Excel. Une fois que le fichier est ouvert dans Excel, il faut dire à l'utilisateur de faire "enregistrer sous ..." format xls si par exemple il veut faire un lien odbc.