PHP uses COM to get Rich text content

Source: Internet
Author: User

1. Need to install Office on the app server

2. You may need to create a folder: Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
3. You may need to set permissions in the component service, locate the "Microsoft Office ..." property, set the related permissions

4. You may need to set the login username and password for the Apache service

functionGetrtftext ($rtfFileName) {    $result= ' '; if(!Is_file($rtfFileName)) {        Throw NewErrorexception ("File not found.")); }    $rtfFileName=Realpath($rtfFileName); //Connect to Word    if(!class_exists(' COM ')) {        Throw NewErrorexception (' COM extension is not enabled. ')); }    $word=NewCOM ("Word.Application"); if(!$word) {        Throw NewErrorexception (' Unable to instantiate Word COM object. '); }    //Check the Word version.    if($word->version < 12) {        $word-Quit (); $word=NULL; Throw NewErrorexception (' The version of Word is too old. ')); }    //$word->visible = 1;    Try {        //documents.open:http://msdn.microsoft.com/en-us/library/office/ff835182%28v=office.14%29.aspx//$word Visible=true;        $word->documents->open ($rtfFileName,FALSE,TRUE); $result=$word->activedocument->content->Text; $word->activedocument->close (FALSE); //echo '. $test;}Catch(Exception $e) {        $word-Quit (); $word=NULL; Throw $e; }    Try {        $word-Quit (); $word=NULL; } Catch(Exception $e) {        Var_dump($e); }    return $result;}

PHP uses COM to get Rich text content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.