2013-07-21 69 views
2

我需要儘快解決這個問題。我嘗試了很多解決方案,但所有的教程和示例都創建了文檔並將word文件下載到本地計算機中。我想要的是上傳或保存到服務器的文件系統。請幫我解決這個問題。在PHP的服務器文件系統中生成word文檔

謝謝。

+0

你的問題有點含糊不清。你想寫一個生成word文檔的php腳本?那個PHP腳本坐在你的服務器或你的本地計算機上? –

+0

我想用php創建一個word文檔,並將該文檔保存在服務器中,而不是保存在本地計算機中。 –

回答

1

PHPWord可以這樣做:

http://phpword.codeplex.com/releases/view/49543

我試圖例子/ BasicTable.php,它在服務器上創建的文件,不下載。

這裏使用的代碼:

<?php 
require_once '../PHPWord.php'; 

// New Word Document 
$PHPWord = new PHPWord(); 

// New portrait section 
$section = $PHPWord->createSection(); 

// Add table 
$table = $section->addTable(); 

for($r = 1; $r <= 10; $r++) { // Loop through rows 
    // Add row 
    $table->addRow(); 

    for($c = 1; $c <= 5; $c++) { // Loop through cells 
     // Add Cell 
     $table->addCell(1750)->addText("Row $r, Cell $c"); 
    } 
} 

// Save File 
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); 
$objWriter->save('BasicTable.docx'); 
?> 
+0

這很好地工作。謝謝 –