我有一个PHP文件,其中包含一个名为$data
的变量。现在我在页面上回显这个变量。它工作正常,但我想在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 :(得分: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