Tag: office interop

C#Outlook 2007 COM互操作应用程序不退出!

任何想法为什么以下代码不退出通过COM互操作创建的Outlook 2007进程? Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); var item = app.Session.OpenSharedItem(“C:\\test.msg”) as Microsoft.Office.Interop.Outlook.MailItem; string body = item.HTMLBody; int att = item.Attachments.Count; (item as Microsoft.Office.Interop.Outlook._MailItem).Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard); System.Runtime.InteropServices.Marshal.ReleaseComObject(item); (app as Microsoft.Office.Interop.Outlook._Application).Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(app); System.Diagnostics.Debugger.Break(); 一个几乎相同的使用Word的片段工作,所以我想知道我是否忘记清理一些东西……

多DPI系统上的VSTO自定义任务窗口显示内容两次

我正在使用VSTO构建办公室插件。 在具有不同DPI设置的多个监视器的系统上,我的自定义任务窗格的内容在具有较高DPI设置的监视器上绘制两次: 只有较小的版本实际上响应用户输入。 较大的版本似乎只是一个放大图像。 我尝试过使用各种DPI相关设置,例如: 我的用户控件上的AutoScaleMode 。 我尝试了所有选项,没有变化。 使用SetProcessDpiAwareness将进程设置为DPI可识别 – 或不 – 。 我尝试了所有选项,没有变化。 使用app.manifest并将dpiAware设置为true和false 。 没变。 新的Web Addins没有这个问题。 此外,内部任务窗格没有此问题。 这是一个已知的问题吗? 我怎样才能解决这个问题?

如何逐行阅读MS Word段落和表格内容

我正在使用Microsoft.Office.Interop.Word在C#(3.5)中阅读word文档。 逐行读取,将行拆分为数组[]并处理每一行的行,并根据一些业务逻辑替换一些单词并在替换单词后,用转换后的行替换整行。 直到现在每件事情都很好。 现在我有一些word文档,那些是段落和表格。 我想逐一阅读表中的每一列,并替换特定列中列的内容。 更新 使用Office Automation 1. Opening word file. 2. Moving cursor to top of the document 3. Selecting first line using (`wordApp.Selection.endKey`) and processing all words 4. After processing the words replacing the selected line with the processed line. 5. Using wordApp.Selection.MoveDown(ref lineCount, ref countPage, ref MISSING); moving next line processed […]

Outlook筛选项 – 获取一周范围内的所有定期约会

我试图在周范围内获得所有约会,但重复出现的约会没有出现。 这是代码: var outlook = new Microsoft.Office.Interop.Outlook.Application(); var calendar = outlook.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); calendar.Items.IncludeRecurrences = true; string filter = String.Format(“[Start] >= {0} And [End] < {1}", DateTime.Now.Date.ToString("ddddd h:nn AMPM"), DateTime.Now.Date.AddDays(5).ToString("ddddd h:nn AMPM")); Outlook.AppointmentItem appointment; foreach (var item in calendar.Items.Restrict(filter)) { appointment = item as Outlook.AppointmentItem; if (appointment != null) { MessageBox.Show(appointment.Start.ToString()); } } 如何获取Outlook中显示的所有定期约会一周?

呼叫被被叫方拒绝了。 (来自HRESULT的exception:0x80010001(RPC_E_CALL_REJECTED))

我有一个小的C#Winforms应用程序,它使用Word.Interop获取单个邮件合并文档,复制每个部分,将该部分粘贴到它自己的文档中,并单独保存。 我保持(有时随机)收到错误消息: Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) 。 我测试了下面的代码,当我使用断点时,我从未收到过此消息。 但是,如果我让它运行不受限制,它似乎在我的行oNewWord.ActiveDocument.Range(0, 0).Paste(); 。 什么是更奇怪的,有时候我得到了预期的消息,其他时候处理似乎只是挂起,当我在Visual Studio中按PAUSE时,它显示我当前在我的exception消息框行。 有谁知道如何解决这个问题? 码: public void MergeSplitAndReview() { try { // Mail Merge Template Word.Application oWord = new Word.Application(); Word.Document oWrdDoc = new Word.Document(); // New Document Instance […]

如何以编程方式从图像列表中创建powerpoint

我已经看到了这个问题:以编程方式创建PowerPoint演示文稿 ,但该问题问“你能吗?” 答案是肯定的。 但我问“怎么样?” 特别是“从图像列表?” 这就是我打破ppt到图像的方法 var app = new PowerPoint.Application(); var pres = app.Presentations; var file = pres.Open(input, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); file.SaveAs(output, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue); file.Close(); app.Quit(); 我该如何反过来?

VSTOunit testing通过RequestComAddInAutomationService在C#.NET中添加Office

在过去的几周里,我一直在阅读各种StackOverflow问题和其他教程和文档(下面注意其中一些),试图找到一种unit testingVSTO AddIn的方法。 不幸的是,它总是在我的测试中导致E_NOINTERFACEexception。 我正在使用的代码如下 – 覆盖RequestComAddinAutomationService的ThisAddin部分类的一个提取,另一个描述测试实用程序接口的提取,测试本身,以及另一个程序集提取,certificateAddIn程序集及其内部对测试可见。 我的问题是 :为什么这不起作用? 我很确定这遵循VSTO测试的普遍接受的做法。 如果以下不再可能,那么应该如何测试VSTO? .NET remoting / IPC是唯一的解决方案吗? ThisAddin.cs public partial class ThisAddin { #region Testing Utilities private AddinHelper _comAddinObject; protected override object RequestComAddInAutomationService() { // This is being called when I debug/run my project, but not when I run the tests return _comAddinObject ?? (_comAddinObject = new […]

方法:使用.net在Word上添加多表

我尝试使用c#在word文档中添加多个表 // Tables is a list of items which I want to present each in a table foreach (List ClassTable in Tables) { // tbl is a “Microsoft.Office.Interop.Word.Table” // myRange is like MyDoc.Range(ref missing, ref missing) tbl = MyDoc.Tables.Add(myRange, ClassTable.Count(), 3, missing, missing); tbl.Borders.Enable = 1; RowCounter = 1; foreach (string[] item in TableContent) { […]

VSTO Outlook插件需要保存设置,最好的方法?

我正在写一个VSTO Outlook添加,我需要保存插件从Web服务获得的一些设置。 做这个的最好方式是什么。 注册? VSTO插件是否可以完全访问这样的操作? 也许包含设置的文件? 提前致谢。

DateTime.Now.ToString(“MM / DD / YYYY”)包含不正确的月份

所以我一直在将DateTime.Now.ToString(“MM/DD/YYYY”)到List(以及一堆其他数据),然后将这些列表写入Excel工作簿中的各个行。 这一切都很好(这是我经常做的事),除了月份。 我尝试过三次出口,每次我得到一个不同的月份; 第一次56 / 26-17,第二次2017年2月26日,第三次14/26/2017 ….