Skip to content

Commit 205f43b

Browse files
authored
Merge pull request #329 from OfficeDev/main
[admin] merge to live
2 parents 36affc3 + 9e74945 commit 205f43b

File tree

276 files changed

+9206
-11856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+9206
-11856
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,6 @@ __pycache__/
287287
*.odx.cs
288288
*.xsd.cs
289289

290-
docs/open-xml-docs/
290+
docs/open-xml-docs/
291+
samples/**/Properties/**/*
292+
samples/**/My\ Project/**/*

.openpublishing.publish.config.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,42 @@
66
"build_output_subfolder": "open-xml-docs",
77
"locale": "en-us",
88
"monikers": [],
9-
"moniker_ranges": [],
9+
"moniker_ranges": [
10+
"openxml-2.7.1",
11+
"openxml-2.7.2",
12+
"openxml-2.8.0",
13+
"openxml-2.8.1",
14+
"openxml-2.9.0",
15+
"openxml-2.9.1",
16+
"openxml-2.10.0",
17+
"openxml-2.10.1",
18+
"openxml-2.11.0",
19+
"openxml-2.11.1",
20+
"openxml-2.11.2",
21+
"openxml-2.11.3",
22+
"openxml-2.12.0",
23+
"openxml-2.12.1",
24+
"openxml-2.12.2",
25+
"openxml-2.12.3",
26+
"openxml-2.13.0",
27+
"openxml-2.13.1",
28+
"openxml-2.14.0",
29+
"openxml-2.15.0",
30+
"openxml-2.16.0",
31+
"openxml-2.17.1",
32+
"openxml-2.18.0",
33+
"openxml-2.19.0",
34+
"openxml-2.20.0",
35+
"openxml-3.0.0",
36+
"openxml-3.0.1"
37+
],
1038
"open_to_public_contributors": true,
1139
"customized_tasks": {
1240
"docset_prebuild": [
1341
"_dependentPackages/CommonPlugins/tools/JoinTOC.ps1"
1442
]
1543
},
44+
"xref_query_tags": [ "/dotnet" ],
1645
"type_mapping": {
1746
"Conceptual": "Content",
1847
"ManagedReference": "Content",

docs/about-the-open-xml-sdk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ The SDK supports the following common tasks/scenarios:
6262

6363
## Open XML SDK for Office
6464

65-
The Open XML SDK provides the namespaces and members to support the Microsoft Office 2013. The Open XML SDK can also read ISO/IEC 29500 Strict Format files. The Strict format is a subset of the Transitional format that does not include legacy features - this makes it theoretically easier for a new implementer to support since it has a smaller technical footprint.
65+
The Open XML SDK provides the namespaces and members to support the Microsoft Office. The Open XML SDK can also read ISO/IEC 29500 Strict Format files. The Strict format is a subset of the Transitional format that does not include legacy features - this makes it theoretically easier for a new implementer to support since it has a smaller technical footprint.
6666

6767
The SDK supports the following common tasks/scenarios:
6868

69-
- **Support of Office 2013 Preview file format** In addition to the Open XML SDK for Microsoft Office classes, Open XML SDK provides new classes that enable you to write and build applications to manipulate Open XML file extensions of the new Office 2013 features.
69+
- **Support of Office Preview file format** In addition to the Open XML SDK for Microsoft Office classes, Open XML SDK provides new classes that enable you to write and build applications to manipulate Open XML file extensions of the new Office features.
7070
- **Reads ISO Strict Document File** Open XML SDK can read ISO/IEC 29500 Strict Format files. When the Open XML SDK API opens a Strict Format file, each Open XML part in the file is loaded to an **OpenXmlPart** class of the Open XML SDK by mapping `https://purl.oclc.org/ooxml/` namespaces to the corresponding `https://schemas.openxmlformats.org/` namespaces.
7171
- **Fixes to the Open XML SDK for Microsoft Office** Open XML SDK includes fixes to known issues in the Open XML SDK for Microsoft Office. These include lost whitespaces in PowerPoint presentations and an issue with the Custom UI in Word documents where a specified argument was reported as being out of the range of valid values.
7272

docs/general/diagnosticids.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ ms.suite: office
55
ms.author: o365devx
66
author: o365devx
77
ms.topic: conceptual
8-
ms.date: 11/01/2017
8+
ms.date: 01/08/2025
99
ms.localizationpriority: high
1010
---
1111

1212
# Diagnostic IDs
1313

14-
Diagnostic IDs are used to identify APIs or patterns that can raise compiler warnings or errors. This can be done via [ObsoleteAttribute](/dotnet/api/system.obsoleteattribute.diagnosticid) or [ExperimentalAttribute](/dotnet/api/system.diagnostics.codeanalysis.experimentalattribute). These can be suppressed at the consumer level for each diagnostic id.
14+
Diagnostic IDs are used to identify APIs or patterns that can raise compiler warnings or errors. This can be done via <xref:System.ObsoleteAttribute.DiagnosticId*> or <xref:System.Diagnostics.CodeAnalysis.ExperimentalAttribute>. These can be suppressed at the consumer level for each diagnostic id.
1515

1616
## Experimental APIs
1717

1818
### OOXML0001
1919

2020
**Title**: IPackage related APIs are currently experimental
2121

22-
As of v3.0, a new abstraction layer was added in between `System.IO.Packaging` and `DocumentFormat.OpenXml.Packaging.OpenXmlPackage`. This is currently experimental, but can be used if needed. This will be stabalized in a future release, and may or may not require code changes.
22+
As of v3.0, a new abstraction layer was added in between `System.IO.Packaging` and `DocumentFormat.OpenXml.Packaging.OpenXmlPackage`. This is currently experimental, but can be used if needed. This will be stabilized in a future release, and may or may not require code changes.
2323

2424
## Suppress warnings
2525

docs/general/features.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,21 @@ private sealed class PrivateFeature
3838
{
3939
}
4040
```
41+
4142
> [!NOTE]
4243
> The feature collection on elements is readonly. This is due to memory issues if it is made writeable. If this is needed, please engage on https://github.com/dotnet/open-xml-sdk to let us know your scenario.
4344
4445
## Visualizing Registered Features
4546

46-
The in-box implementations of the `IFeatureCollection` provide a helpful debug view so you can see what features are available and what their properties/fields are:
47+
The in-box implementations of the <xref:DocumentFormat.OpenXml.Features.IFeatureCollection> provide a helpful debug view so you can see what features are available and what their properties/fields are:
4748

4849
![Features Debug View](../media/feature-debug-view.png)
4950

5051
## Available Features
5152

5253
The features that are currently available are described below and at what scope they are available:
5354

54-
### IDisposableFeature
55+
### <xref:DocumentFormat.OpenXml.Features.IDisposableFeature>
5556

5657
This feature allows for registering actions that need to run when a package or a part is destroyed or disposed:
5758

@@ -65,7 +66,7 @@ part.Features.Get<IDisposableFeature>().Register(() => /* Some action that is ca
6566

6667
Packages and parts will have their own implementations of this feature. Elements will retrieve the feature for their containing part if available.
6768

68-
### IPackageEventsFeature
69+
### <xref:DocumentFormat.OpenXml.Features.IPackageEventsFeature>
6970

7071
This feature allows getting event notifications of when a package is changed:
7172

@@ -79,7 +80,7 @@ var feature = package.Features.GetRequired<IPackageEventsFeature>();
7980
> [!NOTE]
8081
> There may be times when the package is changed but an event is not fired. Not all areas have been identified where it would make sense to raise an event. Please file an issue if you find one.
8182
82-
### IPartEventsFeature
83+
### <xref:DocumentFormat.OpenXml.Features.IPartEventsFeature>
8384

8485
This feature allows getting event notifications of when an event is being created. This is a feature that is added to the part or package:
8586

@@ -95,7 +96,7 @@ Generally, assume that there may be a singleton implementation for the events an
9596
> [!NOTE]
9697
> There may be times when the part is changed but an event is not fired. Not all areas have been identified where it would make sense to raise an event. Please file an issue if you find one.
9798
98-
### IPartRootEventsFeature
99+
### <xref:DocumentFormat.OpenXml.Features.IPartRootEventsFeature>
99100

100101
This feature allows getting event notifications of when a part root is being modified/loaded/created/etc. This is a feature that is added to the part level feature:
101102

@@ -111,11 +112,11 @@ Generally, assume that there may be a singleton implementation for the events an
111112
> [!NOTE]
112113
> There may be times when the part root is changed but an event is not fired. Not all areas have been identified where it would make sense to raise an event. Please file an issue if you find one.
113114
114-
### IRandomNumberGeneratorFeature
115+
### <xref:DocumentFormat.OpenXml.Features.IRandomNumberGeneratorFeature>
115116

116117
This feature allows for a shared service to generate random numbers and fill an array.
117118

118-
### IParagraphIdGeneratorFeature
119+
### <xref:DocumentFormat.OpenXml.Features.IParagraphIdGeneratorFeature>
119120

120121
This feature allows for population and tracking of elements that contain paragraph ids. By default, this will ensure uniqueness of values and ensure that values that do exist are valid per the constraints of the standard. To use this feature:
121122

@@ -159,21 +160,3 @@ body2.AddChild(p2);
159160
Assert.NotEqual(p1.ParagraphId, p2.ParagraphId);
160161
Assert.Equal(2, shared.Count);
161162
```
162-
163-
### IPartRootXElementFeature
164-
165-
This feature allows operating on an `OpenXmlPart` by using XLinq features and directly manipulating `XElement` nodes.
166-
167-
```csharp
168-
OpenXmlPart part = GetSomePart();
169-
170-
var node = new(W.document, new XAttribute(XNamespace.Xmlns + "w", W.w),
171-
new XElement(W.body,
172-
new XElement(W.p,
173-
new XElement(W.r,
174-
new XElement(W.t, "Hello World!")))));
175-
176-
part.SetXElement(node);
177-
```
178-
179-
This `XElement` is cached but will be kept in sync with the underlying part if it were to change.

docs/general/how-to-add-a-new-document-part-that-receives-a-relationship-id-to-a-package.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ ms.suite: office
1111
ms.author: o365devx
1212
author: o365devx
1313
ms.topic: conceptual
14-
ms.date: 11/01/2017
14+
ms.date: 01/08/2025
1515
ms.localizationpriority: medium
1616
---
1717

1818
# Add a new document part that receives a relationship ID to a package
1919

2020
This topic shows how to use the classes in the Open XML SDK for
21-
Office to add a document part (file) that receives a relationship **Id** parameter for a word
21+
Office to add a document part (file) that receives a relationship `Id` parameter for a word
2222
processing document.
2323

2424

@@ -32,39 +32,51 @@ processing document.
3232
[!include[Structure](../includes/word/structure.md)]
3333

3434
-----------------------------------------------------------------------------
35-
## Sample Code
36-
The following code, adds a new document part that contains custom XML
37-
from an external file and then populates the document part. You can call
38-
the method **AddNewPart** by using a call like
39-
the following code example.
40-
41-
### [C#](#tab/cs-0)
42-
```csharp
43-
string document = @"C:\Users\Public\Documents\MyPkg1.docx";
44-
AddNewPart(document);
45-
```
46-
47-
### [Visual Basic](#tab/vb-0)
48-
```vb
49-
Dim document As String = "C:\Users\Public\Documents\MyPkg1.docx"
50-
AddNewPart(document)
51-
```
35+
36+
## How the Sample Code Works
37+
38+
The sample code, in this how-to, starts by passing in a parameter that represents the path to the Word document. It then creates
39+
a new WordprocessingDocument object within a using statement.
40+
41+
### [C#](#tab/cs-1)
42+
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs#snippet1)]
43+
44+
### [Visual Basic](#tab/vb-1)
45+
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb#snippet1)]
46+
***
47+
48+
It then adds the MainDocumentPart part in the new word processing document, with the relationship ID, rId1. It also adds the `CustomFilePropertiesPart` part and a `CoreFilePropertiesPart` in the new word processing document.
49+
50+
### [C#](#tab/cs-2)
51+
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs#snippet2)]
52+
53+
### [Visual Basic](#tab/vb-2)
54+
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb#snippet2)]
5255
***
5356

57+
The code then adds the `DigitalSignatureOriginPart` part, the `ExtendedFilePropertiesPart` part, and the `ThumbnailPart` part in the new word processing document with realtionship IDs rId4, rId5, and rId6.
5458

55-
The following is the complete code example in both C\# and Visual Basic.
59+
> [!NOTE]
60+
> The <xref:DocumentFormat.OpenXml.Packaging.WordprocessingDocument.AddNewPart*> method creates a relationship from the current document part to the new document part. This method returns the new document part. Also, you can use the <a href="xref:DocumentFormat.OpenXml.Packaging.DataPart.FeedData*?displayProperty=nameWithType"/> method to fill the document part.
61+
62+
## Sample Code
63+
64+
The following code, adds a new document part that contains custom XML
65+
from an external file and then populates the document part. Below is the
66+
complete code example in both C\# and Visual Basic.
5667

5768
### [C#](#tab/cs)
58-
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs)]
69+
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs#snippet0)]
5970

