2011-01-22 57 views
-2

我能夠生成Microsoft Word文件,但我想要表格結構中的數據。我在PHP中使用了一個HTML表格標籤,但輸出看起來並不令人滿意。在表中有很多cellpacing和cellpadding,即使我已經將它們初始化爲零空間。任何想法如何解決這個問題?在PHP中生成Microsoft Word文件

在這裏不用我的代碼

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'> 
      <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>"; 
+1

該文件的用途是什麼?用*空格*表示屏幕上的內存或空間嗎?也許CSV會更好。 (我假設你只是生成一個包含單詞的文件;)) – 2011-01-22 10:06:53

+1

也許你應該通過解釋你想要做什麼,用完整的單詞(O/P =?),完整的句子和適當的術語來闡述你的問題(我們是假設「Word」實際上是微軟的Word?) – thkala 2011-01-22 10:07:30

回答

4

爲什麼不考慮建立一個「真正的」 Word文檔,而不是一個「化妝相信,HTML實際上是詞」的文件。看看PHPWord