Best way to control Word from Windows Forms? - c#

I am updating a Windows Forms application that was written for Office 2003. It would open Word, populate it with text from the database, create buttons appropriate for the user's security roles, and handle button clicks. The old way was with CommandBars. The Word documents created this way were stored as DB Blobs, so they were only ever available via the Forms application. That is the functionality I need, but without CommandBars.
Now, we have the Ribbon, Action Panes, VSTO, and OpenXML. I know my way around C#, but I'm new to all of these technologies.
I imagine a solution where I set up a template with the proper buttons on a nice ribbon, and the buttons raise events. If someone just tried to use the template by itself, there would be no data and the events would do nothing. But my Windows Form could create a new document based on the template, populate it with text from the database, hide inappropriate buttons, and handle button click events. Easy peasy.
I began by adding a Word 2010 Template project and making a ribbon for it. It looks nice in the debugger. But, I can't create a new document with it from a Console app. Word launches, but the ribbon isn't there. There's a note in the documentation that "If a Microsoft Office Word template has managed code extensions, the project assembly is not called if the template is attached as a global template or loaded from the startup directory of Word. In addition, the document does not recognize the format of a template that is part of an Office solution." I believe this means my template is useless. I can't open Word and make a new document with my template or call the template from another project, so, pointless.
All the MS help has failed me, and mostly leads me in circles. I need some direction. For each piece of the scenario I described, what is the most appropriate modern technology? For each technology I need to use, what is the best resource for my situation?

Related

create Power Point Custom Element on the slide

I'm just wondering if it's feasible to create interactive custom element for PowerPoint and add it to presentation programmatically using OpenXml for example.
For instance, we can insert a picture on a slide. So, I want to insert a picture on the slide and be able to change size, colour or shape right in playing mode.
Another example, I want to have buttons on my presentation and be able to click on it to get some action done, again, right in playing mode. In other words, I want to make my presentation interactive during the playing mode.
The first thing that I came up with, is using VSTO to create a plug-in, however as far as I know VSTO and OpenXml give an opportunity to play with XML structure and that's it.
Maybe I googled it incorrectly and used wrong keywords but I've found nothing
UPDATE
One of the possible ways that it can be done with (I think so) is adding a custom object, like excel spreadsheet. However, in presentation mode, it's not interactive either.
VSTO can create COM add-ins that work with the PowerPoint object model directly; you don't necessarily need to do anything with XML.
You can also create add-ins using the VBA that's built into PowerPoint or distribute presentations that include VBA.
A VSTO or VBA add-in solution would require that the user install your software, which may or may not be practical in your situation.
VBA in the presentation file itself, saved as a PPTM rather than PPTX, could probably do all that you want to do. It would require no special installation, but the user's security settings would have to permit macros.
Anything that involves a code solution would need to be permissible under the user's or enterprise's security restrictions, of course.
While you can't change picture size etc in slideshow mode, you can add action buttons that add some forms of interactivity to your presentation; these require no code at all. It's a built-in PPT feature.

c# VSTO Host WPF form inside Excel sheet

I would like to embed a standalone WPF form inside an Excel sheet.
Microsoft provide information on how to host a WPF form inside an Excel Action Pane or Task Pane here: https://msdn.microsoft.com/en-us/library/bb772076.aspx
However, I'm unable to find information on how I can do this within the Excel sheet itself. Is this possible? Should I just load the form when the user clicks on the tab? Or is there a better way to do this?
I've never seen that anywhere so I guess it's not possible.
What I have done a few times (but never in production) is your second suggestion
Should I just load the form when the user clicks on the tab? Or is there a better way to do this?
Yes, this should work fine, there is something like WPF host you can use on standard form or create another project in your solution (WPF project) and call it from VSTO

Attach a .net control to a worksheet without VSTO (but Excel-DNA)