6071
### [Visual Basic](#tab/vb)
61-
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb)]
72+
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb#snippet0)]
73+
***
6274

6375
-----------------------------------------------------------------------------
64-
## See also
76+
## See also
6577

6678

6779
- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
68-
80+
6981

7082

docs/general/how-to-add-a-new-document-part-to-a-package.md

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.suite: office
99
ms.author: o365devx
1010
author: o365devx
1111
ms.topic: conceptual
12-
ms.date: 03/22/2022
12+
ms.date: 01/08/2025
1313
ms.localizationpriority: medium
1414
---
1515

@@ -21,79 +21,45 @@ This topic shows how to use the classes in the Open XML SDK for Office to add a
2121

2222
## Get a WordprocessingDocument object
2323

24-
The code starts with opening a package file by passing a file name to one of the overloaded **[Open()](https://msdn.microsoft.com/library/office/documentformat.openxml.packaging.wordprocessingdocument.open.aspx)** methods of the **[DocumentFormat.OpenXml.Packaging.WordprocessingDocument](https://msdn.microsoft.com/library/office/documentformat.openxml.packaging.wordprocessingdocument.aspx)** that takes a string and a Boolean value that specifies whether the file should be opened for editing or for read-only access. In this case, the Boolean value is **true** specifying that the file should be opened in read/write mode.
25-
26-
### [C#](#tab/cs-0)
27-
```csharp
28-
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
29-
{
30-
// Insert other code here.
31-
}
32-
```
33-
34-
### [Visual Basic](#tab/vb-0)
35-
```vb
36-
Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
37-
' Insert other code here.
38-
End Using
39-
```
24+
The code starts with opening a package file by passing a file name to one of the overloaded <xref:DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open%2A> methods of the <xref:DocumentFormat.OpenXml.Packaging.WordprocessingDocument> that takes a string and a Boolean value that specifies whether the file should be opened for editing or for read-only access. In this case, the Boolean value is `true` specifying that the file should be opened in read/write mode.
25+
26+
### [C#](#tab/cs-1)
27+
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet1)]
28+
29+
### [Visual Basic](#tab/vb-1)
30+
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet1)]
4031
***
4132

