Tag: office interop

将命名空间传递给函数

我有一个函数,它接受一个word文档并以html格式保存。 我想使用相同的函数来处理任何文档类型。 由于Jon Skeet指出,我尝试使用generics(我假设不同的doc API是相同的)失败了。 还有另一种方式吗? using Word = Microsoft.Office.Interop.Word; using Excel = Microsoft.Office.Interop.Excel; //Works ok private void convertDocToHtm( string filename ) { … snip var app = new Word.Application(); var doc = new Word.Document(); doc = app.Documents.Open(ref fileName, ref missing, ref trueValue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, […]

适用于OS X的MS Office Interop

我一直在寻找与Mac版Office(特别是PowerPoint)互操作的信息。 我无法找到任何可用API的文档,甚至找不到用于访问它们的协议…(类似COM?Apple原生自动化API?完全不同的其他内容?) 但是,似乎有可能。 Mac中存在各种“PowerPoint远程控制”应用程序,它们可以制作PowerPoint切换幻灯片的运行实例,甚至可以从每张幻灯片中提取演示者注释。 这显然是一些味道的互相支持! 所有与Microsoft.Office.Interop引用相关的都需要有窗口,我的问题是否有任何解决方案,或者我只是在虚拟机上运行Windows … 更新 所以我们做了一些研究: 首先我们尝试使用Mono,允许你在mac中构建C#,这种方法不成功,因为powerpoint演示自动化的库需要一个窗口 我们尝试了Apache.poi,我们成功地创建了修改powerpoint演示文稿,但这种方法并不是实时的,这是不利的 第三种方法和最逻辑但有限的(仅向前和向后移动)是模拟mac命令键(箭头)(用于向前和向后),因此无论何时需要我们重新创建这些命令 这三种方法是向前迈进的,但不允许我们实时绘制或修改演示文稿的部分内容,寻求建议。 先感谢您

DisposableAction和Marshal.ReleaseComObject

做一些办公室Interop,代码是Type try { selection = getSelected(Return.Some.Office.InteropObject); for ( int i = 0 ; i < selection.count ; i++) yield return selection.item(i) } finally { Marshal.ReleaseComObject(selection); } 想知道用DisposableAction替换它是否是个好主意并改为 using ( var a = new DisposableAction(getSelected(Return.Some.Office.InteropObject)) ) { foreach(var b in a.Items) yield return b; }

Outlook MailItem作为流

是否可以直接将MailItem作为Stream返回? ( 来自Microsoft.Office.Interop.Outlook MailItem ) 现在我找到了一个临时解决方案,首先将MailItem保存到目录,打开它并将流返回到文件,然后再次删除该文件。 这个临时解决方案在处理大量电子邮件时很慢,我想用例如直接将MailItem作为MemoryStream返回来替换它。 如何才能做到这一点? ( 由于评论编辑:缓慢是一部分,但另一个代码部分(无法修改)只接受一个流,这就是我正在寻找一个解决方案来打开一个MailItem作为流)

在ppt中保存幻灯片时保留源模板

我正在尝试保存选定的幻灯片,因此它不会保留我的源模板。 在保存幻灯片时如何保留现有模板 private void SaveSelectedSlide_Click(object sender, RibbonControlEventArgs e) { try { PowerPoint.Application ppApp = Globals.ThisAddIn.Application; PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange; string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue); Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = ppApp.ActivePresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText]; for (int i = 1; i <= ppslr.Count; i++) { var sourceSlide = ppslr[i]; sourceSlide.Copy(); var design = sourceSlide.Design; temporaryPresentation.Slides.Paste(); } temporaryPresentation.SaveAs("Temporary", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue); […]

80040154 Outlook 2010中未注册ERROR的类添加

我正在使用Visual Studio 2010创建Outlook 2010添加。 我尝试创建一个新的Outlook AppointmentItem来考虑我最终可以将它添加到日历中。 Microsoft.Office.Interop.Outlook.AppointmentItem tempApp = new Microsoft.Office.Interop.Outlook.AppointmentItem(); 但是当AddIn运行并尝试创建AppointmentItem对象时,我在上面的行中收到此错误。 System.Runtime.InteropServices.COMException was unhandled by user code Message=Retrieving the COM class factory for component with CLSID {00061030-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). Source=mscorlib ErrorCode=-2147221164 我可以做些什么来“注册课程”? 我猜这与某些方面的Microsoft.Office.Interop.Outlook.dll有关。

COMexception80040154创建Excel应用程序时

我正在尝试在没有安装Office的服务器上运行我的应用程序。 using EXCEL = Microsoft.Office.Interop.Excel; … EXCEL.Application app = new EXCEL.Application();//Exception thrown here 代码在我自己的系统上工作正常,但在服务器上它提供以下exception: Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {…} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 两个系统都是32位,我在应用程序的exe旁边复制了excel Interop dll。 我还安装了O2010PIA 。 任何铅?

使用互操作将多个单词表添加到单词中

我正在尝试使用c#将多个表插入到word文档中,但是当我添加另一个代码块来添加表时,我收到错误而第二个表没有被插入。 如何将范围向下移动到页面底部,然后添加另一个表? 我尝试使用文档参考结束创建一个新范围,但这似乎不起作用,任何人都可以给我一些帮助吗? Word._Application objApp; Word._Document objDoc; try { object objMiss = System.Reflection.Missing.Value; object objEndOfDocFlag = “\\endofdoc”; /* \endofdoc is a predefined bookmark */ //Start Word and create a new document. objApp = new Word.Application(); objApp.Visible = true; objDoc = objApp.Documents.Add(ref objMiss, ref objMiss, ref objMiss, ref objMiss); //Insert a paragraph at the end of […]

检查Word是否可见时执行冻结

在执行某些任务之前,我要检查Word是否仍然可见。 问题是在关闭可见性检查后关闭Word 2010后执行只是冻结。 2007年不会发生。 //Initializing Word and Document While(WordIsOpen()) { } //Perform Post Close Tasks public bool WordIsOpen() { if(MyApp.Application.Visible)//Execution just freezes at this line after Word is not visible return true; else return false; } 有人以前看过这个问题吗? 有没有更好的方法来检查这个?

使绑定重定向适用于办公室加载项

我在我的Word插件中使用Microsoft.Bcl.Async,我的插件编译为exe(test_addin.exe)文件,从Microsoft Word作为程序集加载,当我直接启动可执行文件时,一切正常,但是当我从Word运行它时,我收到一个错误,说它无法加载Systems.Threading.Tasks程序集。 Could not load file or assembly System.Threading.Tasks… 看起来它与绑定重定向有关,当我尝试从Word运行应用程序时,它希望配置文件位于’C:\Program Files (x86)\Microsoft Office\Office15’文件夹中,并命名为WINWORD.exe.config ,遗憾的是不可能,因为我可能无权访问该文件夹。 我的test_addin.exe.config文件: 我已经尝试将AppDomain.CurrentDomain.SetupInformation.ConfigurationFile设置为指向正确的路径,但它似乎没有帮助,还有其他方法使其适用于Office加载项吗?