Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
455e776
closes #231
mikeebowen Feb 5, 2024
00a87e6
closes #230
mikeebowen Feb 5, 2024
2561802
Merge remote-tracking branch 'upstream/main' into extract-snippets-2
mikeebowen Feb 6, 2024
a1b162c
closes #219
mikeebowen Feb 6, 2024
3368d85
closes #218
mikeebowen Feb 7, 2024
5f30e91
closes #310
mikeebowen Feb 8, 2024
37c5abd
closes #217
mikeebowen Feb 8, 2024
428e4e4
closes #216
mikeebowen Feb 8, 2024
b2fc6f1
closes #215
mikeebowen Feb 9, 2024
367e934
closes #214
mikeebowen Feb 9, 2024
a37abb3
closes #213
mikeebowen Feb 13, 2024
a887549
closes #212
mikeebowen May 13, 2024
bb1f634
closes #211
mikeebowen May 13, 2024
1d5930b
closes #210
mikeebowen May 13, 2024
59fb086
closes #209
mikeebowen May 13, 2024
c1de6cb
closes #208
mikeebowen May 14, 2024
0cf5f64
closes #207
mikeebowen Sep 10, 2024
5b493ed
closes #206
mikeebowen Sep 12, 2024
4b78beb
closes #205
mikeebowen Sep 12, 2024
5764348
closes #314
mikeebowen Sep 17, 2024
d8f386a
closes #204
mikeebowen Sep 18, 2024
8be3137
closes #203
mikeebowen Sep 19, 2024
25963a6
closes #202
mikeebowen Sep 19, 2024
9dc2934
closes #201
mikeebowen Sep 20, 2024
a9d0927
closes #200
mikeebowen Nov 21, 2024
a97d9e4
update SDK version
mikeebowen Nov 21, 2024
c2bb069
fix xref errors
mikeebowen Nov 21, 2024
f51f3f7
add missing heading
mikeebowen Nov 21, 2024
2359790
closes #199
mikeebowen Nov 26, 2024
7d6e92b
closes #198
mikeebowen Nov 26, 2024
1b53a54
fix xref errors
mikeebowen Nov 26, 2024
56ffe22
closes #197
mikeebowen Nov 26, 2024
4125a27
closes #196
mikeebowen Nov 26, 2024
545b059
fix tab names
mikeebowen Nov 27, 2024
2236858
fix tab names
mikeebowen Nov 27, 2024
4346e18
closes #194
mikeebowen Nov 27, 2024
36b0ede
closes #193
mikeebowen Nov 27, 2024
42e00d2
update using-statement.md
mikeebowen Dec 3, 2024
b7fa8ef
update using-statement.md file location
mikeebowen Dec 3, 2024
0cd3853
re-add using-statement.md to fix errors. Will be removed in a later PR
mikeebowen Dec 3, 2024
80c463d
revert changes to presentation folder
mikeebowen Dec 3, 2024
6003c8b
closes #192
mikeebowen Dec 2, 2024
73f318b
closes #191
mikeebowen Dec 3, 2024
3ca422c
fixes #190
mikeebowen Dec 3, 2024
f8662ec
move using paragraph into separate file
mikeebowen Dec 3, 2024
1624302
closes #189
mikeebowen Dec 4, 2024
bd191aa
closes #188
mikeebowen Dec 4, 2024
ea176fd
closes #187
mikeebowen Dec 6, 2024
795c6c7
closes #186
mikeebowen Dec 6, 2024
3c0aa1b
- closes #185
mikeebowen Dec 31, 2024
28c1ce3
closes #184
mikeebowen Dec 31, 2024
f93643f
closes #183
mikeebowen Dec 31, 2024
000770d
closes #182
mikeebowen Jan 2, 2025
8aee71b
closes #180
mikeebowen Jan 3, 2025
1ab1dfb
fix merge conflict
mikeebowen Jan 3, 2025
650bba1
closes #326
mikeebowen Jan 3, 2025
2304d56
closes #325
mikeebowen Jan 4, 2025
7d53a79
closes #324
mikeebowen Jan 4, 2025
36a8656
update using statement snippet
mikeebowen Jan 7, 2025
b53d6b9
move links to xrefs
mikeebowen Jan 8, 2025
9240ced
closes #315
mikeebowen Jan 8, 2025
f0efe05
closes #322
mikeebowen Jan 8, 2025
f6392cb
closes #321
mikeebowen Jan 8, 2025
b55eaec
closes #320
mikeebowen Jan 8, 2025
2bbe4e3
closes #318
mikeebowen Jan 8, 2025
9739867
closes #319
mikeebowen Jan 9, 2025
73d4234
closes #317
mikeebowen Jan 9, 2025
145bcc1
closes #316
mikeebowen Jan 9, 2025
28f3fd9
clean up hot-to-add-custom-ui-to-a-spreadsheet
mikeebowen Jan 9, 2025
4dc4cd8
use consistent styling in structure snippets
mikeebowen Jan 9, 2025
d8a73c0
clean up how-to-calculate-the-sum-of-a-range-of-cells-in-a-spreadshee…
mikeebowen Jan 9, 2025
18aa8da
clean up how-to-create-a-spreadsheet-document-by-providing-a-file-name
mikeebowen Jan 9, 2025
c3767d9
clean up how-to-delete-text-from-a-cell-in-a-spreadsheet.md
mikeebowen Jan 9, 2025
680331d
clean up docs\spreadsheet\how-to-get-a-column-heading-in-a-spreadshee…
mikeebowen Jan 9, 2025
1e7f8e1
clean up docs\spreadsheet\how-to-get-worksheet-information-from-a-pac…
mikeebowen Jan 9, 2025
ab513bd
clean up docs\spreadsheet\how-to-insert-a-new-worksheet-into-a-spread…
mikeebowen Jan 10, 2025
048995d
clean up docs\spreadsheet\how-to-insert-text-into-a-cell-in-a-spreads…
mikeebowen Jan 10, 2025
f687a69
clean up docs\spreadsheet\how-to-insert-a-new-worksheet-into-a-spread…
mikeebowen Jan 10, 2025
9fca4ab
clean up docs\spreadsheet\how-to-open-a-spreadsheet-document-for-read…
mikeebowen Jan 10, 2025
c56fc6b
clean up docs\spreadsheet\how-to-open-a-spreadsheet-document-from-a-s…
mikeebowen Jan 10, 2025
8310965
clean up docs\spreadsheet\how-to-parse-and-read-a-large-spreadsheet.md
mikeebowen Jan 10, 2025
5f19816
clean up docs\spreadsheet\how-to-retrieve-a-dictionary-of-all-named-r…
mikeebowen Jan 10, 2025
014cdec
clean up docs\spreadsheet\how-to-retrieve-a-list-of-the-hidden-rows-o…
mikeebowen Jan 10, 2025
1294bfe
clean up docs\spreadsheet\how-to-retrieve-a-list-of-the-hidden-worksh…
mikeebowen Jan 10, 2025
689bfba
clean up docs\spreadsheet\how-to-retrieve-a-list-of-the-worksheets-in…
mikeebowen Jan 10, 2025
93c4e5c
clean up docs\spreadsheet\how-to-retrieve-the-values-of-cells-in-a-sp…
mikeebowen Jan 10, 2025
b9b7789
remove whitespace
mikeebowen Jan 10, 2025
3b69597
clean up docs\spreadsheet\how-to-insert-a-chart-into-a-spreadsheet.md
mikeebowen Jan 14, 2025
169f3d8
fix merge conflict
mikeebowen Jan 14, 2025
3aa05a4
clean up docs\spreadsheet\structure-of-a-spreadsheetml-document.md
mikeebowen Jan 14, 2025
d0bc85b
clean up docs\spreadsheet\working-with-conditional-formatting.md
mikeebowen Jan 14, 2025
1557411
clean up docs\spreadsheet\working-with-formulas.md
mikeebowen Jan 14, 2025
4ffbce6
clean up docs\spreadsheet\working-with-pivottables.md
mikeebowen Jan 14, 2025
397732d
clean up docs\spreadsheet\working-with-sheets.md
mikeebowen Jan 14, 2025
c69d518
clean up docs\spreadsheet\working-with-tables.md
mikeebowen Jan 14, 2025
3ba0209
clean up docs\spreadsheet\working-with-the-calculation-chain.md
mikeebowen Jan 14, 2025
25adb02
clean up docs\spreadsheet\working-with-the-shared-string-table.md
mikeebowen Jan 14, 2025
91d8ea3
remove calls to Save
mikeebowen Jan 17, 2025
af594c1
fix docfx errors
mikeebowen Jan 21, 2025
de849da
fix xref links
mikeebowen Jan 21, 2025
2d92911
fix usage before assignment issue
mikeebowen Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/general/diagnosticids.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ ms.suite: office
ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 11/01/2017
ms.date: 01/08/2025
ms.localizationpriority: high
---

