日期:2014-05-18 浏览次数:20830 次
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); Document doc = null; object missing = System.Reflection.Missing.Value; object filename = System.Windows.Forms.Application.StartupPath + @"\EmrEditor.html"; object readOnly = false; object isVisible = true; object index = 0; IDataObject data = null; try { doc = app.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); data = Clipboard.GetDataObject(); } finally { if (doc != null) { object docType = WdNewDocumentType.wdNewBlankDocument; Document d = app.Documents.Add(ref missing, ref missing, ref docType, ref missing); d.ActiveWindow.Selection.PasteAndFormat(WdRecoveryType.wdPasteDefault); if (d.Tables.Count > 0) { d.Tables[1].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone; d.Tables[1].Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone; } filename = @"d:\word.pdf"; object fileFormat = WdSaveFormat.wdFormatPDF; d.SaveAs(ref filename, ref fileFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); d = null; doc.Close(ref missing, ref missing, ref missing); doc = null; GC.Collect(); if (app != null) { object saveOptions = WdSaveOptions.wdDoNotSaveChanges; app.Quit(ref saveOptions, ref missing, ref missing); app = null; } } }
Type wordType = Type.GetTypeFromProgID("Word.Application"); Object word = System.Activator.CreateInstance(wordType); Object documents = wordType.InvokeMember("Documents", BindingFlags.GetProperty, null, word, null);
if (d.Tables.Count > 0) { d.Tables[1].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone; d.Tables[1].Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone; }