2011-12-15 9 views
2

私は$dataという名前の変数を持つPHPファイルを持っています。今、私はこの変数をページにエコーします。それはうまく動作しますが、私はこの変数をドキュメントファイルに書きたいと思います。これどうやってやるの?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; 
    ?> 

私はそれが仕事をしたりしませんかわからない、私はそれを試していないとして、それはだとして

は、PHPのCOMの取扱説明書を http://www.php.net/manual/en/class.com.php

+2

非常に悪いアイデアを行きますWindowsのみの拡張機能。 – Maerlyn

+1

通常、すべてのサーバはunixまたはlinuxにあります。そしてそれはどのように有用ですか? –

関連する問題