开发者

Generating a Microsoft Word file in PHP [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

I am able to generate a Microsoft word file, but I want the data in table structure. I have used an HTML table tag in PHP, but the output does not look satisfactory. In the table are a lot of cellspacing and cellpadding even if I have initialize them to zero space. Any idea how can I solve this?

here goes my code

    header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=document_name.doc");
    $now_date = date('d-m-Y H:i');
    echo "<html>";
    echo "<body>";
    echo "</body>";
    echo "<head>";
    echo "<div>Seminarthema:</div>\n";
    echo "<div>Termin:$now_date</div>";
    echo "<br></br>";
    echo "<div style='size:20px;'><h2>Teilnehmerliste</h2></div>";
    echo "<table border='1' cellpadding='0' cellspacing='0'>
    开发者_StackOverflow中文版        <tr><th>Name</th><th>Vorname</th><th>Buchungskreis</th><th>Kurs-ID</th><th>Teilgenommen</th></tr>";     
    $students = $GLOBALS["TYPO3_DB"]->exec_SELECTquery('*','tx_training_Registration','hidden=0 AND deleted=0');
    $countstud = $GLOBALS['TYPO3_DB']->sql_num_rows($students); 
    if($countstud){ 
        while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($students)){
            echo "<tr>";
                echo "<td>".utf8_decode($row2['firstname'])."</td>";
                echo "<td>".utf8_decode($row2['lastname'])."</td>";
                echo "<td>".utf8_decode($row2['companycode'])."</td>";
                echo "<td>".utf8_decode($row2['trainingid'])."</td>";
                echo "<td>".utf8_decode($row2[' status'])."</td>";
            echo "</tr>";
        }   
    }                                 
    echo  "</table>";   
    echo "</head>";
    echo "</html>"; 


Why not consider creating a "real" Word document rather than a "make-believe that HTML is actually Word" file. Take a look at PHPWord.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