vsto

Opening a saved workbook causes the current workbook to throw exceptions

本小妞迷上赌 提交于 2019-12-07 03:35:23
问题 I'm trying to open a save Excel workbook while keeping a reference to the current workbook. The issue is that as soon as I open the saved workbook, the original throws an exception upon access. Here's a code snippet to demonstrate. I put this in an event handler for a ribbon button to test it. try { string workbookPath = @"C:\Temp\Test.xlsx"; Workbook current = Globals.ThisAddIn.Application.ActiveWorkbook; Workbook newWorkbook = Globals.ThisAddIn.Application.Workbooks.Open(workbookPath);

c# excel beforesave thread

末鹿安然 提交于 2019-12-07 03:00:30
I try to create a c# excel 2007 Add-In, and i want to do "faster" the "beforeSave" method. I simply use a thread (and try the task and task.factory too) but its always say same error. The code. private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.WorkbookBeforeSave += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave); }// thisAddIn_startup method end public void Application_WorkbookBeforeSave(Microsoft.Office.Interop.Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel) { backendworker bwfs = new

How to center a WPF Window in a Excel VSTO addin

坚强是说给别人听的谎言 提交于 2019-12-07 01:30:57
问题 The problem is that a WPF window only takes a system.form.window so I cannot set Excel to be the owner object in my VSTO application, because the VSTO addin only exposes Excel's hwnd, or its active window as a Native Window since it is COM. That means when WindowStartUpLoadation is set to be center owner it doesn't work. So I am forced to work around this. What I have come up with so far after reading this site is to try and manually center the window, but even with his simple example my

Get the last cell (column, row) of a Excel range object

佐手、 提交于 2019-12-07 00:57:16
问题 I have a Microsoft.Office.Interop.Excel.Range object and want to estimate the end-coordinates of that range ie (last column, last row). There are no properties like LastCol , LastRow . The only properties are Column and Row , which specify the first cell. But how can I get the last cell of the range? 回答1: This should get the first first and last cell of the range: Initiate Excel. Open workbook. Select your range, in this case I got the used range of the active sheet. Call the get_address

Outlook : How to get email from Recipient field?

有些话、适合烂在心里 提交于 2019-12-06 23:26:39
问题 I'm attempting to get the email address typed into the To field of a compose mail window. I try to get the Address property of a Recipient, which according to VS, should give me the email. I am instead receiving a string that looks like this: "/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe" How can I get the email address in the recipient field? My code so far: List <string> emails = new List<string>(); if (thisMailItem.Recipients.Count > 0) { foreach (Recipient rec in

How can I add the images to button using the ribbon xml?

老子叫甜甜 提交于 2019-12-06 21:42:56
问题 How to add the custom images to the ribbon button in the tab and the context menu. I tried the link Adding Image to ribbon button but no luck :-(. I am designing the addin for Excel. I added this in the header. <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load" loadImage="Ribbon_LoadImage"> <button id="btn2d" keytip="L" screentip="2D Visualization" supertip="2D Part Visualization" label="2D" size="large"/> <contextMenu idMso="ContextMenuCell"> <button

Unit Testing VSTO projects

最后都变了- 提交于 2019-12-06 20:49:30
In most unit test tutorials I follow it has me create a second unit test project and then add a solution/project reference from the test project to the other project. I have a VSTO addin, and when I go to add the reference I don't see anything listed under Solution > Project. Why is this? How else can I add a reference to the addin project to test it? If this is your first time at unit testing, then VSTO might be a steep learning curve. As suggested by @Sam Holder, you might want to put some of your logic into a separate assembly to encourage you to separate your logic from your interactions

Deleting columns from a table with merged cells

对着背影说爱祢 提交于 2019-12-06 19:29:50
问题 I'm trying to delete columns from a table which has horizontally merged cells Selection.MoveEnd Unit:=WdUnits.wdCell, Count:=3 Selection.Columns.Delete Eventhough columns are getting deleted, merged cells are removed in the process leaving a broken table. Almost similar approach to delete rows works fine as explained in this answer Workaround I'm doing something like this as work around Selection.MoveEnd Unit:=WdUnits.wdCell, Count:=3 Selection.MoveDown Unit:=WdUnits.wdLine, Count:=2, Extend:

Adding items to RibbonDropDown at runtime

落花浮王杯 提交于 2019-12-06 18:33:35
问题 So I have a dropdown menu in a ribbon with contents that can be changed while it is being used. Outlook is also happy to let me 'add' or 'insert' items into it, as long as I do not add more than 1 item. If I try to, I'll be told that the index is out of bounds rather than expanding the upper bounds for me. I find that if I insert it into the collection in the designer portion of the code, it will work fine, but designer code is only run once, unless I Dispose the ribbon and re-create it. Any

Hooked events Outlook VSTO continuing job on main Thread

瘦欲@ 提交于 2019-12-06 17:01:01
问题 I have developed an Outlook VSTO addin. Some tasks should be made on a background thread. Typically, checking something in my local db or invoking a web request. After reading several posts, I dropped the idea of calling the Outlook Object Model (OOM) in a background thread. I have some wpf controls and I successfully managed to use the .NET 40 TPL to perform the async task and when completed to "finish" the job (i.e. accessing the UI or the OOM) in the Main VSTA Thread. To do so I use a