begin process at 2012 05 29 01:50:10
  Trouver un code source :
 
dans
 
Accueil > Forum > 

PHP

 > 

Divers

 > 

Divers

 > 

exporter un tableau html en Excel


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

exporter un tableau html en Excel

jeudi 23 octobre 2008 à 16:44:44 | exporter un tableau html en Excel

matrix154

Salut tout le monde!

j'ai un problème pour exposrter un tableau html (creé par PHP) en Excel!
Avec un script PHP contenant un <form> pour parcourir et séléctioner le fichier à lire. En cliquant sur le boutton le fichier est lu et filtrer comme je veux.
Dans ce resultat il y a un 2ème boutton pour l'éxporter. En cliquant ce 2ème boutton une fenêtre apparait (comme je veux) pour télécharger/sauvegarder ce fichier d'excel, auf que cet Excel est vide:
j'éspère que vous pourriez m'aider!

voici mon code:

1. main page:
<form enctype="multipart/form-data" action="action_browse.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="5000">
Choose a file to upload: <input name="meinedatei" type="file"><br>
<input type="submit" name="SUBMIT" value="upload & filter">
</form>

2. action_browse.php:
<?
if ($_FILES[meinedatei] !="")
{
    @copy($_FILES[meinedatei][tmp_name], "./".$_FILES[meinedatei][name]) or die("Couldn't copy the file.");
}
else
{
    die(mysql_error());
}
$temp_datei = $_FILES[meinedatei][tmp_name];
$dateiname = $_FILES[meinedatei][name];
echo "temporerer Name mit Pfad: "; print ($temp_datei); echo "<br>";
echo "Dateiname: "; print ($dateiname); echo "<br>";
$path = $_FILES[meinedatei][tmp_name];
$open = fopen($path,"r+");
echo "<form name='exporter' action='export.php' method='post'>
    <input type='submit' name='SUBMIT' value='als Excel exportieren'><p>";
echo "<table width='75%' border='1'>
            <tr><td></td>
            <td bgcolor='#FED2AA' align='center'><b>ACL Name</b></td>
            <td bgcolor='#FED2AA' align='center'><b>Rule</b></td>
            <td bgcolor='#FED2AA' align='center'><b>Protocol</b></td>
            <td bgcolor='#FED2AA' colspan='2' align='center'><b>Source IP / Netmask</b></td>
            <td bgcolor='#FED2AA' colspan='2' align='center'><b>Destination IP / Netmask</b></td>
            <td bgcolor='#FED2AA' colspan='2' align='center'><b>Service</b></td></tr>";
        while(!feof($open))
        {
            $zeile = fgets($open,255);
            $hostname = "/hostname/iU";
            $remark = "/remark/iU";
            $extended = "/extended/iU";
            $permit = "/permit/iU";
            $deny = "/deny/iU";
            if (preg_match_all($remark,$zeile,$matches,PREG_SET_ORDER))
            {
                $wort = preg_split("/ /", $zeile, -1, PREG_SPLIT_NO_EMPTY);
                echo "<tr><td colspan='10' bgcolor='#DDDDDD' align='left'>$wort[2] $wort[3] $wort[4] $wort[5] $wort[6] $wort[7] $wort[8] $wort[9] $wort[10]</td></tr>";
            }
            //ASA
            elseif     (preg_match_all($extended,$zeile,$matches,PREG_SET_ORDER))
            {
                $i++;
                $wort = preg_split("/ /", $zeile, -1, PREG_SPLIT_NO_EMPTY);
                if ("$wort[5]" == "$wort[6]")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8] $wort[9]</td></tr>";
                elseif ("$wort[5]" == "any")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8]</td>
                    <td bgcolor='#AFAFEF'>$wort[9] $wort[10]</td></tr>";
                elseif ("$wort[7]" == "any")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8]</td>
                    <td bgcolor='#AFAFEF'>$wort[9] $wort[10]</td></tr>";
                else
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8]</td>
                    <td bgcolor='#AFAFEF'>$wort[9]</td>
                    <td bgcolor='#AFAFEF'>$wort[10] $wort[11]";
            }
            //PIX
            elseif     (preg_match_all($permit,$zeile,$matches,PREG_SET_ORDER))
            {
                $i++;
                $wort = preg_split("/ /", $zeile, -1, PREG_SPLIT_NO_EMPTY);
                if ("$wort[4]" == "$wort[5]")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7] $wort[8]</td></tr>";
                elseif ("$wort[4]" == "any")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8] $wort[9]</td></tr>";
                elseif ("$wort[6]" == "any")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8] $wort[9]</td></tr>";
                else
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8]</td>
                    <td bgcolor='#AFAFEF'>$wort[9] $wort[10]";
            }
            elseif     (preg_match_all($deny,$zeile,$matches,PREG_SET_ORDER))
            {
                $i++;
                $wort = preg_split("/ /", $zeile, -1, PREG_SPLIT_NO_EMPTY);
                if ("$wort[4]" == "$wort[5]")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7] $wort[8]</td></tr>";
                elseif ("$wort[4]" == "any")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8] $wort[9]</td></tr>";
                elseif ("$wort[6]" == "any")
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8] $wort[9]</td></tr>";
                else
                echo "<tr><td bgcolor='#AFAFEF'>$i</td>
                    <td bgcolor='#AFAFEF'>$wort[1]</td>
                    <td bgcolor='#AFAFEF'>$wort[2]</td>
                    <td bgcolor='#AFAFEF'>$wort[3]</td>
                    <td bgcolor='#AFAFEF'>$wort[4]</td>
                    <td bgcolor='#AFAFEF'>$wort[5]</td>
                    <td bgcolor='#AFAFEF'>$wort[6]</td>
                    <td bgcolor='#AFAFEF'>$wort[7]</td>
                    <td bgcolor='#AFAFEF'>$wort[8]</td>
                    <td bgcolor='#AFAFEF'>$wort[9] $wort[10]";
            }
        }
        echo "</td></tr></table>";
        fclose ($open);
        echo "</p><input type='submit' name='SUBMIT' value='als Excel exportieren'>
        </form>";
