OpenXML alternative for Microsoft Office Interops "SelectContentControlsByTitle" in C# - c#

The project in which I'm involved has a requirement of generating Word documents.
Initially, I used Interop to achieve this. But since Interop requires the clients to have Office installed on their machines, I switched over to OpenXML instead.
Interop has a nice method for getting Content Controls by title "SelectContentControlsByTitle", is there any alternative to this in OpenXML?
Cheers!

Related

Netoffice progid not found

I've done find and replace solution in Micorsoft.Office.Interop.Word in asp.net I would like to move this solution on NetOffice in my asp.net server where there is no Microsoft Word. I got error
progid not found
. What I do wrong because on my computer where I have Microsoft Word this code work fine in NetOffice?
Word.Application wordApp = new Word.Application(); <-- here is this error
NetOffice is just a COM Wrapper to the office applications, therefore it requires that you have the office app installed on the machine where your application is running.
i.e. You need to have Microsoft Word installed on any machine that you intend to run an app that uses NetOffice.Word.
If this was a desktop app, all you would have to do, would be to install Word on the machine, but given you want to use office automation from a server, and Microsoft does not recommend it, you should look into other options of interfacing with Word documents directly via OpenXML without having to install Word on the machine.
I'd recommend taking a look at the DocX library:
https://github.com/WordDocX/DocX
As well as the articles below:
How to: Create a word processing document by providing a file name (Open XML SDK)
Edit Word Documents using OpenXML and C# Without Automation/Interop
Your code should work with NetOffice, but you need to add a using statement:
using Word = NetOffice.WordApi;
You also need to disable the setting Embed Interop types for all NetOffice DLL's.

How to create Word document in WinRT

I'm currently developing application using WinRT/C#. It is second version, first was developed on WPF. In application I need to generate some reports and export them into MS Word document.
In first version of application I used MS Office Interop to export reports in MS Word, but in WinRT there is no support of MS Office Interop. Is there any simple way to create MS Word document in WinRT? (I know there are third party libraries like Syncfusion for WinRT but I would prefer to not use them).
You won't be able to use MS Office interop from a Windows Store app. You could use Open XML SDK, though. It is also available on NuGet and seems to be WinRT compatible.
Using it won't be as easy as working with interop classes and you'll only be able to create XML based docx files, not binary doc files. On the other hand your users won't need to have Word installed and they'll be able to open the files in other Office suites like OpenOffice or LibreOffice. There's a set of tutorials available on MSDN to get you started.
There is a free solution that consiste to format your document in rtf.
For this i create a new librairy to help a developper to create a document compatible with word.
you can find this there : https://github.com/crogun/WinRTF-For-WinRT
the code is open source, and you can extend it if you want.

Access to office 2003 files

I want to access to office 2003 files (.doc, .xls and .ppt) in order to extract text and some metadata (number of words, number of sheets, pictures, template, etc.). I'm able to do it with Open XML SDK for office 2007 documents. However, this extracton will take place on a server, which can't have apps like Microsoft Office installed (that's the reason why I can't use Office's Interop).
I have tried NPOI, however actually it only supports .xls files. The other libraries that I found are not open-source, I can't use it on my work... I downloaded NPOI Scratchpad but the code is very "raw", I can't use it on my work.
Do you have any other idea to get the text and metadata from office 2003 documents? I'm not a very experienced programmer, and I'm using C# (However, if there is any solution to this problem in C++ I could consider to use it). Thanks.
There are many libraries like:
ClosedXML (Office 2007)
EPPlus (Office 2007)
Aspose cells(Office 97-2010, I use this one)
I don't know any free libraries supporting office 2003 format.
good luck

Read (and write) Office document custom properties without automation

I am looking for a solution for reading (and possibly writing) custom properties of Office documents (both old and new formats) without resorting to Office automation.
I have found Dsofile.dll which seems to work good for old formats but chokes on new ones with a "class not registered". KB remarks say that a certain "Office Compatibility Pack" needs to be installed for this to work but I am really looking for an out-of-box solution.
I am not searching for a solution that reads (and writes) custom properties without Office installed. Actually, I am considering Office to be a prerequisite. It is just that I want a solution that does not require Office automation for simple custom property handling.
There is a "Microsoft Office Metadata Handler" Windows Explorer Shell Extension that shows/manages custom properties for Office documents pretty much the way I want to do it. With Dsofile.dll I seem to have one half of the solution by covering old Office formats.
DSOFile is what to use for the binary formats.
For the newer formats, you can just use XML (Open XML SDK is a fine choice, but you can also just access the DOCX/XLSX/PPTX file formats with System.IO.Packaging in .NET if you don't want to be all that heavy handed with yet-another-dll). See this article for accessing and setting properties: Manipulating Word 2007 Files with the Open XML Format API (Part 2 of 3)

Using Office 2007 PIA's against OpenOffice.Org

I have been using Office 2007 PIA's to run PowerPoint files in my C# application.
I know that this requires Office 2007 to be installed on the machine.
I wanted to know, can the same set up be run with OpenOffice.org installed instead of Microsoft Office?
Note: I am using a Qindows machine.
While OpenOffice does have an Automation Bridge which allows you to access OpenOffice applications in Automation (a proper subset of COM which in turn you can access through COM Interop), the API profile is most definitely not the same.
That being said, any code that you write which uses the Office 2007 PIAs will not be compatable with the Automation model provided by OpenOffice.
Granted, you can probably do many of the same things that you could do in Office, it's just the way you would go about doing them (the methods you call) would be completely different.
In a word, No.
The PIAs contain mapping information specific to the DLL that they wrap, in your case MS Office application DLLs.

Categories