Home  >  Article  >  Backend Development  >  Code for reading and writing WORD documents in PHP_PHP Tutorial

Code for reading and writing WORD documents in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:52:29763browse


Copy the code The code is as follows:

// Create an index pointing to the new COM component
$word = new COM("word.application") or die("Can't start Word!");
// Display the version number of Word currently being used
//echo "Loading Word, v. {$word->Version}
”;
// Set its visibility to 0 (false). If you want it to open at the front, use 1 (true)
// to open the application in the forefront, use 1 (true)
//$word->Visible = 0;

//Open a document
$word->Documents ->OPen(”d:mywebmuban.doc”);
//Read document content

$test= $word->ActiveDocument->content->Text;

echo $test;
echo “
”;
//Replace the variables that need to be replaced in the document
$test=str_replace(”<{variable}>”, "This is a variable",$test);
echo $test;
$word->Documents->Add();
// Add text in a new document
$word- >Selection->TypeText(”$test”);
//Save the document in the directory
$word->Documents[1]->SaveAs(”d:/myweb/comtest. doc");
// Close the connection with the COM component
$word->Quit();
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318933.htmlTechArticleCopy the code as follows: ? //Create an index pointing to the new COM component $word=newCOM(”word. application")ordie("Can'tstartWord!"); //Display the version number of Word currently in use...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn