Opening Word document in read mode using php?

前端 未结 1 1033
孤街浪徒
孤街浪徒 2021-01-14 09:16

I want to read a Word document in a browser using PHP. I have been trying for more than two hours, but I cant get it to work. Can someone help me do this?

相关标签:
1条回答
  • 2021-01-14 09:29

    As your not too detailed in your question on your specific requirements or server setup, this will get you started & also answers the question.

    <?php
    $DocumentPath="C:/xampp/htdocs/test.doc";
    //Create an instance of the Word application
    $word = new COM("word.application") or die("Unable to instantiate application object");
    //Creating an instance of the Word Document object
    $wordDocument = new COM("word.document") or die("Unable to instantiate document object");
    $word->Visible = 0;
    //Open up an empty document
    $wordDocument = $word->Documents->Open($DocumentPath);
    
    //Create the filename for the HTML version
    $HTMLPath = substr_replace($DocumentPath, 'html', -3, 3);
    //Save the document as HTML
    $wordDocument->SaveAs($HTMLPath, 3);
    // clean up
    $wordDocument = null;
    $word->Quit();
    $word = null;
    // read the newly-created document
    readfile($HTMLPath);
    //delete the file
    unlink($HTMLPath)
    ?>
    
    0 讨论(0)
提交回复
热议问题