Questions tagged [openxml-sdk]

The Open XML SDK for Microsoft Office is built on top of the System.IO.Packaging API and provides strongly typed part classes to manipulate Open XML documents.

Open XML is an open ECMA 376 standard and is also approved as the ISO/IEC 29500 standard that defines a set of XML schemas for representing spreadsheets, charts, presentations, and word processing documents. Microsoft Office Word 2007, Excel 2007, and PowerPoint 2007 and later versions all use Open XML as the default file format.

The Open XML file formats are useful for developers because they use an open standard and are based on well-known technologies: ZIP and XML.

The Open XML SDK for Microsoft Office is built on top of the System.IO.Packaging API and provides strongly typed part classes to manipulate Open XML documents. (Use version 2.5 whenever possible as it fixes some problems in version 2.0.) The SDK also uses the .NET Framework Language-Integrated Query (LINQ) technology to provide strongly typed object access to the XML content inside the parts of Open XML documents.

The Open XML SDK simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML Application Programming Interface (API) encapsulates many common tasks that developers perform on Open XML packages, so you can perform complex operations with just a few lines of code.

Above is taken from the Overview section here.

In 2015 the Open XML SDK was made open source, public on GitHub. Version 2.6.0 was released which fixes a bug in the way it works with System.IO.Packaging. It is otherwise the same as 2.5. More details are available here.

1516 questions
6
votes
2 answers

How do I unlock a content control using the OpenXML SDK in a Word 2010 document?

I am manipulating a Word 2010 document on the server-side and some of the content controls in the document have the following Locking properties checked Content control cannot be deleted Contents cannot be edited Can anyone advise set these…
Ryan Spears
  • 2,963
  • 2
  • 31
  • 39
5
votes
3 answers

Getting Started OpenXml and PowerPoint

I would like to develop a class library that could process PowerPoint templates, and populate formatted data. Mainly involving tables, labels, slide cloning. I would like to use Open Xml for this with .Net 4. I would like some recommendations and…
Aneef
  • 3,641
  • 10
  • 43
  • 67
5
votes
1 answer

OpenXml: Convert an XElement to an OpenXmlElement

How would I go about converting an XElement to an OpenXmlElement? Either my google-fu fails or this has not been addressed.
emd
  • 1,173
  • 9
  • 21
5
votes
6 answers

Replacing in inner Text in open xml element?

I'm using open xml SDK 2.0 and i'm kind off new to this. I have actually created a quickpart (containg content control) in my word 2007 document named "hello.docx". Now I need to copy the quickpart into the other location of the same document named…
shishi
  • 107
  • 1
  • 2
  • 8
5
votes
1 answer

Insert image from byte array into OpenXML CustomXmlBlock

I'm working with a template document that uses CustomXmlBlocks as placeholders to place tables and other information. I need to be able to place an image into one of these blocks somehow... even if it is placed into a run first. The images come back…
Sunspot
  • 53
  • 3
5
votes
7 answers

Excel Open XML error: "found unreadable content" when creating simple example

I am getting the ambiguous "excel found unreadable content" error when I try to open the document created by the following code: public void GenerateWorkbookFromDB() { //Make a copy of the template file …
Daniel
  • 161
  • 1
  • 1
  • 6
5
votes
3 answers

DocumentFormat.OpenXml Adding an Image to a word doc

I am creating a simple word doc, using the openXml SDK. It is working so far. Now how can I add an image from my file system to this doc? I don't care where it is in the doc just so it is there. Thanks! Here is what I have so far. string fileName…
twaldron
  • 2,722
  • 7
  • 40
  • 55
5
votes
1 answer

Open XML - find and replace multiple placeholders in document template

I know there are many posts on SO about this topic, but none seems to treat this particular issue. I'm trying to make a small generic document generator POC. I'm using Open XML. The code goes like this: private static void…
FMR
  • 173
  • 7
  • 17
5
votes
1 answer

What is the most efficient way to clone Office Open XML documents?

When working with Office Open XML documents, e.g., as created by Word, Excel, or PowerPoint since Office 2007 was released, you will often want to clone, or copy, an existing document and then make changes to that clone, thereby creating a new…
Thomas Barnekow
  • 2,059
  • 1
  • 12
  • 21
5
votes
1 answer

How to keep current style in when inserting via OpenXML SDK?

I have a docx document that I want to modify via OpenXML SDK. This document has a table with bookmarks in its cells. The cells have specific font settings, let's say it's Times New Roman, 14pt. When I try to insert some text like this: public…
Nu-hin
  • 691
  • 1
  • 7
  • 12
5
votes
2 answers

How to get MS Word total pages count using Open XML SDK?

I am using below code to get the page count but it is not giving actual page count(PFA). What is the better way to get the total pages count? var pageCount = doc.ExtendedFilePropertiesPart.Properties.Pages.Text.Trim(); Note: We cannot use the…
Ganapathi D
  • 81
  • 1
  • 5
5
votes
4 answers

Union with LINQ to XML

I need to union two sets of XElements into a single, unique set of elements. Using the .Union() extension method, I just get a "union all" instead of a union. Am I missing something? var elements = xDocument.Descendants(w + "sdt") …
user29439
5
votes
1 answer

Read excel by sheet name with OpenXML

I am new at OpenXML c# and I want to read rows from excel file. But I need to read excel sheet by name. this is my sample code that reads first sheet: using (var spreadSheet = SpreadsheetDocument.Open(path, true)) { …
barteloma
  • 6,403
  • 14
  • 79
  • 173
5
votes
1 answer

Show Reviewing Pane in Word Client by default

What I want: I'm editing a WordprocessingDocument, and adding some tracked changes in it. This part is done. Now, I want MS word to show all revisions by default, i.e., it shouldn't require user to click on the red side bar to open the tracked…
Ahmad Khan
  • 2,655
  • 19
  • 25
5
votes
2 answers

Copy Header and Footer to all other Documents OpenXML

We have a master docx with the header and footer in and nothing else (formatted with images). We have 100s of word documents with body content but no header and footer and we want to be able to process these when we populate them and add the header…
user351711
  • 3,171
  • 5
  • 39
  • 74