Posts Tagged “Open XML SDK”

Once again, a question on Stack Overflow offered an intriguing problem that kept my brain busy for quite a while. When generating a table in a Word document cells containing no content would not retain the custom font size being assigned to each cell. Read the rest of this entry »

Comments No Comments »

In both the posts about Coercion types in Word Web Add-ins and reading built-in document properties a key point is using the Word Open XML file format in order to achieve something not available in the APIs. This approach works only in Word and it can be used for almost anything. Even the newer, extended APIs that will be released for Office 2016 won’t (initially) provide functionality for everything that can be contained in a Word document. So working with the Word Open XML file format is a useful tool for the JavaScript as well as the VBA and .NET developer. Read the rest of this entry »

Comments No Comments »

As more and more developers migrate to Visual Studio 2012 and/or Visual Studio 2013, we’re seeing requests in the Open XML SDK forum for a version of the Open XML Package Editor that works with these new versions of Visual Studio.

(The Open XML Package Editor lets you view the structures and XML content in an Office Open XML zip package and edit it, something the Open XML SDK Productivity Tool does not support.)

Unfortunately, at the time of this writing, Microsoft has not updated the tool – originally written for Visual Studio 2010 – nor released a new version. Luckily for all of us, a resourceful colleage of mine who attended my seminar in LucerneDr. Eckehard Pfeifer – did some research that he said I might share :-) Read the rest of this entry »

Comments 2 Comments »

A few days late for my seminar, but it’s finally here! Despite Microsoft Press’s break with O’Reilly, leaving authors in the German market in limbo, the 4th edition of the Word Programmierung Handbuch has been printed, bound and is being distributed this week.

Many thanks to the publisher for managing to accomodate all the new material without needing to throw out as much of the existing as we feared would be necessary. Instead of just over 1000 pages, the 4th edition has 1145, more than 250 completely new! Read the rest of this entry »

Comments 2 Comments »

There was a discussion in the Open XML SDK forum today that I found interesting. Certain namespaces for Office 2010 weren’t being recognized with a reference to the Open XML SDK version 2.0, even though they should have been. The references were being picked up just fine with a reference to the newer Open XML SDK 2.5, however.

When I tested I had no problems using the namespaces. Luckily, I thought to include the version number of the Open XML SDK runtime in my reply. Turns out that Microsoft replaced the original download with a newer version without any public notification, either about the fact that it was being done or mention about problems with the older version. When the OP downloaded the newer version, the problem disappeared!

So if you need to use the older version of the Open XML SDK and are having problems with any namespaces that belong to DocumentFormat.OpenXml.Office2010.Word.DrawingShape, try uninstalling, downloading a newer version and re-installing. You need a version that starts with v2.0.5###; the problem was ocurring in v2.0.4###.

Comments No Comments »

In my last post I described how to achieve a continuous section break in Word Open XML. In this post, I go into how to force the continuous section break in the middle of a paragraph. Read the rest of this entry »

Comments 4 Comments »

There was a question the other day in the Open XML SDK forum about inserting Continuous section breaks. Inspecting a document.xml file, you’d think it would be as simple as adding a SectionType child element to a SectionProperties element associated with a paragraph’s properties, as can be seen in the following Word Open XML:
<w:p><w:pPr><w:sectPr w:rsidR=”0008038F” w:rsidSect=”00C26E80″>
  <w:type w:val=”continuous”/>
   <w:pgSz w:w=”11906″ w:h=”16838″/>
   <w:pgMar w:gutter=”0″ w:footer=”708″ w:header=”708″ w:left=”1417″ w:bottom=”1134″ w:right=”1417″ w:top=”1417″/>
   <w:cols w:space=”708″/><w:docGrid w:linePitch=”360″/>
</w:sectPr></w:pPr></w:p>

If only it were that simple! Read the rest of this entry »

Comments No Comments »

Since time immemorial, you’ve been able to save formatted and unformatted text for re-use in Word. Originally, this was called “AutoText”; in Office 2007 it was renamed “BuildingBlocks”.

These can only be saved in Templates. Originally, they were saved by default to Normal.dot; since 2007 the default storage is an independet file, “Built-in Building Blocks.dotx”. But you can choose any document of type template.

The user can choose an entry from a list and Word will insert it at the current selection. The Word APIs also provide access to this functionality.

But what’s the situation with the Word Open XML file format? Is there a simple way to insert AutoText/Building Blocks from a template “container” into a document? Read the rest of this entry »

Comments No Comments »

