How to access an Office IEnumerable interface? - c#

I am trying to write a C# add-in for PowerPoint with VS2013. But (after some years of absence in programming :) I am struggling with C#.
Task is to let the user choose one installed proofing language and set it for all slides.
First, it seems that PowerPoint doesn't have a function for fetching the installed/available proofing languages, but obviously Word has. So I started with Word and found:
Microsoft.Office.Interop.Word.Languages
But I have not managed to get a collection of the proofing languages; it's an IEnumerable interface so I can't instantiate it.
What is the correct code for this?

You should use the Languages property to get the collection of languages.
_Application.Languages Property
Returns a Languages collection that represents the proofing languages
listed in the Language dialog box.
Here _Application represents the Microsoft Office Word application.

Related

Hide sections in a word document based on users responses to a series of questions

I'm looking for the best way to achieve the following workflow.
Ask a series of questions
Captured the responses
Use the answers captured to either hide or show certain aspects of word document.
Save the complete word document to a location (TBD).
I'm not a developer, so will need to source one who could pick this up, but before I do I wanted to know the best approach to this workflow.
Appreciate any feedback you can offer.
Cheers
There are several libraries for interacting with Word (.docx) documents in C#, such as NPOI and DocX, and it is not theoretically complicated to programatically populate a document based on user input and some decision tree and then save it somewhere locally or expose it for download via a web interface. But, keep in mind, that's only part of the solution -- apps have to be hosted, secured, monitored, etc., and that's where the "hard" part is likely to be.
If you are looking to accomplish this within an enterprise environment that uses Microsoft Office 365, you may not need a developer at all. Microsoft Flow / Microsoft PowerAutomate allows you to produce complex workflows such as the one you described. There's a very similar one listed here:
https://flow.microsoft.com/en-us/galleries/public/templates/3c651e28cded46aab2ba40a2c3116f30/create-word-and-pdf-documents-from-microsoft-forms/

SAP GUI Automation using C# - does sapfewse.ocx have a written developer documentation or api library?

