Office.Interop - Access MS Word Advanced options - c#

I would like to programatically (C#) change the MS Word Advanced option: "Do not compress images in file" using Office.Interop.
How can I do this.
I have looked through the MSDN Library but don't see what I need.

Sorry, but the "Do not compress images in file" option is not accessible via the VBA object model.
Although you could use SendKeys, doing so is not reliable - amongst other things, you can only toggle the setting with SendKeys; you can't test it's current state or set it to a particular state and the keystroke sequence required to access it might change according to which languages a user has installed and which Word version is in use.
Source : http://answers.flyppdevportal.com/MVC/Post/Thread/c87d426e-3571-44a7-85a5-2d7edfa4ce60?category=worddev
Another source with more information (on Powerpoint, but it works exactly the same way as for Word) :
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_other/vba-turn-off-auto-compression/9548f7c0-894d-4e76-acc1-4985df08fd50

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/

How to get installed image editors

Is there a code to get all the image editing software the user has installed?
I would like to know how to list all the applications by going through registry, is there any way to then filter out only the apps that can edit images, like Paint, Photoshop, etc...?
Thanks!
Here is an example for any generic file type:
How to get recommended programs associated with file extension in C#
If you look for jpg, png, etc. you'll get image editors.
No.
There is no expectation that every application developer somehow places metadata tags for their application inside of the registry (or wherever)... and, if for some reaosn a few handful of application developers did there is no way to guarantee the consistancy. Not to mention that application developers don't always use the common words you'd expect for their applications... Not every image editing application has the word "Photo" in it (for example, Picasa from Google).
The best you can hope for is to build some keywords to look for, add in a list of famous applications that don't conform to the keyword conventions your expecting ("Paint", "Photo", "Image", etc.), and work with that... either that or create a large database yourself to check against. Also, as other answers/comments have indicated, looking for applications that are used for specific extensions is helpful.
Nothing guaranteed though.

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

Windows App spellcheck

I was wondering if there is another way to spell check a Windows app instead what I've been of using: "Microsoft.Office.Interop.Word". I can't buy a spell checking add-on. I also cannot use open source and would like the spell check to be dynamic..any suggestions?
EDIT:
I have seen several similar questions, the problem is they all suggest using open source applications (which I would love) or Microsoft Word.
I am currently using Word to spell check and it slows my current application down and causes several glitches in my application. Word is not a clean solution so I'm really wanting to find some other way.. Is my only other option to recreate my app as a WPF app so I can take advantage of the SpellCheck Class?
If I were you I would download the data from the English Wiktionary and parse it to obtain a list of all English words (for instance). Then you could rather easily write at least a primitive spell-checker yourself. In fact, I use a parsed version of the English Wiktionary in my own mathematical application AlgoSim. If you'd like, I could send you the data file.
Update
I have now published a parsed word list at english.zip (942 kB, 383735 entries, zip). The data originates from the English Wiktionary, and as such, is licensed under the Creative Commons Attribution/Share-Alike License.
To obtain a list like this, you can either download all articles on Wiktionary as a huge XML file containing all Wiki- and HTML-formatted articles. This is then more or less trivial to parse. Alternatively, you can run a bot on the site. I got help to obtain a parsed file from a user at Wiktionary (I seem to have forgotten his name, though...), and this file (english.txt in english.zip) is a further processed version of the file I got.
http://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck.aspx
I use Aspell-win32, it's old but it's open source, and works as well or better than the Word spell check. Came here looking for a built in solution.

Retrieve file properties

When in Windows XP, if I open the properties window for the file and click the second tab, I will find a window where to add attributes or remove them.
While developing things, I noticed there was actually something I wanted to know about the file. How to retrieve this data? It's a string with name 'DESCRIPTION'.
The actual tab is saying 'Custom'. I think it's called metadata what it shows.
I noticed that only the files I'm looking at have that tab. It seems to be specific only for the SLDLFP -file.
Not on an XP machine, but I think this might work
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("path.txt");
string desc = myFileVersionInfo.FileDescription;
I think the custom tab is only available for Office documents, and display custom properties (In Word, File -> Properties, Custom tab).
The best way to get the information would be by using MS Office hooks. Last time I did anything like this, it was using OLE Automation, so good luck!
Edit:
Since you added a mention of SLDLFP, I'm guessing that you are working with SolidWorks files.
There may be some standard APIs for this, but none that I have heard of.
Using SolidWorks via Automation is probably going to be your best bet.
I found a link describing how to read these kind of values with a Word 2003 and VB.Net, I would expect that it is similar to how to do this with SolidWorks.
Reading and Writing Custom Document Properties in Microsoft Office Word 2003 with Microsoft Visual Basic .NET
I think this applies to all microsoft office based documents (and not all the other files).
You might need to automate word/excel/powerpoint to get that info.
OR you might need some kind of a binary file reader for MSOffice based files to read the attributes.

Categories