Ilyas
Ilyas

Reputation: 305

Add header to word, and rotate it - with OpenXML

I am currently working on a project where I am using OpenXML SDK and MS Word. I am adding a custom header to the word documents by using Open XML SDK and c#. I am adding the header by using the code as provided here: https://msdn.microsoft.com/en-us/library/office/cc546917.aspx

I need to rotate the header, so it is pointing vertically down the page and is is aligned on the right side. I need som help and tips to do that. If somebodys got some tips or code samples for that, please post it here.

I am new to OpenXML developing, so if you know about any good page I can follow for references, please post that also.

Upvotes: 1

Views: 896

Answers (2)

Rendition
Rendition

Reputation: 504

In order to explore your document, you can use the OpenXML tools provided by Microsoft here: https://www.microsoft.com/en-gb/download/details.aspx?id=30425. When you click download you will see two files including the tools one.

The very useful thing is to create what you want in word manually, find the section using the explorer and then reflect the code. This gives you a great idea of how to implement it in your app.

XML Productivity Tool: Explorer

XML Productivity Tool: Reflected Code

Upvotes: 2

Daniel Brixen
Daniel Brixen

Reputation: 1663

My advice would be to start in Word: try producing a small example of the kind of document you want to produce in code. Then inspect the XML produced by Word, this will give you a good idea of how to produce the document using the OpenXML SDK.

To produce a 'vertical header' you could 'open the header' fx by double-clicking in the top of the document in Word. Then insert a text-box containing the text you want in the header. Make sure to align this text-box to the right side of the page (Layout -> Position -> Position in Top Right with Square Text Wrapping).

As you probably know the docx-file is simply a zip-file, so unzip it and look at the xml in the files word\header1.xml, word\header2.xml, word\header3.xml. (The xml is a bit overwhelming because word inserts a <Choice>-element using either <wps:txbx> or <v:textbox> to produce the textbox.)

MSDN has some excellent stuff, also check out Eric Whites blog.

Upvotes: 2

Related Questions