Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: problema formattazione

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2004
    Messaggi
    13

    problema formattazione

    Ecco il mio problema.....
    ho fatto uno script molto complesso che mi genera una pagina html che riporta un report

    Questo report deve essere trasformato in word per poi essere compilato.

    Però succede che le tabelle non mi rimangono formattate su word 97 mentre sì wu word2000
    perche?

    queste tabelle le ho generate lavorando su word, salvando il documento e poi copiando il codice in dreamweaver, sperando di non incorrere così in problemi visto che è come se uso il codice html di word, invece in word 97 mi sballa tutto e cioè non mi tiene l'altezza delle righe.
    15-20 pagine da riformattare non sono poche...

    cosa mi consigliate di fare?
    esiste uno script magari che bypassa l'html e genera subito da php un file word?

    help me
    grazie
    Cla

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    1,965
    SI si esiste uno script

    per info guarda qui http://it2.php.net/com

    ma quello che ti interessa è questo
    codice:
    <?php
    wdFormatDocument = 0;
       $wdFormatTemplate = 1;
       $wdFormatText = 2;
       $wdFormatTextLineBreaks = 3;
       $wdFormatDOSText = 4;
       $wdFormatDOSTextLineBreaks = 5;
       $wdFormatRTF = 6;
       $wdFormatUnicodeText = 7;
       $wdFormatHTML=8;
    
       class MSWord
       {
           // Vars:
           var $handle;
           
           // Create COM instance to word
           function MSWord($Visible = false)
           {
               $this->handle = new COM("word.application") or die("Unable to instanciate Word");
               $this->handle->Visible = $Visible;
           }
           
           // Open existing document
           function Open($File)
           {
               $this->handle->Documents->Open($File);
           }
           
           // Create new document
           function NewDocument()
           {
               $this->handle->Documents->Add();
           }
           
           // Write text to active document
           function WriteText( $Text )
           {
               $this->handle->Selection->Typetext( $Text );
           }
           
           // Number of documents open
           function DocumentCount()
           {
               return $this->handle->Documents->Count;
           }
           
           // Save document as another file and/or format
           function SaveAs($File, $Format = 0 )
           {
               $this->handle->ActiveDocument->SaveAs($File, $Format);
           }
           
           // Save active document
           function Save()
           {
               $this->handle->ActiveDocument->Save();
           }
           
           // close active document.
           function Close()
           {
               $this->handle->ActiveDocument->Close();
           }
           
           // Get word version
           function GetVersion()
           {
               return $this->handle->Version;
           }
           
           // get handle to word
           function GetHandle()
           {
               return $this->handle;
           }
       
           // Clean up instance with word
           function Quit()
           {
               if( $this->handle )
               {
                   // close word
                   $this->handle->Quit();
       
                   // free the object
                   $this->handle->Release();
                   $this->handle = null;
               }
           }
       };
    
     $Word = new MSWord;
     $Word->Open($input);
    
       $input = "C:\\test.htm";
       $output = "C:\\test.rtf";
    
       $Word = new MSWord;
       $Word->Open($input);
       $Word->SaveAs($output, $wdFormatRTF);
       $Word->Quit();
    ?>

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2004
    Messaggi
    13
    Grazie!
    Ma come faccio a usarlo?
    io genero il report in una pagina che si chiama generarep.php
    che è un misto tra html e php
    come faccio a configurare lo script che mi hai dato?

    Grazie ancora
    cla

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    1,965
    mmmh non ho capito bene cosa intendi...
    beh, se i dati vengono da form o da link (GET) basta che recuperi in qualche modo il nome del file che vuoi creare e con

    $input = "nomfile.est";
    $output = "test.rtf";
    $Word = new MSWord;
    $Word->Open($input);
    $Word->SaveAs($output, $wdFormatRTF);
    $Word->Quit();

    poi fai il redirect o con i meta tags o con header("Locationag.rtf") di php alla pagina in formato rtf

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2004
    Messaggi
    13
    praticamente è così
    inserisco dei dati
    in base a questi dati
    tramite un database sql
    si genera un file php
    che include o meno delle tabelle sempre in php
    quindi genera il mio report sotto php

    io questo lo vorrei in doc e formattato
    come faccio?

    Grazie
    tantissime

  6. #6
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    1,965
    MMMH non so 2 cose:

    1) Se il file viene aperto con il suo output
    2) Se viene sovrascritto un file esistente con il suo nome

    cmq prova modificando il codice così
    codice:
       $input = $_SERVER['PHP_SELF'];
       $output  = str_replace(".php","",$input) . ".rtf";
    
       $Word = new MSWord;
       $Word->Open($input);
       $Word->SaveAs($output, $wdFormatRTF);
       $Word->Quit();
    nella pagina che estrae dati da db viene generato il file .rtf
    non dovrebbe aprirlo immediatamente, quindi devi reindirizzare la pagina o mostrare un link verso nomepagina.rtf

    ciao

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2004
    Messaggi
    13
    ho provato inserndo il codice in questo modo nella pagina dove si genera la pagina:

    <?php
    $wdFormatDocument = 0;
    $wdFormatTemplate = 1;
    $wdFormatText = 2;
    $wdFormatTextLineBreaks = 3;
    $wdFormatDOSText = 4;
    $wdFormatDOSTextLineBreaks = 5;
    $wdFormatRTF = 6;
    $wdFormatUnicodeText = 7;
    $wdFormatHTML=8;

    class MSWord
    {
    // Vars:
    var $handle;

    // Create COM instance to word
    function MSWord($Visible = false)
    {
    $this->handle = new COM("word.application") or die("Unable to instanciate Word");
    $this->handle->Visible = $Visible;
    }

    // Open existing document
    function Open($File)
    {
    $this->handle->Documents->Open($File); 639
    }

    // Create new document
    function NewDocument()
    {
    $this->handle->Documents->Add();
    }

    // Write text to active document
    function WriteText( $Text )
    {
    $this->handle->Selection->Typetext( $Text );
    }

    // Number of documents open
    function DocumentCount()
    {
    return $this->handle->Documents->Count;
    }

    // Save document as another file and/or format
    function SaveAs($File, $Format = 0 )
    {
    $this->handle->ActiveDocument->SaveAs($File, $Format); 663
    }

    // Save active document
    function Save()
    {
    $this->handle->ActiveDocument->Save();
    }

    // close active document.
    function Close()
    {
    $this->handle->ActiveDocument->Close();
    }

    // Get word version
    function GetVersion()
    {
    return $this->handle->Version;
    }

    // get handle to word
    function GetHandle()
    {
    return $this->handle;
    }

    // Clean up instance with word
    function Quit()
    {
    if( $this->handle )
    {
    // close word
    $this->handle->Quit();

    // free the object
    $this->handle->Release();
    $this->handle = null;
    }
    }
    };

    $Word = new MSWord;
    $Word->Open($input);

    $input = $_SERVER['PHP_SELF'];
    $output = str_replace(".php","",$input) . ".rtf";

    $Word = new MSWord;
    $Word->Open($input); 706
    $Word->SaveAs($output, $wdFormatRTF);
    $Word->Quit();

    ?>

    e quindi con la prima parte che mi hai dato e l'ultima modificata...

    ecco mi da questi errori:

    Notice: Undefined variable: input in c:\programmi\easyphp1-7\www\pianilab\rephk\generarep2.php on line 706

    Warning: (null)(): Invoke() failed: Incompatibilità tra tipi. Argument: 2 in c:\programmi\easyphp1-7\www\pianilab\rephk\generarep2.php on line 639

    Warning: (null)(): Invoke() failed: Eccezione. Source: Microsoft Word Description: The document name or path is not valid. Try one or more of the following: * Check the path to make sure it was typed correctly. * On the File menu, click Open. Search for the file using this dialog box. (/pianilab/rephk/generarep2.php) in c:\programmi\easyphp1-7\www\pianilab\rephk\generarep2.php on line 639

    Warning: (null)(): PropGet() failed: Eccezione. Source: Microsoft Word Description: This command is not available because no document is open. in c:\programmi\easyphp1-7\www\pianilab\rephk\generarep2.php on line 663

    ti ho messo i numeri a fianco delle righe incriminate

    scusa se ti continuo a rompere ma è una cosa molto importante!
    Grazie

  8. #8
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    1,965
    modifica questo

    $input = $_SERVER['PHP_SELF'];

    con

    $input = "generarep2.php";

    se gli errori persistono ci guardero' meglio

    ciao

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2004
    Messaggi
    13
    ecco ora cosa dice:

    Warning: (null)(): Invoke() failed: Eccezione. Source: Microsoft Word Description: This file could not be found. Try one or more of the following: * Check the spelling of the name of the document. * Try a different file name. (generarep2.php) in c:\programmi\easyphp1-7\www\pianilab\rephk\generarep2.php on line 639

    Warning: (null)(): PropGet() failed: Eccezione. Source: Microsoft Word Description: This command is not available because no document is open. in c:\programmi\easyphp1-7\www\pianilab\rephk\generarep2.php on line 663

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2004
    Messaggi
    13
    scusa ma alla riga 639 mi richiama la variabile $file
    ma non è definita da nessuna parte,
    può essere lì l'errore?

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 © 2026 vBulletin Solutions, Inc. All rights reserved.