Referring to this question here a past user was able to develop some C# code to perform SAP GUI Automation. However when looking online at tutorials/developer documentation for this library I was unable to find anything.
There are a lot of objects like like, GuiSession, GuiApplication, GuiConnection that I can't find information to online.
How would I go on to writing SAP GUI automation using C# without proper documentation?
There is very little documentation for SAP Scripting in general outside of the one resource posted in the linked question (http://www.synactive.com/download/sap%20gui%20scripting/sap%20gui%20scripting%20api.pdf).
However, I also found this resource (http://help.innowera.net/PR2008/2.00/SAP_Scripting_API.pdf) which is similar to the one above but I think has a bit more detail.
Further, there is a built-in help document within SAP that you can access from the "Customize Local Layout" Menu (click the Monitor Icon in the second-from-the-top toolbar or ALT+F12) and then selecting "SAP GUI Scripting Help"
All three of these resources are primarily for VB; however, the objects, methods and rules are nearly the exact same for C#.
That being said, I do not know of any API Documentation specific to C# at this time
How would I go on to writing SAP GUI automation using C# without proper documentation?
I suggest recording scripts in VB through SAP first so that you can at least get the IDs for each button, menu, and field you use for a particular report. Then you can copy the IDs from that script into your C#. Additionally, these VB scripts can help you determine which objects and methods to use in your C#.
You can access the script recording functionality through the same "Customize Local Layout" menu and selecting "Script Recording and Playback..."
This functionality records every mouse click and keyboard input inside of SAP in VB and stores the resulting script in %AppData%\SAP\SAP GUI\Scripts
As I find more resources for SAP Scripting with C#, I will post them here.
There's now this HTML documentation online:
SAP GUI Scripting API
GuiSession Object
GuiApplication Object
GuiConnection Object
Etc.
The documentation is in your Program Files > SAP. Then, search for this file "SAPGUIScripting.chm". This is the best documentation I've seen. It documents all class objects with their methods, properties and events. It will occasionally provide some direction on how to use some of the methods.
You can also click on the "SAP GUI Scripting Help" as seen below.
As far as using C#, you would use the methods and properties just like you would for any other C# object.
Best of luck and happy scripting!

VSTO add-in, access to both Excel and Word

I'm working on a VSTO add-in for Word 2010 (.NET Framework 4.6.1) in C#. This add-in is meant to produce Word documents from a template, using data from a few sources, a few of which (depending on the ) being one or more Excel workbooks.
I have been perusing the MSDN literature, but I feel as if I'm missing a crucial step.
Is it possible to access the Microsoft.Office.Tools.Word objects in the same add-in as Microsoft.Office.Tools.Excel objects? They each seem to rely on the Factory.GetVstoObject() method, which uses a factory object that is application-specific. I know I can use the normal Microsoft.Office.Interop.Word/Excel objects, but they aren't as useful.
I have been playing around with having two add-ins, one targeting Word and one targeting Excel, but I'm having a hard time getting them to see each other. If this isn't achievable as a VSTO add-in, can you reference multiple Office application object models in a standalone executable?
Is it possible to access the Microsoft.Office.Tools.Word objects in the same add-in as Microsoft.Office.Tools.Excel objects
Maybe not those exact types but you can find something similar. You can always drop down to pure COM/Ole Automation level completely by-passing VSTO APIs. Office is still exposing a COM API which VSTO I suspect is just wrapping into nicer c# classes.
e.g. from a c# Excel VSTO add-in you can fire up word document by:
try
{
var type = Type.GetTypeFromProgID("Word.Application");
dynamic app = Activator.CreateInstance(type);
app.Visible = true;
dynamic doc = app.Documents.Add();
doc.Content.InsertAfter("Hello world!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Note: I am using dynamic (one of the main purposes of dynamic in c# was to make COM easier) here so as to avoid dependence on any specific COM-type library. It's version neutral so it should work any Word version.
I know I can use the normal Microsoft.Office.Interop.Word/Excel objects, but they aren't as useful.
In what sense?
See also
Where to find OLE Automation's documentation, specifically this answer
Disclaimer I never have done any shared add-in I'm going to talk about here (#Cindy Meister would know more)
Till VS 2010 you could create a project called Office Shared add-in. Here is how it looked like in VS 2003
This would be, probably, something what you would need but as said it's no longer available and I seem to remember there were some issues with it anyway.
I found this post where the guy is trying to use something what would mimic the Office Shared add-in template. He claims it's working so that would be worth to try.
Otherwise you would have to use the Office PIA as #MickyD answered

building text editor with code completion feature

Presently I'm trying to build up a text editor for the PHP language which should have the feature of code completion, i.e. if i start to type a word a dynamically created drop down list will display all available keywords starts with my typed letters. Can any body suggest me how it can be done. Idea will be enough for me. If possible please provide me a link to such simple application build in C#.
Considering that in general it's not an easy task, so there is no some "easy" application.
Even if in general idea is not a rocket science. You need to define a dictionary of words, corresponding to some key. When you type "." (in C#) you have to pick from the dictionary all words corresponding to the key equal to the word found on left side from the "."
To do it real working applicaiton is not so easy. By the way I can recommend to have a look on MonoDevlop look on their editor.
I worked with it years ago to make a simple editor for DSL company needed, and spend not small amount of time to correctly understand intenals, integrate well "my new language", "detach" control from Mono and inject into our applicaitons, like a dockable window.
If I where you I would really try to avoid the wheel... code completion is something that most IDE's now come with so what you are after is already available...
That being said, what I would try would be to go over the PHP API and construct a Suffix tree. This type of tree usually allow for a fast way to look for a given word. Once you index the API, you would also add in any other variable the user adds while he/she is performing the actual programming.
You could kick the search automatically in your suffix tree after the user has entered the 3rd letter, or maybe provide means for the user to activate it manually, like the Ctrl-Space keyboard most IDE's (Visual Studio, Netbeans, Eclipse, etc) have.
Note that this could get tricky, since you might want to select the appropriate variable type.

Editing Microsoft Word Documents Programmatically

I want to know if this could be done.
I am building a data dictionary for our software system (school project), and I'm thinking of an automated way to do this. Basically I don't use much of Microsoft Word (2007), I only use it in documenting schools stuff, etc. I want to know if its possible to create/edit a Word document programmatically from a template.
The idea is, I will create a page on Word that contains an empty form that will be repeated on every page. For every data that I will input to my program, it will update the corresponding field in the form and skips to the next form.
The purpose of this, is to eliminate copy-paste methods (my habit) and to speed things up when doing the documentation.
Word automation, as suggested by others, will lead you to a world of hurt for two major reasons:
Office is not intended to be run unattended, so it can pop up message boxes at any time, and
It is (probably) not licensed to enable office functionality for computers which don't have it. If you generate a Word document on a web site using automation, you have to make sure that this functionality cannot be reached by computers which don't have office installed (unless they changed this rule in the last years).
I have used Aspose.Words, it costs a little, but it works well and is intended for this.
Not exactly sure what you really want, but creating word documents with c# shouldn't be any problem:
http://support.microsoft.com/kb/316384
If i find out your purpose correctly you need to visit this microsoft msdn link
Manipulating Word 2007 Files with OpenXML
Definitely possible. A fairly easy way of doing it using Office Automation. See this KB article for a basic sample: How to automate Microsoft Word to create a new document by using Visual C#
I think the main difference to that sample will be that you'll open your template and do SaveAs instead of creating a new document, but I can't remember exactly.
However, depending on your exact requirements, there might be better alternatives. For example, it's not recommended to do Office Automation on servers (including on webservers), so if that's needed you might want to look at something else.
You can use com interop of .net framework.
Understanding the Word Object Model from a .NET Developer's Perspective
Building COM Objects in C#
Using COM programming is not the best way as mentioned by erikkallen, I suggest using OPEN XML. It is really easy to use and your document generation operation will be very fast.
http://blog.goyello.com/2009/08/21/how-to-generate-open-xml-file-in-c-in-4-minutes/
http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx

Categories