2011-12-15 4 views
2

$data이라는 변수가있는 PHP 파일이 있습니다. 이제이 변수를 페이지에 표시합니다. 그것은 잘 작동하지만이 변수를 doc 파일에 쓰고 싶습니다. 어떻게 할 수 있니?PHP를 사용하여 doc 파일을 생성하는 방법

다음 방법을 사용하여 문서를 생성하지만 작동하지 않습니다. 그것의로

$fh = fopen('viewAppraisalDetailDoc.doc',"w+"); 
fwrite($fh, $data); 
$file = 'viewAppraisalDetailDoc.doc'; 

if (file_exists($file)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/msword'); 
    header('Content-Disposition: attachment; filename='.basename($file)); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 
    exit; 
} 

답변

0
<?php 
// starting word 
    $word = new COM("word.application") or die("Unable to instantiate Word"); 
    echo "Loaded Word, version {$word->Version}\n"; 

    //bring it to front 
     $word->Visible = 1; 

    //open an empty document 
    $word->Documents->Add(); 

     //do some weird stuff 
     $word->Selection->TypeText("This is a test..."); 
    $word->Documents[1]->SaveAs("Useless test.doc"); 

    //closing word 
     $word->Quit(); 

    //free the object 
    $word = null; 
    ?> 

나는 http://www.php.net/manual/en/class.com.php

+2

아주 나쁜 생각,

는 PHP의 COM 설명서를 통해 이동, 나는 그것을 시도하지 않은대로, 일을하거나하지 여부를 확실하지 않다 창 전용 확장 프로그램. – Maerlyn

+1

일반적으로 모든 서버는 유닉스 또는 리눅스에 있습니다. 그럼 어떻게 유용합니까 ?? –