The code for reading and writing Word documents in PHP. Copy the code as follows :? Create an index pointing to the new COM component $ wordnewCOM ("word. application") ordie ("CantstartWord !"); Display the version number of the Word currently in use
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 the Word currently in use
// Echo "Loading Word, v. {$ word-> Version}
";
// Set its visibility to 0 (false). If you want to enable it at the frontend, use 1 (true)
// To open the application in the forefront, use 1 (true)
// $ Word-> Visible = 0;
// Play? One document
$ Word-> Documents-> OPen ("d: \ myweb \ muban.doc ");
// Read the document content
$ Test = $ word-> ActiveDocument-> content-> Text;
Echo $ test;
Echo"
";
// Replace the variable to be changed in the document
$ Test = str_replace ("<{variable}>", "this is a variable", $ test );
Echo $ test;
$ Word-> Documents-> Add ();
// Add text to the new document
$ Word-> Selection-> TypeText ("$ test ");
// Save the document in the directory
$ Word-> Documents [1]-> SaveAs ("d:/myweb/comtest.doc ");
// Close the connection with COM components
$ Word-> Quit ();
?>
The http://www.bkjia.com/PHPjc/318933.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318933.htmlTechArticle code is as follows :? // Create an index pointing to the new COM component $ word = newCOM ("word. application") ordie ("Can" tstartWord !"); // Display the version number of the currently used Word...