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
25
votes
2 answers

Add HTML String to OpenXML (*.docx) Document

I am trying to use Microsoft's OpenXML 2.5 library to create a OpenXML document. Everything works great, until I try to insert an HTML string into my document. I have scoured the web and here is what I have come up with so far (snipped to just the…
JasCav
  • 34,458
  • 20
  • 113
  • 170
24
votes
2 answers

cannot preserve space between runs

i want to generate a word document as an input i have this string "open packaging conventions" and each word will have a different style the result should be open packaging conventions WordprocessingDocument document =…
Cerise Frutta
  • 241
  • 1
  • 2
  • 4
24
votes
5 answers

Merge multiple word documents into one Open Xml

I have around 10 word documents which I generate using open xml and other stuff. Now I would like to create another word document and one by one I would like to join them into this newly created document. I wish to use open xml, any hint would be…
Incredible
  • 3,495
  • 8
  • 49
  • 77
23
votes
12 answers

Replace bookmark text in Word file using Open XML SDK

I assume v2.0 is better... they have some nice "how to:..." examples but bookmarks don't seem to act as obviously as say a Table... a bookmark is defined by two XML elements BookmarkStart & BookmarkEnd. We have some templates with text in as…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
23
votes
2 answers

How to create Excel file using OpenXML without creating a local file?

Is it possible to create and edit an excel document using OpenXML SDK without creating a local file? As per the documentation the Create method demands for a filepath, which creates a local copy of the file. SpreadsheetDocument spreadsheetDocument =…
Bishnu Das
  • 462
  • 1
  • 3
  • 9
23
votes
7 answers

How to insert a date to an Open XML worksheet?

I'm using Microsoft Open XML SDK 2 and I'm having a really hard time inserting a date into a cell. I can insert numbers without a problem by setting Cell.DataType = CellValues.Number, but when I do the same with a date (Cell.DataType =…
Manuel
  • 10,869
  • 14
  • 55
  • 86
22
votes
1 answer

C# Open XML 2.0 NumberFormatId range

Working with Open XML 2.0 using c# to parse large excel files. Issue I'm running into is the cell I'm parsing does not have a DataType I then check the NumberFormatId to determine if it is decimal, number or date. I'm looking for the exact…
maguy
  • 1,599
  • 1
  • 15
  • 26
20
votes
2 answers

Open XML SDK 2.0 to get access to excel 2010 worksheet by name

I have an Excel 2010 spreadsheet that has 3 worksheets named Sheet1, Sheet2 and Sheet3. I'm trying to get a reference to a worksheet by name. I'm using the code: using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(FileName, true)) { …
Rick Hodder
  • 2,189
  • 3
  • 26
  • 54
20
votes
6 answers

OpenXML: Auto Size column width in Excel

I have written a code to generate Excel file using OpenXML. Below is the code which generates the Columns in the Excel. Worksheet worksheet = new Worksheet(); Columns columns = new Columns(); int numCols = dt1.Columns.Count; for (int col = 0; col <…
Mittal Patel
  • 808
  • 1
  • 22
  • 37
19
votes
3 answers

Creating custom column widths in OpenXML (excel)

I am new to OpenXML (v. 2.5), and I can create rows and cells, but I need to be able to set the column width and I can not do that correctly for some reason. Without this code: Columns cols = new Columns(); Column c1 = new…
Reid
  • 4,376
  • 11
  • 43
  • 75
19
votes
1 answer

Cannot insert the OpenXmlElement "newChild" because it is part of a tree

The Title states the error I am getting. I'm trying to hide all the text in a word doc using OpenXml. Currently when I try and append the Paragraph properties I receive the above error. I can't find much about this error online. Code that returns…
user1704863
  • 394
  • 1
  • 6
  • 19
18
votes
1 answer

What is the difference between CellValues.InlineString and CellValues.String in OpenXML?

I am trying to write some code to generate an Excel spreadsheet and I am not sure what the difference between CellValues.InlineString and CellValues.String to insert text on the cells. Shall I use this: private void UpdateCellTextValue(Cell…
mhttk
  • 1,688
  • 1
  • 16
  • 29
18
votes
2 answers

Using OpenXmlReader

I hate to resort to StackOverflow for something so (seemingly) basic, but I've been fighting with Microsoft for the last few hours and seem to be hitting a dead end. I am trying to read (large) Excel 2007+ spreadsheets, and Google has kindly…
Argent
  • 795
  • 2
  • 7
  • 25
17
votes
4 answers

How to generate Table Of Contents using OpenXML SDK 2.0?

Using the SDK I'm building Word documents that contain reports. These documents need to have TOC. Does anybody have a complete solution that I can follow in order to understand how to do this? (I've read everything on http://openxmldeveloper.org/)
Yeseanul
  • 2,787
  • 4
  • 21
  • 25
17
votes
4 answers

How to retrieve Tab names from excel sheet using OpenXML

I have a spreadsheet document that has 182 columns in it. I need to place the spreadsheet data into a data table, tab by tab, but i need to find out as I'm adding data from each tab, what is the tab name, and add the tab name to a column in the data…
Kwalke001
  • 173
  • 1
  • 2
  • 7