In my last post I showed how to change the target version of Word for a document using the Open XML SDK in order to ensure that “[Compatibility Mode]” does not appear in the document’s title bar. The code sample was in C#.

In this post I provide the code sample for VB.NET. Due to a bug in VB.NET Linq, it’s not possible to use the same “simple” approach as for C#. VB.NET Linq does not recognize the URI property as a property for the Compatibility Setting. The VB.NET equivalent of the C# approach (included near the end of the code sample, but commented out) causes an error. Read the rest of this entry »

Comments No Comments »

A relatively frequent request we see in the Open XML SDK forum is how to make the [Compatibility Mode] text in the Word title bar disappear.

By default, the Open XML SDK will create a document compatible with Word 2007. When opened in a later version of Office, [Compatibility Mode] appears in the document title bar. The question is, how to make the document a Word 2010 or Word 2013 document. Read the rest of this entry »

Comments 1 Comment »

There is apparently a bug in the Open XML SDK 2.0 when trying to work with a document that contains a Ribbon extension using the namespace for Office 2010 <customUI xmlns=”http://schemas.microsoft.com/office/2009/07/customui“>

If the document contains a customUI12 part, you get the error ArgumentOutOfRangeException when using WordProcessingDocument.Open.

The problem appears to be fixed in Open XML SDK 2.5, which requires the .NET Framework 4.0. Read the rest of this entry »

Comments No Comments »

A fairly common question in the world of Word Development is how to merge multiple documents into one. (See for example this discussion in the MSDN Open XML SDK forum.) Read the rest of this entry »

Comments No Comments »

Once again, a forum question has prompted a topic for my blog. This time, it comes from the discussions about developing for Office 2013.

For many years, a main focus of my work with Word has been related to importing and exporting data into and out of Word documents. The built-in functionality for this has always been “mail merge”. So I’ve worked with mail merge a lot. Unfortunately, it hasn’t really evolved since the early days of Word, around 1990. The only significant change occurred in Word 2003, when OLE DB became a supported connection method to the data source (and the default). Read the rest of this entry »

Comments 2 Comments »

Changes in the Word Open XML for comment’s functionality in Word 2013 were presented in my last post. This time, we’ll look at how these changes affect working with Comments using the Open XML SDK. Read the rest of this entry »

Comments No Comments »

As described in earlier posts, Word 2007 and Word 2010 don’t properly save number formats to number-type form fields. So I decided to try my hand at my first serious manipulation of Office Open XML files. As I felt more comfortable with old-fashioned XML coding, the tool presented in that post only leveraged the Open XML SDK for opening the file “package” and obtaining the required Part from the package.

Once it was clear that my approach did work, it was time to see if I could do the same using the full capabilities of the Open XML SDK. Read the rest of this entry »

Comments No Comments »

No question: I’m object model-oriented. It didn’t take me long to recognize the advantages of object-oriented programming over Word Perfect keyboard macros and the user action emulation of WordBasic when VBA was introduced in the mid-90s! Read the rest of this entry »

Comments No Comments »

Having overcome the obstacle mentioned in my last post, I continued work on a small tool to manage the number formatting of number form fields in Word documents. While becoming acquainted with the principles of Open XML I’ve always felt there are too few samples demonstrating how to work with the various Office applications. So I plan to share some of my code in this blog. Read the rest of this entry »

Comments No Comments »

I thought it would be really cool if I could post code that would modify Word 2007 and Word 2010 documents to fix the numbering format problem described in my last post without needing to use Word 2013. I was stymied for three days by the error message:

 “The specified package is invalid. The main part is missing.”

It came up part of the time, but not all the time, for Word documents of all types when I tried to open them like this:

WordprocessingDocument doc = WordprocessingDocument.Open(openXMLFileName, true);

The error message is mentioned often in questions in various forums, but I could almost never find a resolution for it and the questions that were answered were not for my scenario. One piece of information did help me, though: the actual cause comes from the underlying System.IO.Packaging namespace. The message indicates that System.IO.Packaging doesn’t find valid parts and relationships.

Sure enough, when I checked for the number of Parts in a document I got 0 (zero). This was extremely puzzling and I lost a few hours sleep. The next morning a moderator in the Open XML SDK forum confirmed that he had no problems accessing the files. So the issue was certainly due to my machine’s configuration. What next?

I finally decided to test files from a different Windows folder as I was beginning to suspect a permissions problem. Sure enough, documents in “My documents” worked without a hitch. Using the Windows Share wizard, I granted “share” permissions to “everybody” for the folder with my test files – et voilà, problem solved!

Comments No Comments »