?>

et dérnièrement voici l'export.php:
<?php
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Export_ACL.xls");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unbenanntes Dokument</title>
</head>
<body>
<?php
include ("action_browse.php");
?>
</body>
</html>
jeudi 23 octobre 2008 à 17:03:40 | Re : exporter un tableau html en Excel

fregolo52

Membre Club
salut,

J'ai repris un code existant. En fait, ce que lit une base MySQL (dans ton cas on dira que tu scrute ton tableau) et stocke les données dans un fichier temporaire au format CSV (données séparée par des ; ).

Voici le chargement du fichier par excel :
        header("Content-disposition: inline; filename=$file");
        header("Content-Type: application/force-download");
        //header("Content-Type: application/ms-excel");
        header("Content-Transfer-Encoding: application/octet-stream\n"); // Surtout ne pas enlever le \n
        header("Content-Length: ".filesize("./temp/" . $file));
        header("Pragma: no-cache");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
        header("Expires: 0");
        readfile("./temp/" . $file);


J'espère que ca t'aidera.
jeudi 23 octobre 2008 à 17:51:53 | Re : exporter un tableau html en Excel

matrix154

merci fregolo52 pour la réponse rapide,

éxactement! je lis le fichier temporairement et je traitement directement à une facon que je lis ligne par ligne, je filtre les ligne que j'en ai besoin, ensuite je partage chaque phrase/ligne voulu pour que je les mettres dans le tableau.

Avec le code que tu m'as donné ca ne marche pas (j'ai remplacé $file par la variable temporaire "$temp_datei")
il me propose de sauvegarder le fichier "export.php" même et ce dérnier contient ces lignes suivantes:

<br />
<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for ./temp/ in <b>D:\xampp\htdocs\pndh-final\export.php</b> on line <b>8</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\pndh-final\export.php:8) in <b>D:\xampp\htdocs\pndh-final\export.php</b> on line <b>8</b><br />
mardi 28 octobre 2008 à 12:08:12 | Re : exporter un tableau html en Excel

matrix154

salut!!

n'y-a-t-il pas des ideés??


Cette discussion est classée dans : echo, preg, zeile, elseif, wort


Répondre à ce message

Sujets en rapport avec ce message

inserer une date dans la table [ par ikramta ] salut tout le mande .j'ai un formulaire qui contien:saisir la date:<input type="text" size="4"  name Problème avec mon script [ par azep ] Bonjour, je ne trouve pas d'erreur dans mon code php,Pouvez vous m'aider s-il vous plait ?Voici mon code php : $p Problème [ par azep ] Bonjour, j'ai un problème avec mon inscription ^^Voici mon problème, quand j'oublie un champ, sa marche et sa me met "Vous avez oublié le champs ..." comment utiliser preg_split() ? [ par Mastronic ] Bonjour,  comment utiliser preg_split() ?j'ai ecris cette example qui me retourne  "AZERTYU" au lieux de R... pourquoi ? il y a t'il une erreur de syn PHP mettre une condition dans une boucle while [ par jibtothenight ] Bojour,je suis débutant en php et je n'arrive pas à intégrer ma condition dans ma boucle while.L'execution du fichier me met une erreur : syntax error affiche plus ma bdd quand je supp une entrée [ par jphilippev ] bonjourj'ai un ti probleme sur une page phpelle affiche une liste contenue dans ma bddnom prenom etc... avec une limite de 20 par pagemais le probleme recuperation du resultat d'un menu deroulant dans une autre page php [ par imad_lol ] bonjour ,jai une page php ou j'insere un formulaire qui contient un menu deroulant avec plusieur items(a partir d'une base de données) et un boutton d Recuperer valeur d'un input image... [ par DjChat ] Bonjour a tous, je suis entrain de crée un formulaire avec des images clickable, j'aurai voulu recuperé le nom de la personne a qui est la photo, donc prob: passage POST formulaire d'un widget [ par kenza1987 ] Bonjour, en fait g besoin de vos lumieres !!! je vous explique mon probleme :je suis entrain de creer un widget en forme de formulaire qui va faire l' Affichage de texte de BDD et saut de ligne... [ par DjChat ] Bonjour a tous, j'ai crée une partie membre ou les utlisateur peuvent ecrire du texte qui sera affiché sur leur profile. J'ai juste un souci quand j


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
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,577 sec (3)

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