I'm trying to do something that I'm not sure is possible.
I want to use a .net 3rd party library that gives nice winform chart controls, to replace some (very complex and ugly) VBA generated charts in an Excel worksheet.
I'm using Excel-DNA (which is great BTW), and I managed to do all sorts of things with it, like displaying Winform forms in both sync and async way (thanks to https://github.com/Ron-Ldn/DotNetRefEdit)
So far, I managed to make my non modal form with the charts appear when I activate a particular worksheet, and by setting it's parent and topMost properties, it kinda have the expected behavior. But placing it is a real pain (different screen sizes) and I was wondering if there is a way to properly do it
So here's the question : Can I attach in some way a .Net form or a custom control to a worksheet, maybe even have it positionned relatively to a particular cell ? It must be non modal and it will display only if we are on a particular sheet.
I know with VSTO you could add a control to a worksheet, but I don't want to use VSTO. I also know that I could probably create my own ActiveX control and have it registered, and then place it in Excel like I would with another button control for example, but that seems hazardous according to what I read about it
Thank you for all ideas or suggestions
Consider creating a custom task pane (CTP) pinned to the right hand side of the Excel workbook (worksheets).
For more information on how to do this in ExcelDNA, see ExcelDNA GitHub Sample on CTP.

Insert outlook 2007 button within menu in C#?

In Outlook 2007 you have the navigation panel, consisting of "Mail","Calendar","Contacts","Tasks" etc (this is all below the tree structure).
1) Is it possible (and if so, how?) to insert another user-defined button between, say, "Mail" and "Calendar"?
2) Programatically, how could I minimise the main pane? So if I was in "Mail", the main pane would be "Inbox".
I have been using Add-in Express for customisation, but I dont believe it can do the above and could be a general .NET question.
Do you mean create an additional button inside Outlook, or reuse the button styles/etc in a 3rd party application?
If you mean inside Outlook, then yes, Outlook 2010 (not 2007) provides some OM hooks to add 1 additional button here. It's called the Solutions module. If there is only one solution installed, the name of the button takes the title of the solution. If there are multiple solutions then the title reverts to "Solutions"
If you mean outside of Outlook, then no. It's not possible. These buttons are not COM components (in fact, they're not even proper HWNDs).
1.) You cannot create new Navigation Modules in the Navigation Pane. See MSDN forums for related question.
2.) An Outlook View Control will let you takeover the currently active view pane.

C# Outlook Addin w/ WPF

I have looked at several tutorials on writing general Outlook add-ins, and have gotten simple examples to work: items in menu, context menu, ribbons, etc.
Many of Microsoft's documentation has send me in circles, or is in VB, so I have run into some questions with what we are trying to accomplish.
Is there a way to add a custom control below the Subject line in a new email? We need to supply a drop-down and add an additional header to emails sent for email tracking. Right now the best I have gotten is adding a CommandBarButton in the "Add-ins" tab of the Ribbon, is there a better method?
Will we run into any issues installing for multiple versions of outlook? (Will only 2007 and higher work?)
Can you host WPF controls directly in a Ribbon, etc.? I know that WPF popup windows work just fine when shown from a CommandBarButton.
Are there some good links out there for what we're trying to do?
2: Multi-version support is a PITA. The hedge-your-bets approach is to develop on a PC running the version of Outlook you want to support; thus you may have multiple setup packages for each supported version. Everybody tries to get around this though, but I've used this approach with success:
Version-Specific UI in Add-ins - Andrew Whitechapel - Site Home - MSDN Blogs:
http://blogs.msdn.com/b/andreww/archive/2008/09/02/version-specific-ui-in-add-ins.aspx
4: Essential resources:
Visual Studio Tools for Office For Office and Outlook for Developers Forums on MSDN
OutlookCode.com
(FYI, I work for Add-in Express)
No, not without implementing the entire message window.
We have to make 2 projects for 2007 and 2010, we are skipping 2003 and below b/c it is much more difficult and would be rarely used.
Can't host WPF in a Ribbon, we're going to display a WPF popup from a Ribbon button press.
Best thing I've found is to just follow the project template in Visual Studio and mess around.
Overall, our add-in is going to do the following:
Make 2 projects for 2010 and 2007 that share a "Shared" assembly
All reusable work is done in the shared assembly
WPF is only displayed via popup windows (you can do a custom task pane, but it doesn't make sense for our add-in)

Categories

Resources