我正在使用PHP来启动Word Automation并操纵word文档,但我想它可以用所有其他语言完成。我需要做的很简单,我需要删除第一页并添加页眉和页脚。
这是我的代码:
$word = new COM('word.applicantion');
$word->Documents->Open('xxx.docx');
$word->Documents[1]->SaveAs($result_file_name, 12);
任何样品?
答案 0 :(得分:2)
答案 1 :(得分:1)
试 { $ word = new COM(“word.application”)// $ word = new COM(“C:\ x.docx”); 或死(“无法创建单词的实例”);
//bring word to the front
$word->Visible = 1;
//open a word document
$word->Documents->Open("file.docx");
// remove first page
$range = $word->ActiveDocument->Bookmarks("\page");
$range->Select();
$word->Selection->Delete();
//save the document as docx
$word->Documents[1]->SaveAs("modified_file.docx", 12); // SaveAs('filename', format) // format: 0 - same?, 1 - doc?, 2 - text, 4 - text other encoding
}
catch(Exception $e)
{
echo "error class.document.php - convert_to_docx: $e 20100816.01714";
}
//close word
if($word)
$word->Quit();
//free object resources
//$word->Release();
$word = null;