本文整理汇总了C#中Microsoft.Office.Interop.Word.Application.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.Application.GetType方法的具体用法?C# Microsoft.Office.Interop.Word.Application.GetType怎么用?C# Microsoft.Office.Interop.Word.Application.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word.Application
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Word.Application.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convertion2Html
/// <summary>
/// 将doc文档转换成html
/// </summary>
/// <param name="FilePath">虚拟路径文件名</param>
/// <param name="NewHtmlName">新的html文件名</param>
/// <param name="StrHtml">获取的Html</param>
/// <param name="IsDelDocFile">是否删除doc文件</param>
/// <param name="IsDelHtmlFile">是否删除html文件</param>
/// <returns>如果返回false,则NewHtmlName和StrHtml均为空</returns>
public bool Convertion2Html(string FilePath, out string NewHtmlName, out string StrHtml, bool IsDelDocFile, bool IsDelHtmlFile)
{
NewHtmlName = "";
StrHtml = "";
if (FilePath.Trim() == "")
{
return false;
}
//必须先关闭WINWORD
try
{
System.Diagnostics.Process[] CloseID = System.Diagnostics.Process.GetProcessesByName("WINWORD");
for (int i = 0; i < CloseID.Length; i++)
{
if (!CloseID[i].CloseMainWindow())
{
CloseID[i].Kill();
}
}
}
catch { }
//绝对路径,同时将后缀名定位小写doc,防止大写
string RealFileNamePath = HttpContext.Current.Server.MapPath(FilePath);
RealFileNamePath = RealFileNamePath.Substring(0, RealFileNamePath.Length - 3) + "doc";
RealFileNamePath = "d:\\2.doc";
//调用word类库
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
Type docsType = docs.GetType();
//读取doc文档
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
try
{
doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod,null, docs, new Object[] { RealFileNamePath, true, true });
}
catch
{
try
{
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
}
catch { }
return false;
}
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = RealFileNamePath.Replace(".doc", ".htm");
try
{
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
}
catch
{
// 退出 Word
try
{
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
}
catch { }
return false;
}
//返回的数据
NewHtmlName = FilePath.Replace(".doc", ".htm");
//一定要等待几秒再操作,否则由于缓存的文件没有写入,会导致异常
System.Threading.Thread.Sleep(3000);
StrHtml = this.GetFileContent(NewHtmlName);
//根据需要删除文件
if (IsDelDocFile)
{
System.IO.File.Delete(RealFileNamePath);
//.........这里部分代码省略.........