Précédent   Forum des professionnels en informatique > PHP > Langage > Fichiers
Fichiers Forum d'entraide sur les fichiers avec PHP. Avant de poster -> FAQ fichiers et Sources fichiers
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 21/04/2011, 16h44   #1
Futur Membre du Club
 
Homme
Inscription : mars 2009
Messages : 19
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : mars 2009
Messages : 19
Points : 16
Points : 16
Par défaut Problème de close() pour un fichier Excel.

Bonjour à toutes et à tous.

Je développe un site actuellement pour un client, et celui-ci a besoin d'extraire une partie de sa BDD dans un fichier Excel.

Je me suis donc tourné vers la petite librairie php_writeexcel mais celle-ci me donne quelques fils à retordre.

En effet, même dans leurs codes exemple, le script plante sur

censé fermer le fichier temporaire du classeur Excel nouvellement créé.

Voici mon code complet :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
<?php
 
set_time_limit(1000);
 
require_once "php_writeexcel-0.3.0/class.writeexcel_workbook.inc.php";
require_once "php_writeexcel-0.3.0/class.writeexcel_worksheet.inc.php";
require_once ("../config.php");
 
$fname = tempnam("/tmp", "invitation.xls");
$workbook = &new writeexcel_workbook($fname);
$worksheet =& $workbook->addworksheet();
 
# Set the column width for columns 1, 2, 3 and 4
$worksheet->set_column(0, 3, 15);
 
# Create a format for the column headings
$header =& $workbook->addformat();
$header->set_bold();
 
# Create a format for the stock volume
$f_tel =& $workbook->addformat();
$f_tel->set_align('left');
$f_tel->set_num_format('0#########');
 
# Write out the data
$worksheet->write(0, 0, 'Nom', $header);
$worksheet->write(0, 1, 'Entreprise',   $header);
$worksheet->write(0, 2, 'Adresse',  $header);
$worksheet->write(0, 3, 'Telephone',  $header);
$worksheet->write(0, 4, 'Email',  $header);
$worksheet->write(0, 5, 'Metier/Activite',  $header);
$worksheet->write(0, 6, 'Apres-Midi',  $header);
$worksheet->write(0, 7, 'Cocktail',  $header);
 
 
$bdd = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $bdd);
 
$dbres = mysql_query("SELECT * FROM inauguration ORDER BY id", $bdd);
 
$ligne = 1;
 
while($row = mysql_fetch_assoc($dbres)) {
	$worksheet->write($ligne, 0, $row["sexe"]." ".$row["nom"]." ".$row["prenom"]);
	$worksheet->write($ligne, 1, $row["entreprise"]);
	$worksheet->write($ligne, 2, $row["rue"]." ".$row["cp"]." ".$row["ville"]);
	$worksheet->write($ligne, 3, $row["telephone"], $f_tel);
	$worksheet->write($ligne, 4, $row["mail"]);
	$worksheet->write($ligne, 5, $row["activite"]);
	$worksheet->write($ligne, 6, $row["apresMidi"]);
	$worksheet->write($ligne, 7, $row["cocktail"]);
	$ligne++;
}
 
$workbook->close();
 
header("Content-Type: application/x-msexcel; name=\"invitation.xls\"");
header("Content-Disposition: inline; filename=\"invitation.xls\"");
 
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);
 
?>
J'ai tenté en vain de chercher une réponse à ce problème, mais je n'ai vu nulle personne sur Internet étant tombé dessus.

Si par hasard, l'un de vous trouve la solution de ce problème (ou me propose une toute autre solution ), je lui en serais très reconnaissant =)

Taz.
Bouffe est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/04/2011, 17h23   #2
Membre Expert
 
Inscription : avril 2006
Messages : 1 338
Détails du profil
Informations personnelles :
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations forums :
Inscription : avril 2006
Messages : 1 338
Points : 1 315
Points : 1 315
pour une autre solution des exports csv de ta base ne sont pas suffisant pour ton client..?

sinon: http://g-ernaelsten.developpez.com/tutoriels/excel2007/
__________________
Stay in Bed .. Save Energy
boo64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/04/2011, 09h13   #3
Futur Membre du Club
 
Homme
Inscription : mars 2009
Messages : 19
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : mars 2009
Messages : 19
Points : 16
Points : 16
Après quelques nouveaux essais infructueux pour l'exporter en XLS (ça fait moins peur au client qu'un fichier CSV qu'il ne connait pas), j'ai tout de même opté pour la solution du CSV.

Merci de ton aide
Bouffe est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h27.


 
 
 
 
Partenaires

Hébergement Web