>php教程 >php手册 >C#生成的dll(引用了office的com控件实现文档转换),PHP调用时

C#生成的dll(引用了office的com控件实现文档转换),PHP调用时

WBOY
WBOY원래의
2016-06-06 19:42:341247검색

C#生成dll,其中引用了office的com控件实现文档转换。 当其他winform程序调用时正常。 但注册该dll后,由PHP调用时出错。 try catch了一下,输出 Word 出现问题 。 测试机器上装的是office2007。C#实现文档转换部分: string fileFolder = Path.GetDirectory

C#生成dll,其中引用了office的com控件实现文档转换。

当其他winform程序调用时正常。

但注册该dll后,由PHP调用时出错。

try catch了一下,输出“Word 出现问题”。

测试机器上装的是office2007。C#实现文档转换部分:

          <span>string</span> fileFolder =<span> Path.GetDirectoryName(wordFilePath);
          </span><span>string</span> fileNameWithoutExtension =<span> Path.GetFileNameWithoutExtension(wordFilePath);
          </span><span>string</span> htmlFilePath = fileFolder + <span>@"</span><span>\</span><span>"</span> + fileNameWithoutExtension + <span>@"</span><span>.html</span><span>"</span><span>;

          Object objWordPath </span>=<span> wordFilePath;
          Object objHtmlPath </span>=<span> htmlFilePath;
          MSWord.Application wordApp;
          MSWord.Document wordDoc;
          Object Nothing </span>=<span> Missing.Value;
          wordApp </span>= <span>new</span><span> MSWord.ApplicationClass();
          wordDoc </span>= wordApp.Documents.Add(<span>ref</span> objWordPath, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing);<span>//</span><span>===========PHP调用时这下面的语句执行不到</span>
          <span>object</span> format =<span> MSWord.WdSaveFormat.wdFormatFilteredHTML;
          wordDoc.SaveAs(</span><span>ref</span> objHtmlPath, <span>ref</span> format, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span><span> Nothing,
            </span><span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span><span> Nothing);
          wordDoc.Close(</span><span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span><span> Nothing);
          wordApp.Quit(</span><span>ref</span> Nothing, <span>ref</span> Nothing, <span>ref</span> Nothing);

dll注册后,PHP调用部分:

<span>php
</span><span>$c</span>= <span>new</span> COM("ComLibrary.Test"<span>);
</span><span>echo</span> <span>$c</span>->SaveWordAsHtml("D:\\ningtao\\xampp\\htdocs\\test.doc"<span>);
</span>?>

不知道是由什么引起的。

初步怀疑有2中可能:

1、dll注册为COM+再被PHP调用时,没有正确的调用office的com组件。

2、被PHP调用时,由于文件的读写权限引起的问题。

 

大家有没有遇到过类似问题的,该如何解决?

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.