Bonjour.
voici mon code d'export de données MySql vers un fichier excel.
Je suis dans une feuille Excel, je clique sur un bouton Macro qui appelle ce code PHP d'import.
Mon souci, c'est que les données ne se copient pas dans la feuille active,
d'où je lance pourtant la macro, je ne sais pas comment lui indiquer la bonne feuille.
<?php
# Get bug rows according to the current filter
$id_project = $_GET["projectid"];
$query = "SELECT distinct(t1.bug_id), t1.date_modified, t1.old_value, t1.new_value FROM t1 INNER JOIN t2 ON t1.bug_id = t2.id WHERE t2.project_id = ".$id_project ;
$result = @db_query( $query );
$num_files = db_num_rows( $result );
$t_filename = "test_export_csv.csv";
# Send headers to browser to activate mime loading
# Make sure that IE can download the attachments under https.
header( 'Pragma: public' );
header( 'Content-Type: text/plain; name=' . $t_filename );
header( 'Content-Transfer-Encoding: BASE64;' );
# Added Quotes (") around file name.
header( 'Content-Disposition: attachment; filename="' . $t_filename .'"');
# export the rows
for ($i=0;$i<$num_files;$i++) {
$t_row = db_fetch_array( $result );
echo "\"".$t_row[ "bug_id" ]."\"" ;
echo ",";
echo "\"".$t_row[ "date_modified" ]."\"" ;
echo ",";
echo "\"".$t_row[ "old_value" ]."\"" ;
echo ",";
echo "\"".$t_row[ "new_value" ]."\"" ;
echo "\n";
}
?>
Partager