4233

43-
The **using** statement provides a recommended alternative to the typical .Create, .Save, .Close sequence. It ensures that the **Dispose** method (internal method used by the Open XML SDK to clean up resources) is automatically called when the closing brace is reached. The block that follows the **using** statement establishes a scope for the object that is created or named in the **using** statement, in this case **wordDoc**. Because the **WordprocessingDocument** class in the Open XML SDK
44-
automatically saves and closes the object as part of its **System.IDisposable** implementation, and because the **Dispose** method is automatically called when you exit the block; you do not have to explicitly call **Save** and **Close**, as long as you use **using**.
34+
[!include[Using Statement](../includes/word/using-statement.md)]
4535

4636
[!include[Structure](../includes/word/structure.md)]
4737

4838
## How the sample code works
4939

50-
After opening the document for editing, in the **using** statement, as a **WordprocessingDocument** object, the code creates a reference to the **MainDocumentPart** part and adds a new custom XML part. It then reads the contents of the external
51-
file that contains the custom XML and writes it to the **CustomXmlPart** part.
40+
After opening the document for editing, in the `using` statement, as a <xref:DocumentFormat.OpenXml.Packaging.WordprocessingDocument> object, the code creates a reference to the `MainDocumentPart` part and adds a new custom XML part. It then reads the contents of the external
41+
file that contains the custom XML and writes it to the `CustomXmlPart` part.
5242

