【问题标题】:How can write on a word document or can create a new word document? [closed]如何在word文档上书写或创建新的word文档? [关闭]
【发布时间】:2014-01-03 12:08:02
【问题描述】:

服务器上有 php 4.4.8。怎么能在word文档上写。我可以写它,但它下载。写作没有表现出来。如果不可能,如何创建一个新的word文档。

【问题讨论】:

  • 你的问题很不清楚。你能写文件吗,是或否?如果是,请告诉我们您的问题是什么。
  • 没有。我想用php创建一个新文档

标签: php ms-word phpword


【解决方案1】:

试试这个

$word = new COM("word.application");

// Hide MS Word application window
$word->Visible = 0;


$template_file = 'C:/xampp/htdocs/portal/includes/templates/form1.docx'; 
//file name is different based on initiating form.

//Create new document
$word->Documents->Open($template_file);
//WO Number
$woNumBookMark = 'WONum';
$objBookmark = $word->ActiveDocument->Bookmarks($woNumBookMark);
$range = $objBookmark->Range;
$range->Text = htmlentities($workOrderNum) . '/' . htmlentities($lotID);
$filename = tempnam(sys_get_temp_dir(), "word");
$word->Documents[1]->SaveAs($filename);

// Close and quit
$word->Quit();
unset($word);
header("Content-Length: ".filesize($filename));
//header("Content-Type: application/force-download");
header("Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Disposition: attachment;Filename=document_name.docx");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

// Send file to browser

readfile($filename);
unlink($filename);

根据您的需要进行更改。

【讨论】:

猜你喜欢
  • 2010-09-05
  • 1970-01-01
  • 2010-11-05
  • 2014-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多