110,477
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Runtime.InteropServices;namespace ComLibrary {
[Guid("2BF6AD68-C374-4877-AB19-B523AC1148AD")]
public interface ITest {
[DispId(0)]
string GetGuid();
[DispId(1)]
string About();
[DispId(2)]
int Add(int a, int b);
} [Guid("585AC64C-53ED-4be8-A4F7-90397D676443")]
public class Test : ITest {
public string GetGuid() {
return System.Guid.NewGuid().ToString();
} public string About() {
return "Hello higkoo !";
} public int Add(int a, int b) {
return a + b; }
}
<?php
$c= new COM("ComLibrary.Test");
echo $c->About();
?>
try
{
MSWord.ApplicationClass word = new MSWord.ApplicationClass();
Type wordType = word.GetType();
MSWord.Documents docs = word.Documents;
Type docsType = docs.GetType();
strMsg += "-打开文档" + docsType.ToString();
MSWord.Document doc = (MSWord.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFilePath, true, true });
Type docType = doc.GetType();
strMsg += "-另存文档" + docType.ToString();
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { htmlFilePath, MSWord.WdSaveFormat.wdFormatFilteredHTML });
strMsg += "-退出WORD";
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
strMsg += "-转换成功";
}
catch (Exception ex)
{
strMsg += @"--错误信息:" + ex.Message;
}
finally
{
//最后关闭打开的winword 进程
Process[] myProcesses = Process.GetProcessesByName("WINWORD");
foreach (Process myProcess in myProcesses)
{
myProcess.Kill();
}
}
// 记录日志
strMsg += "--文档路径:" + wordFilePath + "--时间:" +DateTime.Now.ToString() + "\r\n";
using (var writer = new StreamWriter(logFilePath, true, Encoding.UTF8))
{
writer.Write(strMsg);
}