5343
> [!NOTE]
5444
> To use the new document part in the document, add a link to the document part in the relationship part for the new part.
5545
56-
### [C#](#tab/cs-1)
57-
```csharp
58-
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
59-
CustomXmlPart myXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
60-
61-
using (FileStream stream = new FileStream(fileName, FileMode.Open))
62-
{
63-
myXmlPart.FeedData(stream);
64-
}
65-
```
66-
67-
### [Visual Basic](#tab/vb-1)
68-
```vb
69-
Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart
70-
71-
Dim myXmlPart As CustomXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml)
46+
### [C#](#tab/cs-2)
47+
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet2)]
7248

73-
Using stream As New FileStream(fileName, FileMode.Open)
74-
myXmlPart.FeedData(stream)
75-
End Using
76-
```
49+
### [Visual Basic](#tab/vb-2)
50+
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet2)]
7751
***
7852

7953

8054
## Sample code
8155

82-
The following code adds a new document part that contains custom XML from an external file and then populates the part. To call the AddCustomXmlPart method in your program, use the following example that modifies the file "myPkg2.docx" by adding a new document part to it.
56+
The following code adds a new document part that contains custom XML from an external file and then populates the part. To call the `AddCustomXmlPart` method in your program, use the following example that modifies a file by adding a new document part to it.
8357

84-
### [C#](#tab/cs-2)
85-
```csharp
86-
string document = @"C:\Users\Public\Documents\myPkg2.docx";
87-
string fileName = @"C:\Users\Public\Documents\myXML.xml";
88-
AddNewPart(document, fileName);
89-
```
58+
### [C#](#tab/cs-3)
59+
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet3)]
9060

91-
### [Visual Basic](#tab/vb-2)
92-
```vb
93-
Dim document As String = "C:\Users\Public\Documents\myPkg2.docx"
94-
Dim fileName As String = "C:\Users\Public\Documents\myXML.xml"
95-
AddNewPart(document, fileName)
96-
```
61+
### [Visual Basic](#tab/vb-3)
62+
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet3)]
9763
***
9864

9965

@@ -103,10 +69,11 @@ The following code adds a new document part that contains custom XML from an ext
10369
Following is the complete code example in both C\# and Visual Basic.
10470

10571
### [C#](#tab/cs)
106-
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs)]
72+
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet0)]
10773

10874
### [Visual Basic](#tab/vb)
109-
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb)]
75+
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet0)]
76+
***
11077

11178
## See also
11279

0 commit comments

Comments
 (0)