# Diagnostic IDs

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.
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.

## Experimental APIs

### OOXML0001

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

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.
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.

## Suppress warnings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ ms.suite: office
ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 11/01/2017
ms.date: 01/08/2025
ms.localizationpriority: medium
---

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

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


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

-----------------------------------------------------------------------------
## Sample Code
The following code, adds a new document part that contains custom XML
from an external file and then populates the document part. You can call
the method **AddNewPart** by using a call like
the following code example.

### [C#](#tab/cs-0)
```csharp
string document = @"C:\Users\Public\Documents\MyPkg1.docx";
AddNewPart(document);
```

### [Visual Basic](#tab/vb-0)
```vb
Dim document As String = "C:\Users\Public\Documents\MyPkg1.docx"
AddNewPart(document)
```

## How the Sample Code Works

The sample code, in this how-to, starts by passing in a parameter that represents the path to the Word document. It then creates
a new WordprocessingDocument object within a using statement.

### [C#](#tab/cs-1)
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs#snippet1)]

### [Visual Basic](#tab/vb-1)
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb#snippet1)]
***

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.

### [C#](#tab/cs-2)
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs#snippet2)]

### [Visual Basic](#tab/vb-2)
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb#snippet2)]
***

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.

The following is the complete code example in both C\# and Visual Basic.
> [!NOTE]
> 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.

