Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    64

    esportazione in excel-mime tipe

    Ciao a tutti
    ho un problema con questo script:

    <?
    $filename="prenotazioni".$var=$_GET["from"].".xls";
    header ("Content-Type: application/vnd.ms-excel");
    header ("Content-Disposition: filename=$filename");
    session_start();
    ?>
    <!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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <table border=1>

    <?
    echo "<table border=1>";

    error_reporting(0);//eliminare in fase di sviluppo

    $conn = mysqli_connect($host,$user , $pass, $db_name);
    $conn3 = mysqli_connect($host,$user , $pass, "work_ut");
    $var=$_GET["from"] ;

    $query1="SELECT * from prenotazione WHERE oggetto LIKE '".$var."';";

    $record =mysqli_query($conn,$query1);
    var_dump($record);
    $riga= "<tr><td>NOME</td><td>COGNOME</td><td>FACOLTA</td><td>TELEFONO</td><td>E-MAIL</td></tr>";
    while($row=mysqli_fetch_row($record))
    {

    extract($row);
    $q="SELECT * FROM `utente` WHERE `id`= ".$row[2]." ;";
    $s=mysqli_query($conn3,$q);
    $utente=mysqli_fetch_assoc($s);




    $riga.= "<tr>"."<td>".$utente['nome']."</td>"."<td>".$utente['cognome']."</td>"."<td>".$utente['facolta']."</td>"."<td>".$utente['telefono']."</td>"."<td>".$utente['email']."</td>"."</tr>";


    }
    print $riga;
    echo "</table>";
    ?>
    <body>
    </body>
    </html>


    Il file excel viene creato ma e bianco, ma cmq lo script funziona infatti se commento gli Header
    la pagina viene creata correttamente...
    Qualcuno sa aiutarmi?

  2. #2
    Se vuoi creare un file di excel al volo e con tutti i crismi, puoi usare Spreadsheet_Excel_Writer presente nel pacchetto Pear.

    Se vuoi fare in casa, ed ottenere un effetto simil-excel, devi invece togliere da $riga la formattazione a tabelle, ed usare invece il tabulatore (\t) ed il NewLine (\n).
    Codice PHP:
    $riga.= .$utente['nome']."\\t".$utente['cognome']."\\t".$utente['facolta']."\\t".$utente['telefono']."\t".$utente['email']."\\n"
    Questo è un barbatrucco, nel senso che una volta che vengono lanciati gli header, quando si apre il prompt che ti chiede "Apri", "Salva" e "Annulla", se si preme APRI si otterrà un file di testo con dei caratteri strani tra le varie parole.
    Cosa che non succede una volta che verrà salvato nel PC.

    Un ultimo appunto: uno degli header che hai scritto te è errato.
    Codice PHP:
    header ("Content-Disposition:attachment; filename=$filename"); 
    Vedi un po' se funge ora???
    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.