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

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

WBOY
WBOYOriginal
2016-06-06 19:42:341247browse

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调用时,由于文件的读写权限引起的问题。

 

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn