码迷,mamicode.com
首页 > Web开发 > 详细

PHP使用COM 获取RTF内容

时间:2016-05-03 20:30:48      阅读:425      评论:0      收藏:0      [点我收藏+]

标签:

1. 需要在APP服务器上安装Office

2. 可能需要创建文件夹:Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
3. 可能需要设置权限  component service,中找到 “Microsoft Office ….”中的属性,设置相关的权限

4. 可能需要设置Apache服务的登录用户名及密码

function getRTFtext($rtfFileName) {
    $result=‘‘;
    if (!is_file($rtfFileName)) {
        throw new ErrorException("File not found.");
    }
    $rtfFileName = realpath($rtfFileName);

    // Connect to Word
    if (!class_exists(‘COM‘)) {
        throw new ErrorException(‘COM extension is not enabled.‘);
    }

    $word = new COM("word.application");
    if (!$word) {
        throw new ErrorException(‘Unable to instantiate Word COM object.‘);
    }
    // Check the Word version.
    if ($word->Version < 12) {
        $word->Quit();
        $word = null;
        throw new ErrorException(‘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使用COM 获取RTF内容

标签:

原文地址:http://www.cnblogs.com/krisy/p/5456254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!