## Sample Code

The following code, adds a new document part that contains custom XML
from an external file and then populates the document part. Below is the
complete code example in both C\# and Visual Basic.

### [C#](#tab/cs)
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs)]
[!code-csharp[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/cs/Program.cs#snippet0)]

### [Visual Basic](#tab/vb)
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb)]
[!code-vb[](../../samples/word/add_a_new_part_that_receives_a_relationship_id_to_a_package/vb/Program.vb#snippet0)]
***

-----------------------------------------------------------------------------
## See also
## See also


- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)



75 changes: 21 additions & 54 deletions docs/general/how-to-add-a-new-document-part-to-a-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ms.suite: office
ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 03/22/2022
ms.date: 01/08/2025
ms.localizationpriority: medium
---

Expand All @@ -23,77 +23,43 @@ This topic shows how to use the classes in the Open XML SDK for Office to add a

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.

### [C#](#tab/cs-0)
```csharp
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
{
// Insert other code here.
}
```

### [Visual Basic](#tab/vb-0)
```vb
Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
' Insert other code here.
End Using
```
### [C#](#tab/cs-1)
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet1)]

### [Visual Basic](#tab/vb-1)
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet1)]
***


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 <xref:DocumentFormat.OpenXml.Packaging.WordprocessingDocument> class in the Open XML SDK
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**.
[!include[Using Statement](../includes/word/using-statement.md)]

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

## How the sample code works

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
file that contains the custom XML and writes it to the **CustomXmlPart** part.
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
file that contains the custom XML and writes it to the `CustomXmlPart` part.

> [!NOTE]
> To use the new document part in the document, add a link to the document part in the relationship part for the new part.

### [C#](#tab/cs-1)
```csharp
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
CustomXmlPart myXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);

using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
myXmlPart.FeedData(stream);
}
```

### [Visual Basic](#tab/vb-1)
```vb
Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart

Dim myXmlPart As CustomXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml)
### [C#](#tab/cs-2)
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet2)]

Using stream As New FileStream(fileName, FileMode.Open)
myXmlPart.FeedData(stream)
End Using
```
### [Visual Basic](#tab/vb-2)
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet2)]
***


## Sample code

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.
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.

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

### [Visual Basic](#tab/vb-2)
```vb
Dim document As String = "C:\Users\Public\Documents\myPkg2.docx"
Dim fileName As String = "C:\Users\Public\Documents\myXML.xml"
AddNewPart(document, fileName)
```
### [Visual Basic](#tab/vb-3)
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet3)]
***


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

### [C#](#tab/cs)
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs)]
[!code-csharp[](../../samples/word/add_a_new_part_to_a_package/cs/Program.cs#snippet0)]

### [Visual Basic](#tab/vb)
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb)]
[!code-vb[](../../samples/word/add_a_new_part_to_a_package/vb/Program.vb#snippet0)]
***

## See also

Expand Down
Loading
Loading