本文整理汇总了C#中Microsoft.Office.Interop.Word.Application.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Application.GetType方法的具体用法?C# Application.GetType怎么用?C# Application.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word.Application
的用法示例。
在下文中一共展示了Application.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WordToHtml
/// <summary>
/// 需要转换的Word文档路径
/// </summary>
/// <param name="fileName">完整路径</param>
/// <returns>HTML页面路径</returns>
private static string WordToHtml(object fileName)
{
Word.Application word = new Word.Application();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
//打开文件
Type docsType = docs.GetType();
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs, new object[] { fileName, true, true });
//转换格式,另存
Type docType = doc.GetType();
string wordSaveFileName = fileName.ToString();
string htmlSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.LastIndexOf(".") + 1) + "html";
object saveFileName = (object)htmlSaveFileName;
docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", BindingFlags.InvokeMethod, null, doc, null);
//退出Word
wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
return saveFileName.ToString();
}
示例2: Word2Pdf
/// <summary>
/// word转换成pdf
/// </summary>
/// <param name="filePath"></param>
public static void Word2Pdf(string filePath)
{
path = filePath;
saveFileName = filePath + ".pdf";
var word = new Word.Application();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
var docsType = docs.GetType();
var doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs,
new Object[] { path, true, true });
Type docType = doc.GetType();
docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc,
new object[] { saveFileName, Word.WdSaveFormat.wdFormatPDF });
wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
}
示例3: GetWordContent
public static List<string> GetWordContent(string filePath)
{
try
{
List<string> allContent = new List<string>();
string content = string.Empty;
path = filePath;
var word = new Word.Application();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
var docsType = docs.GetType();
var doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs,
new Object[] { path, true, true });
for (int i = 0; i < doc.Paragraphs.Count; i++)
{
if (content.Length <= 300)
content += doc.Paragraphs[i+1].Range.Text;
else
{
allContent.Add(content);
content = "";
content += doc.Paragraphs[i+1].Range.Text;
}
}
if (allContent.Count == 0)
allContent.Add(content);
Type docType = doc.GetType();
docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc,
new object[] { saveFileName, Word.WdSaveFormat.wdFormatPDF });
wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
return allContent;
}
catch(Exception e)
{
return null;
}
}
示例4: ReadWordFile
//.........这里部分代码省略.........
}
//ShortFormReport.DataLeftMammaryGland = doc.FormFields[60].Result;
string dataLeftAgeRelated = doc.FormFields[61].Result;
if (string.IsNullOrEmpty(dataLeftAgeRelated))
{
shortFormReport.DataLeftAgeRelated = "0";//"";
}
else if (dataLeftAgeRelated.StartsWith("<5"))
{
shortFormReport.DataLeftAgeRelated = "1";// App.Current.FindResource("ReportContext_111").ToString();
}
else if (dataLeftAgeRelated.StartsWith(">95"))
{
shortFormReport.DataLeftAgeRelated = "3";// App.Current.FindResource("ReportContext_113").ToString();
}
else
{
shortFormReport.DataLeftAgeRelated = "2";// App.Current.FindResource("ReportContext_112").ToString();
}
//ShortFormReport.DataLeftAgeRelated = doc.FormFields[61].Result;
string dataRightMammaryGland = doc.FormFields[64].Result;
if (string.IsNullOrEmpty(dataLeftMammaryGland))
{
shortFormReport.DataRightMammaryGland = "0";// "";
}
else if (dataLeftMammaryGland.StartsWith("Ductal type") || dataLeftMammaryGland.StartsWith("导管型乳腺结构") || dataLeftMammaryGland.StartsWith("导管式结构"))
{
shortFormReport.DataRightMammaryGland = "5";// App.Current.FindResource("ReportContext_126").ToString();
}
else if (dataLeftMammaryGland.StartsWith("Mixed type with ductal component predominance") || dataLeftMammaryGland.StartsWith("混合型,导管型结构优势") || dataLeftMammaryGland.StartsWith("导管成分优先的"))
{
shortFormReport.DataRightMammaryGland = "4";// App.Current.FindResource("ReportContext_125").ToString();
}
else if (dataLeftMammaryGland.StartsWith("Mixed type of mammary gland structure") || dataLeftMammaryGland.StartsWith("Mixed type of structure") || dataLeftMammaryGland.StartsWith("混合型乳腺结构") || dataLeftMammaryGland.StartsWith("混合式结构"))
{
shortFormReport.DataRightMammaryGland = "3";// App.Current.FindResource("ReportContext_124").ToString();
}
else if (dataLeftMammaryGland.StartsWith("Mixed type with amorphous component predominance") || dataLeftMammaryGland.StartsWith("混合型,无定型结构优势") || (dataLeftMammaryGland.Contains("无") && dataLeftMammaryGland.Contains("混合")))
{
shortFormReport.DataRightMammaryGland = "2";// App.Current.FindResource("ReportContext_123").ToString();
}
else if (dataLeftMammaryGland.StartsWith("Amorphous type") || dataLeftMammaryGland.StartsWith("无定型乳腺结构") || (dataLeftMammaryGland.Contains("无") && !dataLeftMammaryGland.Contains("混合")))
{
shortFormReport.DataRightMammaryGland = "1";// App.Current.FindResource("ReportContext_122").ToString();
}
//ShortFormReport.DataLeftMammaryGland = doc.FormFields[60].Result;
string dataRightAgeRelated = doc.FormFields[65].Result;
if (string.IsNullOrEmpty(dataRightAgeRelated))
{
shortFormReport.DataRightAgeRelated = "0";// "";
}
else if (dataRightAgeRelated.StartsWith("<5"))
{
shortFormReport.DataRightAgeRelated = "1";// App.Current.FindResource("ReportContext_111").ToString();
}
else if (dataRightAgeRelated.StartsWith(">95"))
{
shortFormReport.DataRightAgeRelated = "3";// App.Current.FindResource("ReportContext_113").ToString();
}
else
{
shortFormReport.DataRightAgeRelated = "2";// App.Current.FindResource("ReportContext_112").ToString();
}
//ShortFormReport.DataRightMammaryGland = doc.FormFields[64].Result;
//ShortFormReport.DataRightAgeRelated = doc.FormFields[65].Result;
}
catch(Exception){}
finally
{
Type wordType = wordApp.GetType();
try
{
if (doc != null)
{
doc.Close();
}
if (wordApp != null)
{
wordApp.Quit();
}
}
catch (Exception)
{
try
{
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, wordApp, null);
doc = null;
wordApp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch (Exception) { }
}
}
return shortFormReport;
}