diff --git a/docs/how-to-add-custom-ui-to-a-spreadsheet-document.md b/docs/how-to-add-custom-ui-to-a-spreadsheet-document.md
index de4945af..26a788d2 100644
--- a/docs/how-to-add-custom-ui-to-a-spreadsheet-document.md
+++ b/docs/how-to-add-custom-ui-to-a-spreadsheet-document.md
@@ -169,86 +169,11 @@ Given a reference to the ribbon extensibility part, the following code finishes
The following is the complete **AddCustomUI** code sample in C\# and Visual Basic.
-```csharp
- static public void AddCustomUI(string fileName, string customUIContent)
- {
- // Add a custom UI part to the document.
- // Use this sample XML to test:
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
-
- // In the sample XLSM file, create a module and create a procedure
- // named SampleMacro, using this
- // signature: Public Sub SampleMacro(control As IRibbonControl)
- // Add some code, and then save and close the XLSM file. Run this
- // example to add a button to the Add-Ins tab that calls the macro,
- // given the XML content above in the AddCustomUI.xml file.
-
- using (SpreadsheetDocument document =
- SpreadsheetDocument.Open(fileName, true))
- {
- // You can have only a single ribbon extensibility part.
- // If the part doesn't exist, create it.
- var part = document.RibbonExtensibilityPart;
- if (part == null)
- {
- part = document.AddRibbonExtensibilityPart();
- }
- part.CustomUI = new CustomUI(customUIContent);
- part.CustomUI.Save();
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/add_custom_ui/cs/Program.cs)]
-```vb
- Public Sub XLAddCustomUI(ByVal fileName As String,
- ByVal customUIContent As String)
- ' Add a custom UI part to the document.
- ' Use this sample XML to test:
-
- '
- '
- '
- '
- '
- '
- '
- '
- '
- '
- '
-
- ' In the sample XLSM file, create a module and create a procedure
- ' named SampleMacro, using this signature:
- ' Public Sub SampleMacro(control As IRibbonControl)
- ' Add some code, and then save and close the XLSM file. Run this
- ' example to add a button to the Add-Ins tab that calls the macro,
- ' given the XML content above in the AddCustomUI.xml file.
-
- Using document As SpreadsheetDocument =
- SpreadsheetDocument.Open(fileName, True)
- ' You can have only a single ribbon extensibility part.
- ' If the part doesn't exist, add it.
- Dim part = document.RibbonExtensibilityPart
- If part Is Nothing Then
- part = document.AddRibbonExtensibilityPart
- End If
- part.CustomUI = New CustomUI(customUIContent)
- part.CustomUI.Save()
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/add_custom_ui/vb/Program.vb)]
## See also
diff --git a/docs/how-to-add-tables-to-word-processing-documents.md b/docs/how-to-add-tables-to-word-processing-documents.md
index 18843079..94153914 100644
--- a/docs/how-to-add-tables-to-word-processing-documents.md
+++ b/docs/how-to-add-tables-to-word-processing-documents.md
@@ -257,127 +257,11 @@ The following code concludes by appending the table to the body of the document,
The following is the complete **AddTable** code sample in C\# and Visual Basic.
-```csharp
- // Take the data from a two-dimensional array and build a table at the
- // end of the supplied document.
- public static void AddTable(string fileName, string[,] data)
- {
- using (var document = WordprocessingDocument.Open(fileName, true))
- {
-
- var doc = document.MainDocumentPart.Document;
-
- Table table = new Table();
-
- TableProperties props = new TableProperties(
- new TableBorders(
- new TopBorder
- {
- Val = new EnumValue(BorderValues.Single),
- Size = 12
- },
- new BottomBorder
- {
- Val = new EnumValue(BorderValues.Single),
- Size = 12
- },
- new LeftBorder
- {
- Val = new EnumValue(BorderValues.Single),
- Size = 12
- },
- new RightBorder
- {
- Val = new EnumValue(BorderValues.Single),
- Size = 12
- },
- new InsideHorizontalBorder
- {
- Val = new EnumValue(BorderValues.Single),
- Size = 12
- },
- new InsideVerticalBorder
- {
- Val = new EnumValue(BorderValues.Single),
- Size = 12
- }));
-
- table.AppendChild(props);
-
- for (var i = 0; i <= data.GetUpperBound(0); i++)
- {
- var tr = new TableRow();
- for (var j = 0; j <= data.GetUpperBound(1); j++)
- {
- var tc = new TableCell();
- tc.Append(new Paragraph(new Run(new Text(data[i, j]))));
-
- // Assume you want columns that are automatically sized.
- tc.Append(new TableCellProperties(
- new TableCellWidth { Type = TableWidthUnitValues.Auto }));
-
- tr.Append(tc);
- }
- table.Append(tr);
- }
- doc.Body.Append(table);
- doc.Save();
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/add_tables/cs/Program.cs)]
-```vb
- ' Take the data from a two-dimensional array and build a table at the
- ' end of the supplied document.
- Public Sub AddTable(ByVal fileName As String,
- ByVal data(,) As String)
- Using document = WordprocessingDocument.Open(fileName, True)
-
- Dim doc = document.MainDocumentPart.Document
-
- Dim table As New Table()
-
- Dim props As TableProperties = _
- New TableProperties(New TableBorders( _
- New TopBorder With {
- .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
- .Size = 12},
- New BottomBorder With {
- .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
- .Size = 12},
- New LeftBorder With {
- .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
- .Size = 12},
- New RightBorder With {
- .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
- .Size = 12}, _
- New InsideHorizontalBorder With {
- .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
- .Size = 12}, _
- New InsideVerticalBorder With {
- .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
- .Size = 12}))
- table.AppendChild(Of TableProperties)(props)
-
- For i = 0 To UBound(data, 1)
- Dim tr As New TableRow
- For j = 0 To UBound(data, 2)
- Dim tc As New TableCell
- tc.Append(New Paragraph(New Run(New Text(data(i, j)))))
-
- ' Assume you want columns that are automatically sized.
- tc.Append(New TableCellProperties(
- New TableCellWidth With {.Type = TableWidthUnitValues.Auto}))
-
- tr.Append(tc)
- Next
- table.Append(tr)
- Next
- doc.Body.Append(table)
- doc.Save()
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/add_tables/vb/Program.vb)]
## See also
diff --git a/docs/how-to-change-text-in-a-table-in-a-word-processing-document.md b/docs/how-to-change-text-in-a-table-in-a-word-processing-document.md
index 46e99dca..5d82026a 100644
--- a/docs/how-to-change-text-in-a-table-in-a-word-processing-document.md
+++ b/docs/how-to-change-text-in-a-table-in-a-word-processing-document.md
@@ -19,19 +19,7 @@ ms.localizationpriority: high
This topic shows how to use the Open XML SDK for Office to programmatically change text in a table in an existing word processing document.
-The following assembly directives are required to compile the code in this topic.
-```csharp
- using System.Linq;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Wordprocessing;
-```
-
-```vb
- Imports System.Linq
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Wordprocessing
-```
## Open the Existing Document
@@ -197,65 +185,11 @@ example."
Following is the complete code example.
-```csharp
- // Change the text in a table in a word processing document.
- public static void ChangeTextInCell(string filepath, string txt)
- {
- // Use the file name and path passed in as an argument to
- // open an existing document.
- using (WordprocessingDocument doc =
- WordprocessingDocument.Open(filepath, true))
- {
- // Find the first table in the document.
- Table table =
- doc.MainDocumentPart.Document.Body.Elements
().First();
-
- // Find the second row in the table.
- TableRow row = table.Elements().ElementAt(1);
-
- // Find the third cell in the row.
- TableCell cell = row.Elements().ElementAt(2);
-
- // Find the first paragraph in the table cell.
- Paragraph p = cell.Elements().First();
-
- // Find the first run in the paragraph.
- Run r = p.Elements().First();
-
- // Set the text for the run.
- Text t = r.Elements().First();
- t.Text = txt;
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/change_text_a_table/cs/Program.cs)]
-```vb
- ' Change the text in a table in a word processing document.
- Public Sub ChangeTextInCell(ByVal filepath As String, ByVal txt As String)
- ' Use the file name and path passed in as an argument to
- ' Open an existing document.
- Using doc As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
- ' Find the first table in the document.
- Dim table As Table = doc.MainDocumentPart.Document.Body.Elements(Of Table)().First()
-
- ' Find the second row in the table.
- Dim row As TableRow = table.Elements(Of TableRow)().ElementAt(1)
-
- ' Find the third cell in the row.
- Dim cell As TableCell = row.Elements(Of TableCell)().ElementAt(2)
-
- ' Find the first paragraph in the table cell.
- Dim p As Paragraph = cell.Elements(Of Paragraph)().First()
-
- ' Find the first run in the paragraph.
- Dim r As Run = p.Elements(Of Run)().First()
-
- ' Set the text for the run.
- Dim t As Text = r.Elements(Of Text)().First()
- t.Text = txt
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/change_text_a_table/vb/Program.vb)]
## See also
diff --git a/docs/how-to-change-the-fill-color-of-a-shape-in-a-presentation.md b/docs/how-to-change-the-fill-color-of-a-shape-in-a-presentation.md
index c13fe102..ba90e7b8 100644
--- a/docs/how-to-change-the-fill-color-of-a-shape-in-a-presentation.md
+++ b/docs/how-to-change-the-fill-color-of-a-shape-in-a-presentation.md
@@ -21,22 +21,7 @@ This topic shows how to use the classes in the Open XML SDK to
change the fill color of a shape on the first slide in a presentation
programmatically.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using DocumentFormat.OpenXml.Presentation;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml;
- using Drawing = DocumentFormat.OpenXml.Drawing;
-```
-
-```vb
- Imports DocumentFormat.OpenXml.Presentation
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml
- Imports Drawing = DocumentFormat.OpenXml.Drawing
-```
## Getting a Presentation Object
@@ -261,87 +246,11 @@ fill color in the file "Myppt3.pptx" by using the following call.
After running the program, examine the file "Myppt3.pptx" to see the
change in the fill color.
-```csharp
- // Change the fill color of a shape.
- // The test file must have a filled shape as the first shape on the first slide.
- public static void SetPPTShapeColor(string docName)
- {
- using (PresentationDocument ppt = PresentationDocument.Open(docName, true))
- {
- // Get the relationship ID of the first slide.
- PresentationPart part = ppt.PresentationPart;
- OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;
- string relId = (slideIds[0] as SlideId).RelationshipId;
-
- // Get the slide part from the relationship ID.
- SlidePart slide = (SlidePart)part.GetPartById(relId);
-
- if (slide != null)
- {
- // Get the shape tree that contains the shape to change.
- ShapeTree tree = slide.Slide.CommonSlideData.ShapeTree;
-
- // Get the first shape in the shape tree.
- Shape shape = tree.GetFirstChild();
-
- if (shape != null)
- {
- // Get the style of the shape.
- ShapeStyle style = shape.ShapeStyle;
-
- // Get the fill reference.
- Drawing.FillReference fillRef = style.FillReference;
-
- // Set the fill color to SchemeColor Accent 6;
- fillRef.SchemeColor = new Drawing.SchemeColor();
- fillRef.SchemeColor.Val = Drawing.SchemeColorValues.Accent6;
-
- // Save the modified slide.
- slide.Slide.Save();
- }
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs)]
-```vb
- ' Change the fill color of a shape.
- ' The test file must have a filled shape as the first shape on the first slide.
- Public Sub SetPPTShapeColor(ByVal docName As String)
- Using ppt As PresentationDocument = PresentationDocument.Open(docName, True)
- ' Get the relationship ID of the first slide.
- Dim part As PresentationPart = ppt.PresentationPart
- Dim slideIds As OpenXmlElementList = part.Presentation.SlideIdList.ChildElements
- Dim relId As String = TryCast(slideIds(0), SlideId).RelationshipId
-
- ' Get the slide part from the relationship ID.
- Dim slide As SlidePart = DirectCast(part.GetPartById(relId), SlidePart)
-
- If slide IsNot Nothing Then
- ' Get the shape tree that contains the shape to change.
- Dim tree As ShapeTree = slide.Slide.CommonSlideData.ShapeTree
-
- ' Get the first shape in the shape tree.
- Dim shape As Shape = tree.GetFirstChild(Of Shape)()
-
- If shape IsNot Nothing Then
- ' Get the style of the shape.
- Dim style As ShapeStyle = shape.ShapeStyle
-
- ' Get the fill reference.
- Dim fillRef As Drawing.FillReference = style.FillReference
-
- ' Set the fill color to SchemeColor Accent 6;
- fillRef.SchemeColor = New Drawing.SchemeColor()
- fillRef.SchemeColor.Val = Drawing.SchemeColorValues.Accent6
-
- ' Save the modified slide.
- slide.Slide.Save()
- End If
- End If
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb)]
## See also
diff --git a/docs/how-to-change-the-print-orientation-of-a-word-processing-document.md b/docs/how-to-change-the-print-orientation-of-a-word-processing-document.md
index f5b505b8..d49000ad 100644
--- a/docs/how-to-change-the-print-orientation-of-a-word-processing-document.md
+++ b/docs/how-to-change-the-print-orientation-of-a-word-processing-document.md
@@ -334,195 +334,11 @@ has changed. If the document has changed, the code saves it.
The following is the complete **SetPrintOrientation** code sample in C\# and Visual
Basic.
-```csharp
- using System.Linq;
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Wordprocessing;
-
- namespace ChangePrintOrientation
- {
- class Program
- {
- static void Main(string[] args)
- {
- SetPrintOrientation(@"C:\Users\Public\Documents\ChangePrintOrientation.docx",
- PageOrientationValues.Landscape);
- }
-
- // Given a document name, set the print orientation for
- // all the sections of the document.
- public static void SetPrintOrientation(
- string fileName, PageOrientationValues newOrientation)
- {
- using (var document =
- WordprocessingDocument.Open(fileName, true))
- {
- bool documentChanged = false;
-
- var docPart = document.MainDocumentPart;
- var sections = docPart.Document.Descendants();
-
- foreach (SectionProperties sectPr in sections)
- {
- bool pageOrientationChanged = false;
-
- PageSize pgSz = sectPr.Descendants().FirstOrDefault();
- if (pgSz != null)
- {
- // No Orient property? Create it now. Otherwise, just
- // set its value. Assume that the default orientation
- // is Portrait.
- if (pgSz.Orient == null)
- {
- // Need to create the attribute. You do not need to
- // create the Orient property if the property does not
- // already exist, and you are setting it to Portrait.
- // That is the default value.
- if (newOrientation != PageOrientationValues.Portrait)
- {
- pageOrientationChanged = true;
- documentChanged = true;
- pgSz.Orient =
- new EnumValue(newOrientation);
- }
- }
- else
- {
- // The Orient property exists, but its value
- // is different than the new value.
- if (pgSz.Orient.Value != newOrientation)
- {
- pgSz.Orient.Value = newOrientation;
- pageOrientationChanged = true;
- documentChanged = true;
- }
- }
-
- if (pageOrientationChanged)
- {
- // Changing the orientation is not enough. You must also
- // change the page size.
- var width = pgSz.Width;
- var height = pgSz.Height;
- pgSz.Width = height;
- pgSz.Height = width;
-
- PageMargin pgMar =
- sectPr.Descendants().FirstOrDefault();
- if (pgMar != null)
- {
- // Rotate margins. Printer settings control how far you
- // rotate when switching to landscape mode. Not having those
- // settings, this code rotates 90 degrees. You could easily
- // modify this behavior, or make it a parameter for the
- // procedure.
- var top = pgMar.Top.Value;
- var bottom = pgMar.Bottom.Value;
- var left = pgMar.Left.Value;
- var right = pgMar.Right.Value;
-
- pgMar.Top = new Int32Value((int)left);
- pgMar.Bottom = new Int32Value((int)right);
- pgMar.Left =
- new UInt32Value((uint)System.Math.Max(0, bottom));
- pgMar.Right =
- new UInt32Value((uint)System.Math.Max(0, top));
- }
- }
- }
- }
- if (documentChanged)
- {
- docPart.Document.Save();
- }
- }
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/change_the_print_orientation/cs/Program.cs)]
-```vb
- ' Given a document name, set the print orientation for
- ' all the sections of the document.
- Public Sub SetPrintOrientation(
- ByVal fileName As String, ByVal newOrientation As PageOrientationValues)
- Using document =
- WordprocessingDocument.Open(fileName, True)
- Dim documentChanged As Boolean = False
-
- Dim docPart = document.MainDocumentPart
- Dim sections = docPart.Document.Descendants(Of SectionProperties)()
-
- For Each sectPr As SectionProperties In sections
-
- Dim pageOrientationChanged As Boolean = False
-
- Dim pgSz As PageSize =
- sectPr.Descendants(Of PageSize).FirstOrDefault
- If pgSz IsNot Nothing Then
- ' No Orient property? Create it now. Otherwise, just
- ' set its value. Assume that the default orientation
- ' is Portrait.
- If pgSz.Orient Is Nothing Then
- ' Need to create the attribute. You do not need to
- ' create the Orient property if the property does not
- ' already exist and you are setting it to Portrait.
- ' That is the default value.
- If newOrientation <> PageOrientationValues.Portrait Then
- pageOrientationChanged = True
- documentChanged = True
- pgSz.Orient =
- New EnumValue(Of PageOrientationValues)(newOrientation)
- End If
- Else
- ' The Orient property exists, but its value
- ' is different than the new value.
- If pgSz.Orient.Value <> newOrientation Then
- pgSz.Orient.Value = newOrientation
- pageOrientationChanged = True
- documentChanged = True
- End If
- End If
-
- If pageOrientationChanged Then
- ' Changing the orientation is not enough. You must also
- ' change the page size.
- Dim width = pgSz.Width
- Dim height = pgSz.Height
- pgSz.Width = height
- pgSz.Height = width
-
- Dim pgMar As PageMargin =
- sectPr.Descendants(Of PageMargin).FirstOrDefault()
- If pgMar IsNot Nothing Then
- ' Rotate margins. Printer settings control how far you
- ' rotate when switching to landscape mode. Not having those
- ' settings, this code rotates 90 degrees. You could easily
- ' modify this behavior, or make it a parameter for the
- ' procedure.
- Dim top = pgMar.Top.Value
- Dim bottom = pgMar.Bottom.Value
- Dim left = pgMar.Left.Value
- Dim right = pgMar.Right.Value
-
- pgMar.Top = CType(left, Int32Value)
- pgMar.Bottom = CType(right, Int32Value)
- pgMar.Left = CType(System.Math.Max(0,
- CType(bottom, Int32Value)), UInt32Value)
- pgMar.Right = CType(System.Math.Max(0,
- CType(top, Int32Value)), UInt32Value)
- End If
- End If
- End If
- Next
-
- If documentChanged Then
- docPart.Document.Save()
- End If
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/change_the_print_orientation/vb/Program.vb)]
-----------------------------------------------------------------------------
diff --git a/docs/how-to-convert-a-word-processing-document-from-the-docm-to-the-docx-file-format.md b/docs/how-to-convert-a-word-processing-document-from-the-docm-to-the-docx-file-format.md
index 84703680..a74d6193 100644
--- a/docs/how-to-convert-a-word-processing-document-from-the-docm-to-the-docx-file-format.md
+++ b/docs/how-to-convert-a-word-processing-document-from-the-docm-to-the-docx-file-format.md
@@ -234,103 +234,11 @@ old file name to the new file name.
The following is the complete **ConvertDOCMtoDOCX** code sample in C\# and Visual
Basic.
-```csharp
- // Given a .docm file (with macro storage), remove the VBA
- // project, reset the document type, and save the document with a new name.
- public static void ConvertDOCMtoDOCX(string fileName)
- {
- bool fileChanged = false;
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs)]
- using (WordprocessingDocument document =
- WordprocessingDocument.Open(fileName, true))
- {
- // Access the main document part.
- var docPart = document.MainDocumentPart;
-
- // Look for the vbaProject part. If it is there, delete it.
- var vbaPart = docPart.VbaProjectPart;
- if (vbaPart != null)
- {
- // Delete the vbaProject part and then save the document.
- docPart.DeletePart(vbaPart);
- docPart.Document.Save();
-
- // Change the document type to
- // not macro-enabled.
- document.ChangeDocumentType(
- WordprocessingDocumentType.Document);
-
- // Track that the document has been changed.
- fileChanged = true;
- }
- }
-
- // If anything goes wrong in this file handling,
- // the code will raise an exception back to the caller.
- if (fileChanged)
- {
- // Create the new .docx filename.
- var newFileName = Path.ChangeExtension(fileName, ".docx");
-
- // If it already exists, it will be deleted!
- if (File.Exists(newFileName))
- {
- File.Delete(newFileName);
- }
-
- // Rename the file.
- File.Move(fileName, newFileName);
- }
- }
-```
-
-```vb
- ' Given a .docm file (with macro storage), remove the VBA
- ' project, reset the document type, and save the document with a new name.
- Public Sub ConvertDOCMtoDOCX(ByVal fileName As String)
- Dim fileChanged As Boolean = False
-
- Using document As WordprocessingDocument =
- WordprocessingDocument.Open(fileName, True)
-
- ' Access the main document part.
- Dim docPart = document.MainDocumentPart
-
- ' Look for the vbaProject part. If it is there, delete it.
- Dim vbaPart = docPart.VbaProjectPart
- If vbaPart IsNot Nothing Then
-
- ' Delete the vbaProject part and then save the document.
- docPart.DeletePart(vbaPart)
- docPart.Document.Save()
-
- ' Change the document type to
- ' not macro-enabled.
- document.ChangeDocumentType(
- WordprocessingDocumentType.Document)
-
- ' Track that the document has been changed.
- fileChanged = True
- End If
- End Using
-
- ' If anything goes wrong in this file handling,
- ' the code will raise an exception back to the caller.
- If fileChanged Then
-
- ' Create the new .docx filename.
- Dim newFileName = Path.ChangeExtension(fileName, ".docx")
-
- ' If it already exists, it will be deleted!
- If File.Exists(newFileName) Then
- File.Delete(newFileName)
- End If
-
- ' Rename the file.
- File.Move(fileName, newFileName)
- End If
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/convert_from_the_docm_to_the_docx_file_format/vb/Program.vb)]
## See also
diff --git a/docs/how-to-create-a-presentation-document-by-providing-a-file-name.md b/docs/how-to-create-a-presentation-document-by-providing-a-file-name.md
index b0a02240..2f4630be 100644
--- a/docs/how-to-create-a-presentation-document-by-providing-a-file-name.md
+++ b/docs/how-to-create-a-presentation-document-by-providing-a-file-name.md
@@ -152,624 +152,11 @@ two slides.
Following is the complete sample C\# and VB code to create a
presentation, given a file path.
-```csharp
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Drawing;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Presentation;
- using P = DocumentFormat.OpenXml.Presentation;
- using D = DocumentFormat.OpenXml.Drawing;
-
- namespace CreatePresentationDocument
- {
- class Program
- {
- static void Main(string[] args)
- {
- string filepath = @"C:\Users\username\Documents\PresentationFromFilename.pptx";
- CreatePresentation(filepath);
- }
-
- public static void CreatePresentation(string filepath)
- {
- // Create a presentation at a specified file path. The presentation document type is pptx, by default.
- PresentationDocument presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation);
- PresentationPart presentationPart = presentationDoc.AddPresentationPart();
- presentationPart.Presentation = new Presentation();
-
- CreatePresentationParts(presentationPart);
-
- //Close the presentation handle
- presentationDoc.Close();
- }
-
- private static void CreatePresentationParts(PresentationPart presentationPart)
- {
- SlideMasterIdList slideMasterIdList1 = new SlideMasterIdList(new SlideMasterId() { Id = (UInt32Value)2147483648U, RelationshipId = "rId1" });
- SlideIdList slideIdList1 = new SlideIdList(new SlideId() { Id = (UInt32Value)256U, RelationshipId = "rId2" });
- SlideSize slideSize1 = new SlideSize() { Cx = 9144000, Cy = 6858000, Type = SlideSizeValues.Screen4x3 };
- NotesSize notesSize1 = new NotesSize() { Cx = 6858000, Cy = 9144000 };
- DefaultTextStyle defaultTextStyle1 = new DefaultTextStyle();
-
- presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1);
-
- SlidePart slidePart1;
- SlideLayoutPart slideLayoutPart1;
- SlideMasterPart slideMasterPart1;
- ThemePart themePart1;
-
-
- slidePart1 = CreateSlidePart(presentationPart);
- slideLayoutPart1 = CreateSlideLayoutPart(slidePart1);
- slideMasterPart1 = CreateSlideMasterPart(slideLayoutPart1);
- themePart1 = CreateTheme(slideMasterPart1);
-
- slideMasterPart1.AddPart(slideLayoutPart1, "rId1");
- presentationPart.AddPart(slideMasterPart1, "rId1");
- presentationPart.AddPart(themePart1, "rId5");
- }
-
- private static SlidePart CreateSlidePart(PresentationPart presentationPart)
- {
- SlidePart slidePart1 = presentationPart.AddNewPart("rId2");
- slidePart1.Slide = new Slide(
- new CommonSlideData(
- new ShapeTree(
- new P.NonVisualGroupShapeProperties(
- new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
- new P.NonVisualGroupShapeDrawingProperties(),
- new ApplicationNonVisualDrawingProperties()),
- new GroupShapeProperties(new TransformGroup()),
- new P.Shape(
- new P.NonVisualShapeProperties(
- new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
- new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
- new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
- new P.ShapeProperties(),
- new P.TextBody(
- new BodyProperties(),
- new ListStyle(),
- new Paragraph(new EndParagraphRunProperties() { Language = "en-US" }))))),
- new ColorMapOverride(new MasterColorMapping()));
- return slidePart1;
- }
-
- private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
- {
- SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart("rId1");
- SlideLayout slideLayout = new SlideLayout(
- new CommonSlideData(new ShapeTree(
- new P.NonVisualGroupShapeProperties(
- new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
- new P.NonVisualGroupShapeDrawingProperties(),
- new ApplicationNonVisualDrawingProperties()),
- new GroupShapeProperties(new TransformGroup()),
- new P.Shape(
- new P.NonVisualShapeProperties(
- new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" },
- new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
- new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
- new P.ShapeProperties(),
- new P.TextBody(
- new BodyProperties(),
- new ListStyle(),
- new Paragraph(new EndParagraphRunProperties()))))),
- new ColorMapOverride(new MasterColorMapping()));
- slideLayoutPart1.SlideLayout = slideLayout;
- return slideLayoutPart1;
- }
-
- private static SlideMasterPart CreateSlideMasterPart(SlideLayoutPart slideLayoutPart1)
- {
- SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart("rId1");
- SlideMaster slideMaster = new SlideMaster(
- new CommonSlideData(new ShapeTree(
- new P.NonVisualGroupShapeProperties(
- new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
- new P.NonVisualGroupShapeDrawingProperties(),
- new ApplicationNonVisualDrawingProperties()),
- new GroupShapeProperties(new TransformGroup()),
- new P.Shape(
- new P.NonVisualShapeProperties(
- new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title Placeholder 1" },
- new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
- new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Title })),
- new P.ShapeProperties(),
- new P.TextBody(
- new BodyProperties(),
- new ListStyle(),
- new Paragraph())))),
- new P.ColorMap() { Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink },
- new SlideLayoutIdList(new SlideLayoutId() { Id = (UInt32Value)2147483649U, RelationshipId = "rId1" }),
- new TextStyles(new TitleStyle(), new BodyStyle(), new OtherStyle()));
- slideMasterPart1.SlideMaster = slideMaster;
-
- return slideMasterPart1;
- }
-
- private static ThemePart CreateTheme(SlideMasterPart slideMasterPart1)
- {
- ThemePart themePart1 = slideMasterPart1.AddNewPart("rId5");
- D.Theme theme1 = new D.Theme() { Name = "Office Theme" };
-
- D.ThemeElements themeElements1 = new D.ThemeElements(
- new D.ColorScheme(
- new D.Dark1Color(new D.SystemColor() { Val = D.SystemColorValues.WindowText, LastColor = "000000" }),
- new D.Light1Color(new D.SystemColor() { Val = D.SystemColorValues.Window, LastColor = "FFFFFF" }),
- new D.Dark2Color(new D.RgbColorModelHex() { Val = "1F497D" }),
- new D.Light2Color(new D.RgbColorModelHex() { Val = "EEECE1" }),
- new D.Accent1Color(new D.RgbColorModelHex() { Val = "4F81BD" }),
- new D.Accent2Color(new D.RgbColorModelHex() { Val = "C0504D" }),
- new D.Accent3Color(new D.RgbColorModelHex() { Val = "9BBB59" }),
- new D.Accent4Color(new D.RgbColorModelHex() { Val = "8064A2" }),
- new D.Accent5Color(new D.RgbColorModelHex() { Val = "4BACC6" }),
- new D.Accent6Color(new D.RgbColorModelHex() { Val = "F79646" }),
- new D.Hyperlink(new D.RgbColorModelHex() { Val = "0000FF" }),
- new D.FollowedHyperlinkColor(new D.RgbColorModelHex() { Val = "800080" })) { Name = "Office" },
- new D.FontScheme(
- new D.MajorFont(
- new D.LatinFont() { Typeface = "Calibri" },
- new D.EastAsianFont() { Typeface = "" },
- new D.ComplexScriptFont() { Typeface = "" }),
- new D.MinorFont(
- new D.LatinFont() { Typeface = "Calibri" },
- new D.EastAsianFont() { Typeface = "" },
- new D.ComplexScriptFont() { Typeface = "" })) { Name = "Office" },
- new D.FormatScheme(
- new D.FillStyleList(
- new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }),
- new D.GradientFill(
- new D.GradientStopList(
- new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 50000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 },
- new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 37000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 35000 },
- new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 15000 },
- new D.SaturationModulation() { Val = 350000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 100000 }
- ),
- new D.LinearGradientFill() { Angle = 16200000, Scaled = true }),
- new D.NoFill(),
- new D.PatternFill(),
- new D.GroupFill()),
- new D.LineStyleList(
- new D.Outline(
- new D.SolidFill(
- new D.SchemeColor(
- new D.Shade() { Val = 95000 },
- new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }),
- new D.PresetDash() { Val = D.PresetLineDashValues.Solid })
- {
- Width = 9525,
- CapType = D.LineCapValues.Flat,
- CompoundLineType = D.CompoundLineValues.Single,
- Alignment = D.PenAlignmentValues.Center
- },
- new D.Outline(
- new D.SolidFill(
- new D.SchemeColor(
- new D.Shade() { Val = 95000 },
- new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }),
- new D.PresetDash() { Val = D.PresetLineDashValues.Solid })
- {
- Width = 9525,
- CapType = D.LineCapValues.Flat,
- CompoundLineType = D.CompoundLineValues.Single,
- Alignment = D.PenAlignmentValues.Center
- },
- new D.Outline(
- new D.SolidFill(
- new D.SchemeColor(
- new D.Shade() { Val = 95000 },
- new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }),
- new D.PresetDash() { Val = D.PresetLineDashValues.Solid })
- {
- Width = 9525,
- CapType = D.LineCapValues.Flat,
- CompoundLineType = D.CompoundLineValues.Single,
- Alignment = D.PenAlignmentValues.Center
- }),
- new D.EffectStyleList(
- new D.EffectStyle(
- new D.EffectList(
- new D.OuterShadow(
- new D.RgbColorModelHex(
- new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })),
- new D.EffectStyle(
- new D.EffectList(
- new D.OuterShadow(
- new D.RgbColorModelHex(
- new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })),
- new D.EffectStyle(
- new D.EffectList(
- new D.OuterShadow(
- new D.RgbColorModelHex(
- new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false }))),
- new D.BackgroundFillStyleList(
- new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }),
- new D.GradientFill(
- new D.GradientStopList(
- new D.GradientStop(
- new D.SchemeColor(new D.Tint() { Val = 50000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 },
- new D.GradientStop(
- new D.SchemeColor(new D.Tint() { Val = 50000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 },
- new D.GradientStop(
- new D.SchemeColor(new D.Tint() { Val = 50000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }),
- new D.LinearGradientFill() { Angle = 16200000, Scaled = true }),
- new D.GradientFill(
- new D.GradientStopList(
- new D.GradientStop(
- new D.SchemeColor(new D.Tint() { Val = 50000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 },
- new D.GradientStop(
- new D.SchemeColor(new D.Tint() { Val = 50000 },
- new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }),
- new D.LinearGradientFill() { Angle = 16200000, Scaled = true }))) { Name = "Office" });
-
- theme1.Append(themeElements1);
- theme1.Append(new D.ObjectDefaults());
- theme1.Append(new D.ExtraColorSchemeList());
-
- themePart1.Theme = theme1;
- return themePart1;
-
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/presentation/create_by_providing_a_file_name/cs/Program.cs)]
-```vb
- Imports System.Collections.Generic
- Imports System.Linq
- Imports System.Text
- Imports DocumentFormat.OpenXml
- Imports DocumentFormat.OpenXml.Drawing
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Presentation
- Imports P = DocumentFormat.OpenXml.Presentation
- Imports D = DocumentFormat.OpenXml.Drawing
-
-
- Namespace CreatePresentationDocument
- Class Program
- Public Shared Sub Main(ByVal args As String())
-
- Dim filepath As String = "C:\Users\username\Documents\PresentationFromFilename.pptx"
- CreatePresentation(filepath)
-
- End Sub
-
- Public Shared Sub CreatePresentation(ByVal filepath As String)
- ' Create a presentation at a specified file path. The presentation document type is pptx, by default.
- Dim presentationDoc As PresentationDocument = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation)
- Dim presentationPart As PresentationPart = presentationDoc.AddPresentationPart()
- presentationPart.Presentation = New Presentation()
-
- CreatePresentationParts(presentationPart)
-
- 'Close the presentation handle
- presentationDoc.Close()
- End Sub
-
- Private Shared Sub CreatePresentationParts(ByVal presentationPart As PresentationPart)
- Dim slideMasterIdList1 As New SlideMasterIdList(New SlideMasterId() With { _
- .Id = CType(2147483648UI, UInt32Value), _
- .RelationshipId = "rId1" _
- })
- Dim slideIdList1 As New SlideIdList(New SlideId() With { _
- .Id = CType(256UI, UInt32Value), .RelationshipId = "rId2" _
- })
- Dim slideSize1 As New SlideSize() With { _
- .Cx = 9144000, _
- .Cy = 6858000, _
- .Type = SlideSizeValues.Screen4x3 _
- }
- Dim notesSize1 As New NotesSize() With { _
- .Cx = 6858000, _
- .Cy = 9144000 _
- }
- Dim defaultTextStyle1 As New DefaultTextStyle()
-
- Dim slidePart1 As SlidePart
- Dim slideLayoutPart1 As SlideLayoutPart
- Dim slideMasterPart1 As SlideMasterPart
- Dim themePart1 As ThemePart
-
- presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1)
-
- slidePart1 = CreateSlidePart(presentationPart)
- slideLayoutPart1 = CreateSlideLayoutPart(slidePart1)
- slideMasterPart1 = CreateSlideMasterPart(slideLayoutPart1)
- themePart1 = CreateTheme(slideMasterPart1)
-
- slideMasterPart1.AddPart(slideLayoutPart1, "rId1")
- presentationPart.AddPart(slideMasterPart1, "rId1")
- presentationPart.AddPart(themePart1, "rId5")
- End Sub
-
- Private Shared Function CreateSlidePart(ByVal presentationPart As PresentationPart) As SlidePart
- Dim slidePart1 As SlidePart = presentationPart.AddNewPart(Of SlidePart)("rId2")
- slidePart1.Slide = New Slide(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With { _
- .Id = CType(1UI, UInt32Value), _
- .Name = "" _
- }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()), New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With { _
- .Id = CType(2UI, UInt32Value), _
- .Name = "Title 1" _
- }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With { _
- .NoGrouping = True _
- }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New P.TextBody(New BodyProperties(), New ListStyle(), New Paragraph(New EndParagraphRunProperties() With { _
- .Language = "en-US" _
- }))))), New ColorMapOverride(New MasterColorMapping()))
- Return slidePart1
- End Function
-
- Private Shared Function CreateSlideLayoutPart(ByVal slidePart1 As SlidePart) As SlideLayoutPart
- Dim slideLayoutPart1 As SlideLayoutPart = slidePart1.AddNewPart(Of SlideLayoutPart)("rId1")
- Dim slideLayout As New SlideLayout(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With { _
- .Id = CType(1UI, UInt32Value), _
- .Name = "" _
- }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()), _
- New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With { _
- .Id = CType(2UI, UInt32Value), _
- .Name = "" _
- }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With { _
- .NoGrouping = True _
- }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New P.TextBody(New BodyProperties(), _
- New ListStyle(), New Paragraph(New EndParagraphRunProperties()))))), New ColorMapOverride(New MasterColorMapping()))
- slideLayoutPart1.SlideLayout = slideLayout
- Return slideLayoutPart1
- End Function
-
- Private Shared Function CreateSlideMasterPart(ByVal slideLayoutPart1 As SlideLayoutPart) As SlideMasterPart
- Dim slideMasterPart1 As SlideMasterPart = slideLayoutPart1.AddNewPart(Of SlideMasterPart)("rId1")
- Dim slideMaster As New SlideMaster(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With { _
- .Id = CType(1UI, UInt32Value), _
- .Name = "" _
- }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()), _
- New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With { _
- .Id = CType(2UI, UInt32Value), _
- .Name = "Title Placeholder 1" _
- }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With { _
- .NoGrouping = True _
- }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape() With { _
- .Type = PlaceholderValues.Title _
- })), New P.ShapeProperties(), New P.TextBody(New BodyProperties(), New ListStyle(), New Paragraph())))), New P.ColorMap() With { _
- .Background1 = D.ColorSchemeIndexValues.Light1, _
- .Text1 = D.ColorSchemeIndexValues.Dark1, _
- .Background2 = D.ColorSchemeIndexValues.Light2, _
- .Text2 = D.ColorSchemeIndexValues.Dark2, _
- .Accent1 = D.ColorSchemeIndexValues.Accent1, _
- .Accent2 = D.ColorSchemeIndexValues.Accent2, _
- .Accent3 = D.ColorSchemeIndexValues.Accent3, _
- .Accent4 = D.ColorSchemeIndexValues.Accent4, _
- .Accent5 = D.ColorSchemeIndexValues.Accent5, _
- .Accent6 = D.ColorSchemeIndexValues.Accent6, _
- .Hyperlink = D.ColorSchemeIndexValues.Hyperlink, _
- .FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink _
- }, New SlideLayoutIdList(New SlideLayoutId() With { _
- .Id = CType(2147483649UI, UInt32Value), _
- .RelationshipId = "rId1" _
- }), New TextStyles(New TitleStyle(), New BodyStyle(), New OtherStyle()))
- slideMasterPart1.SlideMaster = slideMaster
-
- Return slideMasterPart1
- End Function
-
- Private Shared Function CreateTheme(ByVal slideMasterPart1 As SlideMasterPart) As ThemePart
- Dim themePart1 As ThemePart = slideMasterPart1.AddNewPart(Of ThemePart)("rId5")
- Dim theme1 As New D.Theme() With { _
- .Name = "Office Theme" _
- }
-
- Dim themeElements1 As New D.ThemeElements(New D.ColorScheme(New D.Dark1Color(New D.SystemColor() With { _
- .Val = D.SystemColorValues.WindowText, _
- .LastColor = "000000" _
- }), New D.Light1Color(New D.SystemColor() With { _
- .Val = D.SystemColorValues.Window, _
- .LastColor = "FFFFFF" _
- }), New D.Dark2Color(New D.RgbColorModelHex() With { _
- .Val = "1F497D" _
- }), New D.Light2Color(New D.RgbColorModelHex() With { _
- .Val = "EEECE1" _
- }), New D.Accent1Color(New D.RgbColorModelHex() With { _
- .Val = "4F81BD" _
- }), New D.Accent2Color(New D.RgbColorModelHex() With { _
- .Val = "C0504D" _
- }), _
- New D.Accent3Color(New D.RgbColorModelHex() With { _
- .Val = "9BBB59" _
- }), New D.Accent4Color(New D.RgbColorModelHex() With { _
- .Val = "8064A2" _
- }), New D.Accent5Color(New D.RgbColorModelHex() With { _
- .Val = "4BACC6" _
- }), New D.Accent6Color(New D.RgbColorModelHex() With { _
- .Val = "F79646" _
- }), New D.Hyperlink(New D.RgbColorModelHex() With { _
- .Val = "0000FF" _
- }), New D.FollowedHyperlinkColor(New D.RgbColorModelHex() With { _
- .Val = "800080" _
- })) With { _
- .Name = "Office" _
- }, New D.FontScheme(New D.MajorFont(New D.LatinFont() With { _
- .Typeface = "Calibri" _
- }, New D.EastAsianFont() With { _
- .Typeface = "" _
- }, New D.ComplexScriptFont() With { _
- .Typeface = "" _
- }), New D.MinorFont(New D.LatinFont() With { _
- .Typeface = "Calibri" _
- }, New D.EastAsianFont() With { _
- .Typeface = "" _
- }, New D.ComplexScriptFont() With { _
- .Typeface = "" _
- })) With { _
- .Name = "Office" _
- }, New D.FormatScheme(New D.FillStyleList(New D.SolidFill(New D.SchemeColor() With { _
- .Val = D.SchemeColorValues.PhColor _
- }), New D.GradientFill(New D.GradientStopList(New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 50000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 0 _
- }, New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 37000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 35000 _
- }, New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 15000 _
- }, New D.SaturationModulation() With { _
- .Val = 350000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 100000 _
- }), New D.LinearGradientFill() With { _
- .Angle = 16200000, _
- .Scaled = True _
- }), New D.NoFill(), New D.PatternFill(), New D.GroupFill()), New D.LineStyleList(New D.Outline(New D.SolidFill(New D.SchemeColor(New D.Shade() With { _
- .Val = 95000 _
- }, New D.SaturationModulation() With { _
- .Val = 105000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }), New D.PresetDash() With { _
- .Val = D.PresetLineDashValues.Solid _
- }) With { _
- .Width = 9525, _
- .CapType = D.LineCapValues.Flat, _
- .CompoundLineType = D.CompoundLineValues.[Single], _
- .Alignment = D.PenAlignmentValues.Center _
- }, New D.Outline(New D.SolidFill(New D.SchemeColor(New D.Shade() With { _
- .Val = 95000 _
- }, New D.SaturationModulation() With { _
- .Val = 105000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }), New D.PresetDash() With { _
- .Val = D.PresetLineDashValues.Solid _
- }) With { _
- .Width = 9525, _
- .CapType = D.LineCapValues.Flat, _
- .CompoundLineType = D.CompoundLineValues.[Single], _
- .Alignment = D.PenAlignmentValues.Center _
- }, New D.Outline(New D.SolidFill(New D.SchemeColor(New D.Shade() With { _
- .Val = 95000 _
- }, New D.SaturationModulation() With { _
- .Val = 105000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }), New D.PresetDash() With { _
- .Val = D.PresetLineDashValues.Solid _
- }) With { _
- .Width = 9525, _
- .CapType = D.LineCapValues.Flat, _
- .CompoundLineType = D.CompoundLineValues.[Single], _
- .Alignment = D.PenAlignmentValues.Center _
- }), New D.EffectStyleList(New D.EffectStyle(New D.EffectList(New D.OuterShadow(New D.RgbColorModelHex(New D.Alpha() With { _
- .Val = 38000 _
- }) With { _
- .Val = "000000" _
- }) With { _
- .BlurRadius = 40000L, _
- .Distance = 20000L, _
- .Direction = 5400000, _
- .RotateWithShape = False _
- })), New D.EffectStyle(New D.EffectList(New D.OuterShadow(New D.RgbColorModelHex(New D.Alpha() With { _
- .Val = 38000 _
- }) With { _
- .Val = "000000" _
- }) With { _
- .BlurRadius = 40000L, _
- .Distance = 20000L, _
- .Direction = 5400000, _
- .RotateWithShape = False _
- })), New D.EffectStyle(New D.EffectList(New D.OuterShadow(New D.RgbColorModelHex(New D.Alpha() With { _
- .Val = 38000 _
- }) With { _
- .Val = "000000" _
- }) With { _
- .BlurRadius = 40000L, _
- .Distance = 20000L, _
- .Direction = 5400000, _
- .RotateWithShape = False _
- }))), New D.BackgroundFillStyleList(New D.SolidFill(New D.SchemeColor() With { _
- .Val = D.SchemeColorValues.PhColor _
- }), New D.GradientFill(New D.GradientStopList(New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 50000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 0 _
- }, New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 50000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 0 _
- }, New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 50000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 0 _
- }), New D.LinearGradientFill() With { _
- .Angle = 16200000, _
- .Scaled = True _
- }), New D.GradientFill(New D.GradientStopList(New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 50000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 0 _
- }, New D.GradientStop(New D.SchemeColor(New D.Tint() With { _
- .Val = 50000 _
- }, New D.SaturationModulation() With { _
- .Val = 300000 _
- }) With { _
- .Val = D.SchemeColorValues.PhColor _
- }) With { _
- .Position = 0 _
- }), New D.LinearGradientFill() With { _
- .Angle = 16200000, _
- .Scaled = True _
- }))) With { _
- .Name = "Office" _
- })
-
- theme1.Append(themeElements1)
- theme1.Append(New D.ObjectDefaults())
- theme1.Append(New D.ExtraColorSchemeList())
-
- themePart1.Theme = theme1
- Return themePart1
-
- End Function
-
- End Class
-
- End Namespace
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/presentation/create_by_providing_a_file_name/vb/Program.vb)]
--------------------------------------------------------------------------------
diff --git a/docs/how-to-create-and-add-a-character-style-to-a-word-processing-document.md b/docs/how-to-create-and-add-a-character-style-to-a-word-processing-document.md
index a61412ef..8bfe1553 100644
--- a/docs/how-to-create-and-add-a-character-style-to-a-word-processing-document.md
+++ b/docs/how-to-create-and-add-a-character-style-to-a-word-processing-document.md
@@ -507,124 +507,11 @@ properties' **rStyle** element.
The following is the complete **CreateAndAddCharacterStyle** code sample in both C\# and Visual Basic.
-```csharp
- // Create a new character style with the specified style id, style name and aliases and
- // add it to the specified style definitions part.
- public static void CreateAndAddCharacterStyle(StyleDefinitionsPart styleDefinitionsPart,
- string styleid, string stylename, string aliases="")
- {
- // Get access to the root element of the styles part.
- Styles styles = styleDefinitionsPart.Styles;
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/create_and_add_a_character_style/cs/Program.cs)]
- // Create a new character style and specify some of the attributes.
- Style style = new Style()
- {
- Type = StyleValues.Character,
- StyleId = styleid,
- CustomStyle = true
- };
-
- // Create and add the child elements (properties of the style).
- Aliases aliases1 = new Aliases() { Val = aliases };
- StyleName styleName1 = new StyleName() { Val = stylename };
- LinkedStyle linkedStyle1 = new LinkedStyle() { Val = "OverdueAmountPara" };
- if (aliases != "")
- style.Append(aliases1);
- style.Append(styleName1);
- style.Append(linkedStyle1);
-
- // Create the StyleRunProperties object and specify some of the run properties.
- StyleRunProperties styleRunProperties1 = new StyleRunProperties();
- Bold bold1 = new Bold();
- Color color1 = new Color() { ThemeColor = ThemeColorValues.Accent2 };
- RunFonts font1 = new RunFonts() { Ascii = "Tahoma" };
- Italic italic1 = new Italic();
- // Specify a 24 point size.
- FontSize fontSize1 = new FontSize() { Val = "48" };
- styleRunProperties1.Append(font1);
- styleRunProperties1.Append(fontSize1);
- styleRunProperties1.Append(color1);
- styleRunProperties1.Append(bold1);
- styleRunProperties1.Append(italic1);
-
- // Add the run properties to the style.
- style.Append(styleRunProperties1);
-
- // Add the style to the styles part.
- styles.Append(style);
- }
-
- // Add a StylesDefinitionsPart to the document. Returns a reference to it.
- public static StyleDefinitionsPart AddStylesPartToPackage(WordprocessingDocument doc)
- {
- StyleDefinitionsPart part;
- part = doc.MainDocumentPart.AddNewPart();
- Styles root = new Styles();
- root.Save(part);
- return part;
- }
-```
-
-```vb
- ' Create a new character style with the specified style id, style name and aliases and add
- ' it to the specified style definitions part.
- Public Sub CreateAndAddCharacterStyle(ByVal styleDefinitionsPart As StyleDefinitionsPart,
- ByVal styleid As String, ByVal stylename As String, Optional ByVal aliases As String = "")
- ' Get access to the root element of the styles part.
- Dim styles As Styles = styleDefinitionsPart.Styles
- If styles Is Nothing Then
- styleDefinitionsPart.Styles = New Styles()
- styleDefinitionsPart.Styles.Save()
- End If
-
- ' Create a new character style and specify some of the attributes.
- Dim style As New Style() With { _
- .Type = StyleValues.Character, _
- .StyleId = styleid, _
- .CustomStyle = True}
-
- ' Create and add the child elements (properties of the style).
- Dim aliases1 As New Aliases() With {.Val = aliases}
- Dim styleName1 As New StyleName() With {.Val = stylename}
- Dim linkedStyle1 As New LinkedStyle() With {.Val = "OverdueAmountPara"}
- If aliases <> "" Then
- style.Append(aliases1)
- End If
- style.Append(styleName1)
- style.Append(linkedStyle1)
-
- ' Create the StyleRunProperties object and specify some of the run properties.
- Dim styleRunProperties1 As New StyleRunProperties()
- Dim bold1 As New Bold()
- Dim color1 As New Color() With { _
- .ThemeColor = ThemeColorValues.Accent2}
- Dim font1 As New RunFonts() With {.Ascii = "Tahoma"}
- Dim italic1 As New Italic()
- ' Specify a 24 point size.
- Dim fontSize1 As New FontSize() With {.Val = "48"}
- styleRunProperties1.Append(font1)
- styleRunProperties1.Append(fontSize1)
- styleRunProperties1.Append(color1)
- styleRunProperties1.Append(bold1)
- styleRunProperties1.Append(italic1)
-
- ' Add the run properties to the style.
- style.Append(styleRunProperties1)
-
- ' Add the style to the styles part.
- styles.Append(style)
- End Sub
-
- ' Add a StylesDefinitionsPart to the document. Returns a reference to it.
- Public Function AddStylesPartToPackage(ByVal doc As WordprocessingDocument) _
- As StyleDefinitionsPart
- Dim part As StyleDefinitionsPart
- part = doc.MainDocumentPart.AddNewPart(Of StyleDefinitionsPart)()
- Dim root As New Styles()
- root.Save(part)
- Return part
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/create_and_add_a_character_style/vb/Program.vb)]
## See also
diff --git a/docs/how-to-create-and-add-a-paragraph-style-to-a-word-processing-document.md b/docs/how-to-create-and-add-a-paragraph-style-to-a-word-processing-document.md
index 3469a079..0619f2f7 100644
--- a/docs/how-to-create-and-add-a-paragraph-style-to-a-word-processing-document.md
+++ b/docs/how-to-create-and-add-a-paragraph-style-to-a-word-processing-document.md
@@ -561,170 +561,11 @@ ParagraphStyleId property represents the paragraph properties' **pStyle** elemen
The following is the complete **CreateAndAddParagraphStyle** code sample in both
C\# and Visual Basic.
-```csharp
- // Create a new paragraph style with the specified style ID, primary style name, and aliases and
- // add it to the specified style definitions part.
- public static void CreateAndAddParagraphStyle(StyleDefinitionsPart styleDefinitionsPart,
- string styleid, string stylename, string aliases="")
- {
- // Access the root element of the styles part.
- Styles styles = styleDefinitionsPart.Styles;
- if (styles == null)
- {
- styleDefinitionsPart.Styles = new Styles();
- styleDefinitionsPart.Styles.Save();
- }
-
- // Create a new paragraph style element and specify some of the attributes.
- Style style = new Style() { Type = StyleValues.Paragraph,
- StyleId = styleid,
- CustomStyle = true,
- Default = false
- };
-
- // Create and add the child elements (properties of the style).
- Aliases aliases1 = new Aliases() { Val = aliases };
- AutoRedefine autoredefine1 = new AutoRedefine() { Val = OnOffOnlyValues.Off };
- BasedOn basedon1 = new BasedOn() { Val = "Normal" };
- LinkedStyle linkedStyle1 = new LinkedStyle() { Val = "OverdueAmountChar" };
- Locked locked1 = new Locked() { Val = OnOffOnlyValues.Off };
- PrimaryStyle primarystyle1 = new PrimaryStyle() { Val = OnOffOnlyValues.On };
- StyleHidden stylehidden1 = new StyleHidden() { Val = OnOffOnlyValues.Off };
- SemiHidden semihidden1 = new SemiHidden() { Val = OnOffOnlyValues.Off };
- StyleName styleName1 = new StyleName() { Val = stylename };
- NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = "Normal" };
- UIPriority uipriority1 = new UIPriority() { Val = 1 };
- UnhideWhenUsed unhidewhenused1 = new UnhideWhenUsed() { Val = OnOffOnlyValues.On };
- if (aliases != "")
- style.Append(aliases1);
- style.Append(autoredefine1);
- style.Append(basedon1);
- style.Append(linkedStyle1);
- style.Append(locked1);
- style.Append(primarystyle1);
- style.Append(stylehidden1);
- style.Append(semihidden1);
- style.Append(styleName1);
- style.Append(nextParagraphStyle1);
- style.Append(uipriority1);
- style.Append(unhidewhenused1);
-
- // Create the StyleRunProperties object and specify some of the run properties.
- StyleRunProperties styleRunProperties1 = new StyleRunProperties();
- Bold bold1 = new Bold();
- Color color1 = new Color() { ThemeColor = ThemeColorValues.Accent2 };
- RunFonts font1 = new RunFonts() { Ascii = "Lucida Console" };
- Italic italic1 = new Italic();
- // Specify a 12 point size.
- FontSize fontSize1 = new FontSize() { Val = "24" };
- styleRunProperties1.Append(bold1);
- styleRunProperties1.Append(color1);
- styleRunProperties1.Append(font1);
- styleRunProperties1.Append(fontSize1);
- styleRunProperties1.Append(italic1);
-
- // Add the run properties to the style.
- style.Append(styleRunProperties1);
-
- // Add the style to the styles part.
- styles.Append(style);
- }
-
- // Add a StylesDefinitionsPart to the document. Returns a reference to it.
- public static StyleDefinitionsPart AddStylesPartToPackage(WordprocessingDocument doc)
- {
- StyleDefinitionsPart part;
- part = doc.MainDocumentPart.AddNewPart();
- Styles root = new Styles();
- root.Save(part);
- return part;
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/create_and_add_a_paragraph_style/cs/Program.cs)]
-```vb
- ' Create a new paragraph style with the specified style ID, primary style name, and aliases and
- ' add it to the specified style definitions part.
- Public Sub CreateAndAddParagraphStyle(ByVal styleDefinitionsPart As StyleDefinitionsPart,
- ByVal styleid As String, ByVal stylename As String, Optional ByVal aliases As String = "")
-
- ' Access the root element of the styles part.
- Dim styles As Styles = styleDefinitionsPart.Styles
- If styles Is Nothing Then
- styleDefinitionsPart.Styles = New Styles()
- styleDefinitionsPart.Styles.Save()
- End If
-
- ' Create a new paragraph style element and specify some of the attributes.
- Dim style As New Style() With { _
- .Type = StyleValues.Paragraph, _
- .StyleId = styleid, _
- .CustomStyle = True, _
- .[Default] = False}
-
- ' Create and add the child elements (properties of the style)
- Dim aliases1 As New Aliases() With {.Val = aliases}
- Dim autoredefine1 As New AutoRedefine() With {.Val = OnOffOnlyValues.Off}
- Dim basedon1 As New BasedOn() With {.Val = "Normal"}
- Dim linkedStyle1 As New LinkedStyle() With {.Val = "OverdueAmountChar"}
- Dim locked1 As New Locked() With {.Val = OnOffOnlyValues.Off}
- Dim primarystyle1 As New PrimaryStyle() With {.Val = OnOffOnlyValues.[On]}
- Dim stylehidden1 As New StyleHidden() With {.Val = OnOffOnlyValues.Off}
- Dim semihidden1 As New SemiHidden() With {.Val = OnOffOnlyValues.Off}
- Dim styleName1 As New StyleName() With {.Val = stylename}
- Dim nextParagraphStyle1 As New NextParagraphStyle() With { _
- .Val = "Normal"}
- Dim uipriority1 As New UIPriority() With {.Val = 1}
- Dim unhidewhenused1 As New UnhideWhenUsed() With { _
- .Val = OnOffOnlyValues.[On]}
- If aliases <> "" Then
- style.Append(aliases1)
- End If
- style.Append(autoredefine1)
- style.Append(basedon1)
- style.Append(linkedStyle1)
- style.Append(locked1)
- style.Append(primarystyle1)
- style.Append(stylehidden1)
- style.Append(semihidden1)
- style.Append(styleName1)
- style.Append(nextParagraphStyle1)
- style.Append(uipriority1)
- style.Append(unhidewhenused1)
-
- ' Create the StyleRunProperties object and specify some of the run properties.
- Dim styleRunProperties1 As New StyleRunProperties()
- Dim bold1 As New Bold()
- Dim color1 As New Color() With { _
- .ThemeColor = ThemeColorValues.Accent2}
- Dim font1 As New RunFonts() With { _
- .Ascii = "Lucida Console"}
- Dim italic1 As New Italic()
- ' Specify a 12 point size.
- Dim fontSize1 As New FontSize() With { _
- .Val = "24"}
- styleRunProperties1.Append(bold1)
- styleRunProperties1.Append(color1)
- styleRunProperties1.Append(font1)
- styleRunProperties1.Append(fontSize1)
- styleRunProperties1.Append(italic1)
-
- ' Add the run properties to the style.
- style.Append(styleRunProperties1)
-
- ' Add the style to the styles part.
- styles.Append(style)
- End Sub
-
- ' Add a StylesDefinitionsPart to the document. Returns a reference to it.
- Public Function AddStylesPartToPackage(ByVal doc As WordprocessingDocument) _
- As StyleDefinitionsPart
- Dim part As StyleDefinitionsPart
- part = doc.MainDocumentPart.AddNewPart(Of StyleDefinitionsPart)()
- Dim root As New Styles()
- root.Save(part)
- Return part
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/create_and_add_a_paragraph_style/vb/Program.vb)]
---------------------------------------------------------------------------------
diff --git a/docs/how-to-delete-comments-by-all-or-a-specific-author-in-a-word-processing-document.md b/docs/how-to-delete-comments-by-all-or-a-specific-author-in-a-word-processing-document.md
index 378c41b3..ed5e8913 100644
--- a/docs/how-to-delete-comments-by-all-or-a-specific-author-in-a-word-processing-document.md
+++ b/docs/how-to-delete-comments-by-all-or-a-specific-author-in-a-word-processing-document.md
@@ -326,158 +326,11 @@ saving the document.
The following is the complete code sample in both C\# and Visual Basic.
-```csharp
- // Delete comments by a specific author. Pass an empty string for the
- // author to delete all comments, by all authors.
- public static void DeleteComments(string fileName,
- string author = "")
- {
- // Get an existing Wordprocessing document.
- using (WordprocessingDocument document =
- WordprocessingDocument.Open(fileName, true))
- {
- // Set commentPart to the document WordprocessingCommentsPart,
- // if it exists.
- WordprocessingCommentsPart commentPart =
- document.MainDocumentPart.WordprocessingCommentsPart;
-
- // If no WordprocessingCommentsPart exists, there can be no
- // comments. Stop execution and return from the method.
- if (commentPart == null)
- {
- return;
- }
-
- // Create a list of comments by the specified author, or
- // if the author name is empty, all authors.
- List commentsToDelete =
- commentPart.Comments.Elements().ToList();
- if (!String.IsNullOrEmpty(author))
- {
- commentsToDelete = commentsToDelete.
- Where(c => c.Author == author).ToList();
- }
- IEnumerable commentIds =
- commentsToDelete.Select(r => r.Id.Value);
-
- // Delete each comment in commentToDelete from the
- // Comments collection.
- foreach (Comment c in commentsToDelete)
- {
- c.Remove();
- }
-
- // Save the comment part change.
- commentPart.Comments.Save();
-
- Document doc = document.MainDocumentPart.Document;
-
- // Delete CommentRangeStart for each
- // deleted comment in the main document.
- List commentRangeStartToDelete =
- doc.Descendants().
- Where(c => commentIds.Contains(c.Id.Value)).ToList();
- foreach (CommentRangeStart c in commentRangeStartToDelete)
- {
- c.Remove();
- }
-
- // Delete CommentRangeEnd for each deleted comment in the main document.
- List commentRangeEndToDelete =
- doc.Descendants().
- Where(c => commentIds.Contains(c.Id.Value)).ToList();
- foreach (CommentRangeEnd c in commentRangeEndToDelete)
- {
- c.Remove();
- }
-
- // Delete CommentReference for each deleted comment in the main document.
- List commentRangeReferenceToDelete =
- doc.Descendants().
- Where(c => commentIds.Contains(c.Id.Value)).ToList();
- foreach (CommentReference c in commentRangeReferenceToDelete)
- {
- c.Remove();
- }
-
- // Save changes back to the MainDocumentPart part.
- doc.Save();
- }
- }
-```
-
-```vb
- ' Delete comments by a specific author. Pass an empty string for the author
- ' to delete all comments, by all authors.
- Public Sub DeleteComments(ByVal fileName As String,
- Optional ByVal author As String = "")
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs)]
- ' Get an existing Wordprocessing document.
- Using document As WordprocessingDocument =
- WordprocessingDocument.Open(fileName, True)
- ' Set commentPart to the document
- ' WordprocessingCommentsPart, if it exists.
- Dim commentPart As WordprocessingCommentsPart =
- document.MainDocumentPart.WordprocessingCommentsPart
-
- ' If no WordprocessingCommentsPart exists, there can be no
- ' comments. Stop execution and return from the method.
- If (commentPart Is Nothing) Then
- Return
- End If
-
- ' Create a list of comments by the specified author, or
- ' if the author name is empty, all authors.
- Dim commentsToDelete As List(Of Comment) = _
- commentPart.Comments.Elements(Of Comment)().ToList()
- If Not String.IsNullOrEmpty(author) Then
- commentsToDelete = commentsToDelete.
- Where(Function(c) c.Author = author).ToList()
- End If
- Dim commentIds As IEnumerable(Of String) =
- commentsToDelete.Select(Function(r) r.Id.Value)
-
- ' Delete each comment in commentToDelete from the Comments
- ' collection.
- For Each c As Comment In commentsToDelete
- c.Remove()
- Next
-
- ' Save the comment part change.
- commentPart.Comments.Save()
-
- Dim doc As Document = document.MainDocumentPart.Document
-
- ' Delete CommentRangeStart for each
- ' deleted comment in the main document.
- Dim commentRangeStartToDelete As List(Of CommentRangeStart) = _
- doc.Descendants(Of CommentRangeStart). _
- Where(Function(c) commentIds.Contains(c.Id.Value)).ToList()
- For Each c As CommentRangeStart In commentRangeStartToDelete
- c.Remove()
- Next
-
- ' Delete CommentRangeEnd for each deleted comment in main document.
- Dim commentRangeEndToDelete As List(Of CommentRangeEnd) = _
- doc.Descendants(Of CommentRangeEnd). _
- Where(Function(c) commentIds.Contains(c.Id.Value)).ToList()
- For Each c As CommentRangeEnd In commentRangeEndToDelete
- c.Remove()
- Next
-
- ' Delete CommentReference for each deleted comment in the main document.
- Dim commentRangeReferenceToDelete As List(Of CommentReference) = _
- doc.Descendants(Of CommentReference). _
- Where(Function(c) commentIds.Contains(c.Id.Value)).ToList
- For Each c As CommentReference In commentRangeReferenceToDelete
- c.Remove()
- Next
-
- ' Save changes back to the MainDocumentPart part.
- doc.Save()
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/delete_comments_by_all_or_a_specific_author/vb/Program.vb)]
--------------------------------------------------------------------------------
diff --git a/docs/how-to-extract-styles-from-a-word-processing-document.md b/docs/how-to-extract-styles-from-a-word-processing-document.md
index 3f5f2eaa..a076b9b0 100644
--- a/docs/how-to-extract-styles-from-a-word-processing-document.md
+++ b/docs/how-to-extract-styles-from-a-word-processing-document.md
@@ -254,85 +254,11 @@ parameter.
The following is the complete **ExtractStylesPart** code sample in C\# and Visual Basic.
-```csharp
- // Extract the styles or stylesWithEffects part from a
- // word processing document as an XDocument instance.
- public static XDocument ExtractStylesPart(
- string fileName,
- bool getStylesWithEffectsPart = true)
- {
- // Declare a variable to hold the XDocument.
- XDocument styles = null;
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/extract_styles/cs/Program.cs)]
- // Open the document for read access and get a reference.
- using (var document =
- WordprocessingDocument.Open(fileName, false))
- {
- // Get a reference to the main document part.
- var docPart = document.MainDocumentPart;
-
- // Assign a reference to the appropriate part to the
- // stylesPart variable.
- StylesPart stylesPart = null;
- if (getStylesWithEffectsPart)
- stylesPart = docPart.StylesWithEffectsPart;
- else
- stylesPart = docPart.StyleDefinitionsPart;
-
- // If the part exists, read it into the XDocument.
- if (stylesPart != null)
- {
- using (var reader = XmlNodeReader.Create(
- stylesPart.GetStream(FileMode.Open, FileAccess.Read)))
- {
- // Create the XDocument.
- styles = XDocument.Load(reader);
- }
- }
- }
- // Return the XDocument instance.
- return styles;
- }
-```
-
-```vb
- ' Extract the styles or stylesWithEffects part from a
- ' word processing document as an XDocument instance.
- Public Function ExtractStylesPart(
- ByVal fileName As String,
- Optional ByVal getStylesWithEffectsPart As Boolean = True) As XDocument
-
- ' Declare a variable to hold the XDocument.
- Dim styles As XDocument = Nothing
-
- ' Open the document for read access and get a reference.
- Using document = WordprocessingDocument.Open(fileName, False)
-
- ' Get a reference to the main document part.
- Dim docPart = document.MainDocumentPart
-
- ' Assign a reference to the appropriate part to the
- ' stylesPart variable.
- Dim stylesPart As StylesPart = Nothing
- If getStylesWithEffectsPart Then
- stylesPart = docPart.StylesWithEffectsPart
- Else
- stylesPart = docPart.StyleDefinitionsPart
- End If
-
- ' If the part exists, read it into the XDocument.
- If stylesPart IsNot Nothing Then
- Using reader = XmlNodeReader.Create(
- stylesPart.GetStream(FileMode.Open, FileAccess.Read))
- ' Create the XDocument:
- styles = XDocument.Load(reader)
- End Using
- End If
- End Using
- ' Return the XDocument instance.
- Return styles
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/extract_styles/vb/Program.vb)]
---------------------------------------------------------------------------------
diff --git a/docs/how-to-insert-a-comment-into-a-word-processing-document.md b/docs/how-to-insert-a-comment-into-a-word-processing-document.md
index 975b9fe0..8311240b 100644
--- a/docs/how-to-insert-a-comment-into-a-word-processing-document.md
+++ b/docs/how-to-insert-a-comment-into-a-word-processing-document.md
@@ -20,22 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to programmatically add a comment to the first paragraph in a
word processing document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System;
- using System.Linq;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Wordprocessing;
-```
-
-```vb
- Imports System
- Imports System.Linq
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Wordprocessing
-```
--------------------------------------------------------------------------------
## Open the Existing Document for Editing
@@ -253,112 +238,11 @@ comment "This is my comment." in the file "Word8.docx."
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // Insert a comment on the first paragraph.
- public static void AddCommentOnFirstParagraph(string fileName,
- string author, string initials, string comment)
- {
- // Use the file name and path passed in as an
- // argument to open an existing Wordprocessing document.
- using (WordprocessingDocument document =
- WordprocessingDocument.Open(fileName, true))
- {
- // Locate the first paragraph in the document.
- Paragraph firstParagraph =
- document.MainDocumentPart.Document.Descendants().First();
- Comments comments = null;
- string id = "0";
-
- // Verify that the document contains a
- // WordProcessingCommentsPart part; if not, add a new one.
- if (document.MainDocumentPart.GetPartsCountOfType() > 0)
- {
- comments =
- document.MainDocumentPart.WordprocessingCommentsPart.Comments;
- if (comments.HasChildren)
- {
- // Obtain an unused ID.
- id = (comments.Descendants().Select(e => int.Parse(e.Id.Value)).Max() + 1).ToString();
- }
- }
- else
- {
- // No WordprocessingCommentsPart part exists, so add one to the package.
- WordprocessingCommentsPart commentPart =
- document.MainDocumentPart.AddNewPart();
- commentPart.Comments = new Comments();
- comments = commentPart.Comments;
- }
-
- // Compose a new Comment and add it to the Comments part.
- Paragraph p = new Paragraph(new Run(new Text(comment)));
- Comment cmt =
- new Comment() { Id = id,
- Author = author, Initials = initials, Date = DateTime.Now };
- cmt.AppendChild(p);
- comments.AppendChild(cmt);
- comments.Save();
-
- // Specify the text range for the Comment.
- // Insert the new CommentRangeStart before the first run of paragraph.
- firstParagraph.InsertBefore(new CommentRangeStart()
- { Id = id }, firstParagraph.GetFirstChild());
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/insert_a_comment/cs/Program.cs)]
- // Insert the new CommentRangeEnd after last run of paragraph.
- var cmtEnd = firstParagraph.InsertAfter(new CommentRangeEnd()
- { Id = id }, firstParagraph.Elements().Last());
-
- // Compose a run with CommentReference and insert it.
- firstParagraph.InsertAfter(new Run(new CommentReference() { Id = id }), cmtEnd);
- }
- }
-```
-
-```vb
- ' Insert a comment on the first paragraph.
- Public Sub AddCommentOnFirstParagraph(ByVal fileName As String, ByVal author As String, ByVal initials As String, ByVal comment As String)
- ' Use the file name and path passed in as an
- ' argument to open an existing Wordprocessing document.
- Using document As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
- ' Locate the first paragraph in the document.
- Dim firstParagraph As Paragraph = document.MainDocumentPart.Document.Descendants(Of Paragraph)().First()
- Dim comments As Comments = Nothing
- Dim id As String = "0"
-
- ' Verify that the document contains a
- ' WordProcessingCommentsPart part; if not, add a new one.
- If document.MainDocumentPart.GetPartsCountOfType(Of WordprocessingCommentsPart)() > 0 Then
- comments = document.MainDocumentPart.WordprocessingCommentsPart.Comments
- If comments.HasChildren Then
- ' Obtain an unused ID.
- id = comments.Descendants(Of Comment)().[Select](Function(e) e.Id.Value).Max()
- End If
- Else
- ' No WordprocessingCommentsPart part exists, so add one to the package.
- Dim commentPart As WordprocessingCommentsPart = document.MainDocumentPart.AddNewPart(Of WordprocessingCommentsPart)()
- commentPart.Comments = New Comments()
- comments = commentPart.Comments
- End If
-
- ' Compose a new Comment and add it to the Comments part.
- Dim p As New Paragraph(New Run(New Text(comment)))
- Dim cmt As New Comment() With {.Id = id, .Author = author, .Initials = initials, .Date = DateTime.Now}
- cmt.AppendChild(p)
- comments.AppendChild(cmt)
- comments.Save()
-
- ' Specify the text range for the Comment.
- ' Insert the new CommentRangeStart before the first run of paragraph.
- firstParagraph.InsertBefore(New CommentRangeStart() With {.Id = id}, firstParagraph.GetFirstChild(Of Run)())
-
- ' Insert the new CommentRangeEnd after last run of paragraph.
- Dim cmtEnd = firstParagraph.InsertAfter(New CommentRangeEnd() With {.Id = id}, firstParagraph.Elements(Of Run)().Last())
-
- ' Compose a run with CommentReference and insert it.
- firstParagraph.InsertAfter(New Run(New CommentReference() With {.Id = id}), cmtEnd)
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/insert_a_comment/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-insert-a-new-worksheet-into-a-spreadsheet.md b/docs/how-to-insert-a-new-worksheet-into-a-spreadsheet.md
index 3ca929a3..5e426250 100644
--- a/docs/how-to-insert-a-new-worksheet-into-a-spreadsheet.md
+++ b/docs/how-to-insert-a-new-worksheet-into-a-spreadsheet.md
@@ -20,20 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to insert a new worksheet into a spreadsheet document
programmatically.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.Linq;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Spreadsheet;
-```
-
-```vb
- Imports System.Linq
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Spreadsheet
-```
--------------------------------------------------------------------------------
## Getting a SpreadsheetDocument Object
@@ -137,75 +124,6 @@ the **workbook**, **sheets**, **sheet**, **worksheet**, and **sheetData** elemen
| v | DocumentFormat.OpenXml.Spreadsheet.CellValue | The value of a cell. |
---------------------------------------------------------------------------------
-## How the Sample Code Works
-After opening the document for editing as a **SpreadsheetDocument** document package, the code
-adds a new **WorksheetPart** object to the
-**WorkbookPart** object using the [AddNewPart](https://msdn.microsoft.com/library/office/documentformat.openxml.packaging.openxmlpartcontainer.addnewpart.aspx) method. It then adds a new **Worksheet** object to the **WorksheetPart** object.
-
-```csharp
- // Add a blank WorksheetPart.
- WorksheetPart newWorksheetPart =
- spreadSheet.WorkbookPart.AddNewPart();
- newWorksheetPart.Worksheet = new Worksheet(new SheetData());
-
- Sheets sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild();
- string relationshipId =
- spreadSheet.WorkbookPart.GetIdOfPart(newWorksheetPart);
-```
-
-```vb
- ' Add a blank WorksheetPart.
- Dim newWorksheetPart As WorksheetPart = spreadSheet.WorkbookPart.AddNewPart(Of WorksheetPart)()
- newWorksheetPart.Worksheet = New Worksheet(New SheetData())
- ' newWorksheetPart.Worksheet.Save()
-
- Dim sheets As Sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild(Of Sheets)()
- Dim relationshipId As String = spreadSheet.WorkbookPart.GetIdOfPart(newWorksheetPart)
-```
-
-The code then gets a unique ID for the new worksheet by selecting the
-maximum [SheetId](https://msdn.microsoft.com/library/office/documentformat.openxml.spreadsheet.sheet.sheetid.aspx) object used within the spreadsheet
-document and adding one to create the new sheet ID. It gives the
-worksheet a name by concatenating the word "Sheet" with the sheet ID and
-appends the new sheet to the sheets collection.
-
-```csharp
- // Get a unique ID for the new worksheet.
- uint sheetId = 1;
- if (sheets.Elements().Count() > 0)
- {
- sheetId =
- sheets.Elements().Select(s => s.SheetId.Value).Max() + 1;
- }
-
- // Give the new worksheet a name.
- string sheetName = "Sheet" + sheetId;
-
- // Append the new worksheet and associate it with the workbook.
- Sheet sheet = new Sheet()
- { Id = relationshipId, SheetId = sheetId, Name = sheetName };
- sheets.Append(sheet);
-```
-
-```vb
- ' Get a unique ID for the new worksheet.
- Dim sheetId As UInteger = 1
- If (sheets.Elements(Of Sheet).Count > 0) Then
- sheetId = sheets.Elements(Of Sheet).Select(Function(s) s.SheetId.Value).Max + 1
- End If
-
- ' Give the new worksheet a name.
- Dim sheetName As String = ("Sheet" + sheetId.ToString())
-
- ' Append the new worksheet and associate it with the workbook.
- Dim sheet As Sheet = New Sheet
- sheet.Id = relationshipId
- sheet.SheetId = sheetId
- sheet.Name = sheetName
- sheets.Append(sheet)
-```
-
--------------------------------------------------------------------------------
## Sample Code
In the following code, insert a blank [Worksheet](https://msdn.microsoft.com/library/office/documentformat.openxml.packaging.worksheetpart.worksheet.aspx) object by adding a blank [WorksheetPart](https://msdn.microsoft.com/library/office/documentformat.openxml.packaging.worksheetpart.aspx) object, generating a unique
@@ -227,70 +145,11 @@ inserts a worksheet in a file names "Sheet7.xslx," as an example.
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // Given a document name, inserts a new worksheet.
- public static void InsertWorksheet(string docName)
- {
- // Open the document for editing.
- using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(docName, true))
- {
- // Add a blank WorksheetPart.
- WorksheetPart newWorksheetPart = spreadSheet.WorkbookPart.AddNewPart();
- newWorksheetPart.Worksheet = new Worksheet(new SheetData());
-
- Sheets sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild();
- string relationshipId = spreadSheet.WorkbookPart.GetIdOfPart(newWorksheetPart);
-
- // Get a unique ID for the new worksheet.
- uint sheetId = 1;
- if (sheets.Elements().Count() > 0)
- {
- sheetId = sheets.Elements().Select(s => s.SheetId.Value).Max() + 1;
- }
-
- // Give the new worksheet a name.
- string sheetName = "Sheet" + sheetId;
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs)]
- // Append the new worksheet and associate it with the workbook.
- Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
- sheets.Append(sheet);
- }
- }
-```
-
-```vb
- ' Given a document name, inserts a new worksheet.
- Public Sub InsertWorksheet(ByVal docName As String)
- ' Open the document for editing.
- Dim spreadSheet As SpreadsheetDocument = SpreadsheetDocument.Open(docName, True)
-
- Using (spreadSheet)
- ' Add a blank WorksheetPart.
- Dim newWorksheetPart As WorksheetPart = spreadSheet.WorkbookPart.AddNewPart(Of WorksheetPart)()
- newWorksheetPart.Worksheet = New Worksheet(New SheetData())
- ' newWorksheetPart.Worksheet.Save()
-
- Dim sheets As Sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild(Of Sheets)()
- Dim relationshipId As String = spreadSheet.WorkbookPart.GetIdOfPart(newWorksheetPart)
-
- ' Get a unique ID for the new worksheet.
- Dim sheetId As UInteger = 1
- If (sheets.Elements(Of Sheet).Count > 0) Then
- sheetId = sheets.Elements(Of Sheet).Select(Function(s) s.SheetId.Value).Max + 1
- End If
-
- ' Give the new worksheet a name.
- Dim sheetName As String = ("Sheet" + sheetId.ToString())
-
- ' Append the new worksheet and associate it with the workbook.
- Dim sheet As Sheet = New Sheet
- sheet.Id = relationshipId
- sheet.SheetId = sheetId
- sheet.Name = sheetName
- sheets.Append(sheet)
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-insert-a-picture-into-a-word-processing-document.md b/docs/how-to-insert-a-picture-into-a-word-processing-document.md
index feb8e320..d8eeadd4 100644
--- a/docs/how-to-insert-a-picture-into-a-word-processing-document.md
+++ b/docs/how-to-insert-a-picture-into-a-word-processing-document.md
@@ -19,27 +19,7 @@ ms.localizationpriority: high
This topic shows how to use the classes in the Open XML SDK for Office to programmatically add a picture to a word processing document.
-The following assembly directives are required to compile the code in this topic.
-```csharp
- using System.IO;
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Wordprocessing;
- using A = DocumentFormat.OpenXml.Drawing;
- using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing;
- using PIC = DocumentFormat.OpenXml.Drawing.Pictures;
-```
-
-```vb
- Imports System.IO
- Imports DocumentFormat.OpenXml
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Wordprocessing
- Imports A = DocumentFormat.OpenXml.Drawing
- Imports DW = DocumentFormat.OpenXml.Drawing.Wordprocessing
- Imports PIC = DocumentFormat.OpenXml.Drawing.Pictures
-```
--------------------------------------------------------------------------------
@@ -275,137 +255,11 @@ inserted picture.
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void InsertAPicture(string document, string fileName)
- {
- using (WordprocessingDocument wordprocessingDocument =
- WordprocessingDocument.Open(document, true))
- {
- MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
-
- ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/insert_a_picture/cs/Program.cs)]
- using (FileStream stream = new FileStream(fileName, FileMode.Open))
- {
- imagePart.FeedData(stream);
- }
-
- AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));
- }
- }
-
- private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)
- {
- // Define the reference of the image.
- var element =
- new Drawing(
- new DW.Inline(
- new DW.Extent() { Cx = 990000L, Cy = 792000L },
- new DW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L,
- RightEdge = 0L, BottomEdge = 0L },
- new DW.DocProperties() { Id = (UInt32Value)1U,
- Name = "Picture 1" },
- new DW.NonVisualGraphicFrameDrawingProperties(
- new A.GraphicFrameLocks() { NoChangeAspect = true }),
- new A.Graphic(
- new A.GraphicData(
- new PIC.Picture(
- new PIC.NonVisualPictureProperties(
- new PIC.NonVisualDrawingProperties()
- { Id = (UInt32Value)0U,
- Name = "New Bitmap Image.jpg" },
- new PIC.NonVisualPictureDrawingProperties()),
- new PIC.BlipFill(
- new A.Blip(
- new A.BlipExtensionList(
- new A.BlipExtension()
- { Uri =
- "{28A0092B-C50C-407E-A947-70E740481C1C}" })
- )
- { Embed = relationshipId,
- CompressionState =
- A.BlipCompressionValues.Print },
- new A.Stretch(
- new A.FillRectangle())),
- new PIC.ShapeProperties(
- new A.Transform2D(
- new A.Offset() { X = 0L, Y = 0L },
- new A.Extents() { Cx = 990000L, Cy = 792000L }),
- new A.PresetGeometry(
- new A.AdjustValueList()
- ) { Preset = A.ShapeTypeValues.Rectangle }))
- ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
- ) { DistanceFromTop = (UInt32Value)0U,
- DistanceFromBottom = (UInt32Value)0U,
- DistanceFromLeft = (UInt32Value)0U,
- DistanceFromRight = (UInt32Value)0U, EditId = "50D07946" });
-
- // Append the reference to body, the element should be in a Run.
- wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));
- }
-```
-
-```vb
- Public Sub InsertAPicture(ByVal document As String, ByVal fileName As String)
- Using wordprocessingDocument As WordprocessingDocument = WordprocessingDocument.Open(document, True)
- Dim mainPart As MainDocumentPart = wordprocessingDocument.MainDocumentPart
-
- Dim imagePart As ImagePart = mainPart.AddImagePart(ImagePartType.Jpeg)
-
- Using stream As New FileStream(fileName, FileMode.Open)
- imagePart.FeedData(stream)
- End Using
-
- AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart))
- End Using
- End Sub
-
- Private Sub AddImageToBody(ByVal wordDoc As WordprocessingDocument, ByVal relationshipId As String)
- ' Define the reference of the image.
- Dim element = New Drawing( _
- New DW.Inline( _
- New DW.Extent() With {.Cx = 990000L, .Cy = 792000L}, _
- New DW.EffectExtent() With {.LeftEdge = 0L, .TopEdge = 0L, .RightEdge = 0L, .BottomEdge = 0L}, _
- New DW.DocProperties() With {.Id = CType(1UI, UInt32Value), .Name = "Picture1"}, _
- New DW.NonVisualGraphicFrameDrawingProperties( _
- New A.GraphicFrameLocks() With {.NoChangeAspect = True} _
- ), _
- New A.Graphic(New A.GraphicData( _
- New PIC.Picture( _
- New PIC.NonVisualPictureProperties( _
- New PIC.NonVisualDrawingProperties() With {.Id = 0UI, .Name = "Koala.jpg"}, _
- New PIC.NonVisualPictureDrawingProperties() _
- ), _
- New PIC.BlipFill( _
- New A.Blip( _
- New A.BlipExtensionList( _
- New A.BlipExtension() With {.Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"}) _
- ) With {.Embed = relationshipId, .CompressionState = A.BlipCompressionValues.Print}, _
- New A.Stretch( _
- New A.FillRectangle() _
- ) _
- ), _
- New PIC.ShapeProperties( _
- New A.Transform2D( _
- New A.Offset() With {.X = 0L, .Y = 0L}, _
- New A.Extents() With {.Cx = 990000L, .Cy = 792000L}), _
- New A.PresetGeometry( _
- New A.AdjustValueList() _
- ) With {.Preset = A.ShapeTypeValues.Rectangle} _
- ) _
- ) _
- ) With {.Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"} _
- ) _
- ) With {.DistanceFromTop = 0UI, _
- .DistanceFromBottom = 0UI, _
- .DistanceFromLeft = 0UI, _
- .DistanceFromRight = 0UI} _
- )
-
- ' Append the reference to body, the element should be in a Run.
- wordDoc.MainDocumentPart.Document.Body.AppendChild(New Paragraph(New Run(element)))
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/insert_a_picture/vb/Program.vb)]
--------------------------------------------------------------------------------
diff --git a/docs/how-to-insert-a-table-into-a-word-processing-document.md b/docs/how-to-insert-a-table-into-a-word-processing-document.md
index 7d2bcc87..938fafc5 100644
--- a/docs/how-to-insert-a-table-into-a-word-processing-document.md
+++ b/docs/how-to-insert-a-table-into-a-word-processing-document.md
@@ -20,20 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to programmatically insert a table into a word processing
document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Wordprocessing;
-```
-
-```vb
- Imports DocumentFormat.OpenXml
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Wordprocessing
-```
## Getting a WordprocessingDocument Object
@@ -279,121 +266,11 @@ inserted table.
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // Insert a table into a word processing document.
- public static void CreateTable(string fileName)
- {
- // Use the file name and path passed in as an argument
- // to open an existing Word 2007 document.
-
- using (WordprocessingDocument doc
- = WordprocessingDocument.Open(fileName, true))
- {
- // Create an empty table.
- Table table = new Table();
-
- // Create a TableProperties object and specify its border information.
- TableProperties tblProp = new TableProperties(
- new TableBorders(
- new TopBorder() { Val =
- new EnumValue(BorderValues.Dashed), Size = 24 },
- new BottomBorder() { Val =
- new EnumValue(BorderValues.Dashed), Size = 24 },
- new LeftBorder() { Val =
- new EnumValue(BorderValues.Dashed), Size = 24 },
- new RightBorder() { Val =
- new EnumValue(BorderValues.Dashed), Size = 24 },
- new InsideHorizontalBorder() { Val =
- new EnumValue(BorderValues.Dashed), Size = 24 },
- new InsideVerticalBorder() { Val =
- new EnumValue(BorderValues.Dashed), Size = 24 }
- )
- );
-
- // Append the TableProperties object to the empty table.
- table.AppendChild(tblProp);
-
- // Create a row.
- TableRow tr = new TableRow();
-
- // Create a cell.
- TableCell tc1 = new TableCell();
-
- // Specify the width property of the table cell.
- tc1.Append(new TableCellProperties(
- new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));
-
- // Specify the table cell content.
- tc1.Append(new Paragraph(new Run(new Text("some text"))));
-
- // Append the table cell to the table row.
- tr.Append(tc1);
-
- // Create a second table cell by copying the OuterXml value of the first table cell.
- TableCell tc2 = new TableCell(tc1.OuterXml);
-
- // Append the table cell to the table row.
- tr.Append(tc2);
-
- // Append the table row to the table.
- table.Append(tr);
-
- // Append the table to the document.
- doc.MainDocumentPart.Document.Body.Append(table);
- }
- }
-```
-
-```vb
- ' Insert a table into a word processing document.
- Public Sub CreateTable(ByVal fileName As String)
- ' Use the file name and path passed in as an argument
- ' to open an existing Word 2007 document.
-
- Using doc As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
- ' Create an empty table.
- Dim table As New Table()
-
- ' Create a TableProperties object and specify its border information.
- Dim tblProp As New TableProperties(New TableBorders( _
- New TopBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}, _
- New BottomBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}, _
- New LeftBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}, _
- New RightBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}, _
- New InsideHorizontalBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}, _
- New InsideVerticalBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}))
- ' Append the TableProperties object to the empty table.
- table.AppendChild(Of TableProperties)(tblProp)
-
- ' Create a row.
- Dim tr As New TableRow()
-
- ' Create a cell.
- Dim tc1 As New TableCell()
-
- ' Specify the width property of the table cell.
- tc1.Append(New TableCellProperties(New TableCellWidth()))
-
- ' Specify the table cell content.
- tc1.Append(New Paragraph(New Run(New Text("some text"))))
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/insert_a_table/cs/Program.cs)]
- ' Append the table cell to the table row.
- tr.Append(tc1)
-
- ' Create a second table cell by copying the OuterXml value of the first table cell.
- Dim tc2 As New TableCell(tc1.OuterXml)
-
- ' Append the table cell to the table row.
- tr.Append(tc2)
-
- ' Append the table row to the table.
- table.Append(tr)
-
- ' Append the table to the document.
- doc.MainDocumentPart.Document.Body.Append(table)
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/insert_a_table/vb/Program.vb)]
## See also
diff --git a/docs/how-to-merge-two-adjacent-cells-in-a-spreadsheet.md b/docs/how-to-merge-two-adjacent-cells-in-a-spreadsheet.md
index a91a2ca0..0f56e79d 100644
--- a/docs/how-to-merge-two-adjacent-cells-in-a-spreadsheet.md
+++ b/docs/how-to-merge-two-adjacent-cells-in-a-spreadsheet.md
@@ -20,28 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to merge two adjacent cells in a spreadsheet document
programmatically.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Spreadsheet;
- using System.Text.RegularExpressions;
-```
-
-```vb
- Imports System
- Imports System.Collections.Generic
- Imports System.Linq
- Imports DocumentFormat.OpenXml
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Spreadsheet
- Imports System.Text.RegularExpressions
-```
--------------------------------------------------------------------------------
## Getting a SpreadsheetDocument Object
@@ -147,146 +126,6 @@ the **workbook**, **sheets**, **sheet**, **worksheet**, and **sheetData** elemen
| v | DocumentFormat.OpenXml.Spreadsheet.CellValue | The value of a cell. |
---------------------------------------------------------------------------------
-## How the Sample Code Works
-
-After you have opened the spreadsheet file for editing, the code
-verifies that the specified cells exist, and if they do not exist, it
-creates them by calling the **CreateSpreadsheetCellIfNotExist** method and append
-it to the appropriate **[Row](https://msdn.microsoft.com/library/office/documentformat.openxml.spreadsheet.row.aspx)** object.
-
-```csharp
- // Given a Worksheet and a cell name, verifies that the specified cell exists.
- // If it does not exist, creates a new cell.
- private static void CreateSpreadsheetCellIfNotExist(Worksheet worksheet, string cellName)
- {
- string columnName = GetColumnName(cellName);
- uint rowIndex = GetRowIndex(cellName);
-
- IEnumerable rows = worksheet.Descendants().Where(r => r.RowIndex.Value == rowIndex);
-
- // If the Worksheet does not contain the specified row, create the specified row.
- // Create the specified cell in that row, and insert the row into the Worksheet.
- if (rows.Count() == 0)
- {
- Row row = new Row() { RowIndex = new UInt32Value(rowIndex) };
- Cell cell = new Cell() { CellReference = new StringValue(cellName) };
- row.Append(cell);
- worksheet.Descendants().First().Append(row);
- worksheet.Save();
- }
- else
- {
- Row row = rows.First();
-
- IEnumerable cells = row.Elements().Where(c => c.CellReference.Value == cellName);
-
- // If the row does not contain the specified cell, create the specified cell.
- if (cells.Count() == 0)
- {
- Cell cell = new Cell() { CellReference = new StringValue(cellName) };
- row.Append(cell);
- worksheet.Save();
- }
- }
- }
-```
-
-```vb
- ' Given a Worksheet and a cell name, verifies that the specified cell exists.
- ' If it does not exist, creates a new cell.
- Private Sub CreateSpreadsheetCellIfNotExist(ByVal worksheet As Worksheet, ByVal cellName As String)
- Dim columnName As String = GetColumnName(cellName)
- Dim rowIndex As UInteger = GetRowIndex(cellName)
-
- Dim rows As IEnumerable(Of Row) = worksheet.Descendants(Of Row)().Where(Function(r) r.RowIndex.Value = rowIndex.ToString())
-
- ' If the worksheet does not contain the specified row, create the specified row.
- ' Create the specified cell in that row, and insert the row into the worksheet.
- If (rows.Count = 0) Then
- Dim row As Row = New Row()
- row.RowIndex = New UInt32Value(rowIndex)
-
- Dim cell As Cell = New Cell()
- cell.CellReference = New StringValue(cellName)
-
- row.Append(cell)
- worksheet.Descendants(Of SheetData)().First().Append(row)
- worksheet.Save()
- Else
- Dim row As Row = rows.First()
- Dim cells As IEnumerable(Of Cell) = row.Elements(Of Cell)().Where(Function(c) c.CellReference.Value = cellName)
-
- ' If the row does not contain the specified cell, create the specified cell.
- If (cells.Count = 0) Then
- Dim cell As Cell = New Cell
- cell.CellReference = New StringValue(cellName)
-
- row.Append(cell)
- worksheet.Save()
- End If
- End If
- End Sub
-```
-
-In order to get a column name, the code creates a new regular expression
-to match the column name portion of the cell name. This regular
-expression matches any combination of uppercase or lowercase letters.
-For more information about regular expressions, see [Regular Expression
-Language
-Elements](https://msdn.microsoft.com/library/az24scfc.aspx). The
-code gets the column name by calling the [Regex.Match](https://msdn2.microsoft.com/library/3zy662f6).
-
-```csharp
- // Given a cell name, parses the specified cell to get the column name.
- private static string GetColumnName(string cellName)
- {
- // Create a regular expression to match the column name portion of the cell name.
- Regex regex = new Regex("[A-Za-z]+");
- Match match = regex.Match(cellName);
-
- return match.Value;
- }
-```
-
-```vb
- ' Given a cell name, parses the specified cell to get the column name.
- Private Function GetColumnName(ByVal cellName As String) As String
- ' Create a regular expression to match the column name portion of the cell name.
- Dim regex As Regex = New Regex("[A-Za-z]+")
- Dim match As Match = regex.Match(cellName)
- Return match.Value
- End Function
-```
-
-To get the row index, the code creates a new regular expression to match
-the row index portion of the cell name. This regular expression matches
-any combination of decimal digits. The following code creates a regular
-expression to match the row index portion of the cell name, comprised of
-decimal digits.
-
-```csharp
- // Given a cell name, parses the specified cell to get the row index.
- private static uint GetRowIndex(string cellName)
- {
- // Create a regular expression to match the row index portion the cell name.
- Regex regex = new Regex(@"\d+");
- Match match = regex.Match(cellName);
-
- return uint.Parse(match.Value);
- }
-```
-
-```vb
- ' Given a cell name, parses the specified cell to get the row index.
- Private Function GetRowIndex(ByVal cellName As String) As UInteger
- ' Create a regular expression to match the row index portion the cell name.
- Dim regex As Regex = New Regex("\d+")
- Dim match As Match = regex.Match(cellName)
- Return UInteger.Parse(match.Value)
- End Function
-```
-
--------------------------------------------------------------------------------
## Sample Code
@@ -316,264 +155,11 @@ named "Jane," in a file named "Sheet9.xlsx."
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // Given a document name, a worksheet name, and the names of two adjacent cells, merges the two cells.
- // When two cells are merged, only the content from one cell is preserved:
- // the upper-left cell for left-to-right languages or the upper-right cell for right-to-left languages.
- private static void MergeTwoCells(string docName, string sheetName, string cell1Name, string cell2Name)
- {
- // Open the document for editing.
- using (SpreadsheetDocument document = SpreadsheetDocument.Open(docName, true))
- {
- Worksheet worksheet = GetWorksheet(document, sheetName);
- if (worksheet == null || string.IsNullOrEmpty(cell1Name) || string.IsNullOrEmpty(cell2Name))
- {
- return;
- }
-
- // Verify if the specified cells exist, and if they do not exist, create them.
- CreateSpreadsheetCellIfNotExist(worksheet, cell1Name);
- CreateSpreadsheetCellIfNotExist(worksheet, cell2Name);
-
- MergeCells mergeCells;
- if (worksheet.Elements().Count() > 0)
- {
- mergeCells = worksheet.Elements().First();
- }
- else
- {
- mergeCells = new MergeCells();
-
- // Insert a MergeCells object into the specified position.
- if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else if (worksheet.Elements().Count() > 0)
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- else
- {
- worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
- }
- }
-
- // Create the merged cell and append it to the MergeCells collection.
- MergeCell mergeCell = new MergeCell() { Reference = new StringValue(cell1Name + ":" + cell2Name) };
- mergeCells.Append(mergeCell);
-
- worksheet.Save();
- }
- }
- // Given a Worksheet and a cell name, verifies that the specified cell exists.
- // If it does not exist, creates a new cell.
- private static void CreateSpreadsheetCellIfNotExist(Worksheet worksheet, string cellName)
- {
- string columnName = GetColumnName(cellName);
- uint rowIndex = GetRowIndex(cellName);
-
- IEnumerable rows = worksheet.Descendants().Where(r => r.RowIndex.Value == rowIndex);
-
- // If the Worksheet does not contain the specified row, create the specified row.
- // Create the specified cell in that row, and insert the row into the Worksheet.
- if (rows.Count() == 0)
- {
- Row row = new Row() { RowIndex = new UInt32Value(rowIndex) };
- Cell cell = new Cell() { CellReference = new StringValue(cellName) };
- row.Append(cell);
- worksheet.Descendants().First().Append(row);
- worksheet.Save();
- }
- else
- {
- Row row = rows.First();
-
- IEnumerable cells = row.Elements().Where(c => c.CellReference.Value == cellName);
-
- // If the row does not contain the specified cell, create the specified cell.
- if (cells.Count() == 0)
- {
- Cell cell = new Cell() { CellReference = new StringValue(cellName) };
- row.Append(cell);
- worksheet.Save();
- }
- }
- }
-
- // Given a SpreadsheetDocument and a worksheet name, get the specified worksheet.
- private static Worksheet GetWorksheet(SpreadsheetDocument document, string worksheetName)
- {
- IEnumerable sheets = document.WorkbookPart.Workbook.Descendants().Where(s => s.Name == worksheetName);
- WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.First().Id);
- if (sheets.Count() == 0)
- return null;
- else
- return worksheetPart.Worksheet;
- }
-
- // Given a cell name, parses the specified cell to get the column name.
- private static string GetColumnName(string cellName)
- {
- // Create a regular expression to match the column name portion of the cell name.
- Regex regex = new Regex("[A-Za-z]+");
- Match match = regex.Match(cellName);
-
- return match.Value;
- }
- // Given a cell name, parses the specified cell to get the row index.
- private static uint GetRowIndex(string cellName)
- {
- // Create a regular expression to match the row index portion the cell name.
- Regex regex = new Regex(@"\d+");
- Match match = regex.Match(cellName);
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs)]
- return uint.Parse(match.Value);
- }
-```
-
-```vb
- ' Given a document name, a worksheet name, and the names of two adjacent cells, merges the two cells.
- ' When two cells are merged, only the content from one cell is preserved:
- ' the upper-left cell for left-to-right languages or the upper-right cell for right-to-left languages.
- Private Sub MergeTwoCells(ByVal docName As String, ByVal sheetName As String, ByVal cell1Name As String, ByVal cell2Name As String)
- ' Open the document for editing.
- Dim document As SpreadsheetDocument = SpreadsheetDocument.Open(docName, True)
-
- Using (document)
- Dim worksheet As Worksheet = GetWorksheet(document, sheetName)
- If ((worksheet Is Nothing) OrElse (String.IsNullOrEmpty(cell1Name) OrElse String.IsNullOrEmpty(cell2Name))) Then
- Return
- End If
-
- ' Verify if the specified cells exist, and if they do not exist, create them.
- CreateSpreadsheetCellIfNotExist(worksheet, cell1Name)
- CreateSpreadsheetCellIfNotExist(worksheet, cell2Name)
-
- Dim mergeCells As MergeCells
- If (worksheet.Elements(Of MergeCells)().Count() > 0) Then
- mergeCells = worksheet.Elements(Of MergeCells).First()
- Else
- mergeCells = New MergeCells()
-
- ' Insert a MergeCells object into the specified position.
- If (worksheet.Elements(Of CustomSheetView)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of CustomSheetView)().First())
- ElseIf (worksheet.Elements(Of DataConsolidate)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of DataConsolidate)().First())
- ElseIf (worksheet.Elements(Of SortState)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SortState)().First())
- ElseIf (worksheet.Elements(Of AutoFilter)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of AutoFilter)().First())
- ElseIf (worksheet.Elements(Of Scenarios)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of Scenarios)().First())
- ElseIf (worksheet.Elements(Of ProtectedRanges)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of ProtectedRanges)().First())
- ElseIf (worksheet.Elements(Of SheetProtection)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SheetProtection)().First())
- ElseIf (worksheet.Elements(Of SheetCalculationProperties)().Count() > 0) Then
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SheetCalculationProperties)().First())
- Else
- worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SheetData)().First())
- End If
- End If
-
- ' Create the merged cell and append it to the MergeCells collection.
- Dim mergeCell As MergeCell = New MergeCell()
- mergeCell.Reference = New StringValue((cell1Name + (":" + cell2Name)))
- mergeCells.Append(mergeCell)
-
- worksheet.Save()
- End Using
- End Sub
-
- ' Given a SpreadsheetDocument and a worksheet name, get the specified worksheet.
- Private Function GetWorksheet(ByVal document As SpreadsheetDocument, ByVal worksheetName As String) As Worksheet
- Dim sheets As IEnumerable(Of Sheet) = document.WorkbookPart.Workbook.Descendants(Of Sheet)().Where(Function(s) s.Name = worksheetName)
- If (sheets.Count = 0) Then
- ' The specified worksheet does not exist.
- Return Nothing
- End If
- Dim worksheetPart As WorksheetPart = CType(document.WorkbookPart.GetPartById(sheets.First.Id), WorksheetPart)
-
- Return worksheetPart.Worksheet
- End Function
-
- ' Given a Worksheet and a cell name, verifies that the specified cell exists.
- ' If it does not exist, creates a new cell.
- Private Sub CreateSpreadsheetCellIfNotExist(ByVal worksheet As Worksheet, ByVal cellName As String)
- Dim columnName As String = GetColumnName(cellName)
- Dim rowIndex As UInteger = GetRowIndex(cellName)
-
- Dim rows As IEnumerable(Of Row) = worksheet.Descendants(Of Row)().Where(Function(r) r.RowIndex.Value = rowIndex.ToString())
-
- ' If the worksheet does not contain the specified row, create the specified row.
- ' Create the specified cell in that row, and insert the row into the worksheet.
- If (rows.Count = 0) Then
- Dim row As Row = New Row()
- row.RowIndex = New UInt32Value(rowIndex)
-
- Dim cell As Cell = New Cell()
- cell.CellReference = New StringValue(cellName)
-
- row.Append(cell)
- worksheet.Descendants(Of SheetData)().First().Append(row)
- worksheet.Save()
- Else
- Dim row As Row = rows.First()
- Dim cells As IEnumerable(Of Cell) = row.Elements(Of Cell)().Where(Function(c) c.CellReference.Value = cellName)
-
- ' If the row does not contain the specified cell, create the specified cell.
- If (cells.Count = 0) Then
- Dim cell As Cell = New Cell
- cell.CellReference = New StringValue(cellName)
-
- row.Append(cell)
- worksheet.Save()
- End If
- End If
- End Sub
-
- ' Given a cell name, parses the specified cell to get the column name.
- Private Function GetColumnName(ByVal cellName As String) As String
- ' Create a regular expression to match the column name portion of the cell name.
- Dim regex As Regex = New Regex("[A-Za-z]+")
- Dim match As Match = regex.Match(cellName)
- Return match.Value
- End Function
-
- ' Given a cell name, parses the specified cell to get the row index.
- Private Function GetRowIndex(ByVal cellName As String) As UInteger
- ' Create a regular expression to match the row index portion the cell name.
- Dim regex As Regex = New Regex("\d+")
- Dim match As Match = regex.Match(cellName)
- Return UInteger.Parse(match.Value)
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/merge_two_adjacent_cells/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-open-a-spreadsheet-document-for-read-only-access.md b/docs/how-to-open-a-spreadsheet-document-for-read-only-access.md
index 3afe7e62..d9091131 100644
--- a/docs/how-to-open-a-spreadsheet-document-for-read-only-access.md
+++ b/docs/how-to-open-a-spreadsheet-document-for-read-only-access.md
@@ -20,22 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to open a spreadsheet document for read-only access
programmatically.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.IO;
- using System.IO.Packaging;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Spreadsheet;
-```
-
-```vb
- Imports System.IO
- Imports System.IO.Packaging
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Spreadsheet
-```
---------------------------------------------------------------------------------
## When to Open a Document for Read-Only Access
@@ -217,44 +202,6 @@ row|DocumentFormat.OpenXml.Spreadsheet.Row|A row in the cell table.
c|DocumentFormat.OpenXml.Spreadsheet.Cell|A cell in a row.
v|DocumentFormat.OpenXml.Spreadsheet.CellValue|The value of a cell.
-
---------------------------------------------------------------------------------
-## Attempt to Generate the SpreadsheetML Markup to Add a Worksheet
-The sample code shows how, when you try to add a new worksheet, you get
-an exception error because the file is read-only. When you have access
-to the body of the main document part, you add a worksheet by calling
-the [AddNewPart\(String, String)](https://msdn.microsoft.com/library/office/cc562372.aspx) method to
-create a new [WorksheetPart](https://msdn.microsoft.com/library/office/documentformat.openxml.spreadsheet.worksheet.worksheetpart.aspx). The following code example
-attempts to add the new **WorksheetPart**.
-
-```csharp
- public static void OpenSpreadsheetDocumentReadonly(string filepath)
- {
- // Open a SpreadsheetDocument based on a filepath.
- using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filepath, false))
- {
- // Attempt to add a new WorksheetPart.
- // The call to AddNewPart generates an exception because the file is read-only.
- WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
-
- // The rest of the code will not be called.
- }
- }
-```
-
-```vb
- Public Shared Sub OpenSpreadsheetDocumentReadonly(ByVal filepath As String)
- ' Open a SpreadsheetDocument based on a filepath.
- Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(filepath, False)
- ' Attempt to add a new WorksheetPart.
- ' The call to AddNewPart generates an exception because the file is read-only.
- Dim newWorksheetPart As WorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
-
- ' The rest of the code will not be called.
- End Using
- End Sub
-```
-
--------------------------------------------------------------------------------
## Sample Code
The following code sample is used to open a Spreadsheet Document for
@@ -270,33 +217,11 @@ the following code, which opens the file "Sheet10.xlsx," as an example.
```
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void OpenSpreadsheetDocumentReadonly(string filepath)
- {
- // Open a SpreadsheetDocument based on a filepath.
- using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filepath, false))
- {
- // Attempt to add a new WorksheetPart.
- // The call to AddNewPart generates an exception because the file is read-only.
- WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
-
- // The rest of the code will not be called.
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/open_for_read_only_access/cs/Program.cs)]
-```vb
- Public Sub OpenSpreadsheetDocumentReadonly(ByVal filepath As String)
- ' Open a SpreadsheetDocument based on a filepath.
- Using spreadsheetDocument As SpreadsheetDocument = spreadsheetDocument.Open(filepath, False)
- ' Attempt to add a new WorksheetPart.
- ' The call to AddNewPart generates an exception because the file is read-only.
- Dim newWorksheetPart As WorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
-
- ' The rest of the code will not be called.
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/open_for_read_only_access/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-open-a-spreadsheet-document-from-a-stream.md b/docs/how-to-open-a-spreadsheet-document-from-a-stream.md
index 62fc4c58..d041c4a3 100644
--- a/docs/how-to-open-a-spreadsheet-document-from-a-stream.md
+++ b/docs/how-to-open-a-spreadsheet-document-from-a-stream.md
@@ -19,22 +19,7 @@ ms.localizationpriority: high
This topic shows how to use the classes in the Open XML SDK for
Office to open a spreadsheet document from a stream programmatically.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.IO;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Spreadsheet;
- using System.Linq;
-```
-
-```vb
- Imports System.IO
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Spreadsheet
- Imports System.Linq
-```
---------------------------------------------------------------------------------
## When to Open From a Stream
@@ -202,79 +187,11 @@ close the stream passed to it. The calling code must do that.
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void OpenAndAddToSpreadsheetStream(Stream stream)
- {
- // Open a SpreadsheetDocument based on a stream.
- SpreadsheetDocument spreadsheetDocument =
- SpreadsheetDocument.Open(stream, true);
-
- // Add a new worksheet.
- WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
- newWorksheetPart.Worksheet = new Worksheet(new SheetData());
- newWorksheetPart.Worksheet.Save();
-
- Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.GetFirstChild();
- string relationshipId = spreadsheetDocument.WorkbookPart.GetIdOfPart(newWorksheetPart);
-
- // Get a unique ID for the new worksheet.
- uint sheetId = 1;
- if (sheets.Elements().Count() > 0)
- {
- sheetId = sheets.Elements().Select(s => s.SheetId.Value).Max() + 1;
- }
-
- // Give the new worksheet a name.
- string sheetName = "Sheet" + sheetId;
-
- // Append the new worksheet and associate it with the workbook.
- Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
- sheets.Append(sheet);
- spreadsheetDocument.WorkbookPart.Workbook.Save();
-
- // Close the document handle.
- spreadsheetDocument.Close();
-
- // Caller must close the stream.
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/open_from_a_stream/cs/Program.cs)]
-```vb
- Public Sub OpenAndAddToSpreadsheetStream(ByVal stream As Stream)
- ' Open a SpreadsheetDocument based on a stream.
- Dim mySpreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(stream, True)
-
- ' Add a new worksheet.
- Dim newWorksheetPart As WorksheetPart = mySpreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
- newWorksheetPart.Worksheet = New Worksheet(New SheetData())
- newWorksheetPart.Worksheet.Save()
-
- Dim sheets As Sheets = mySpreadsheetDocument.WorkbookPart.Workbook.GetFirstChild(Of Sheets)()
- Dim relationshipId As String = mySpreadsheetDocument.WorkbookPart.GetIdOfPart(newWorksheetPart)
-
- ' Get a unique ID for the new worksheet.
- Dim sheetId As UInteger = 1
- If (sheets.Elements(Of Sheet).Count > 0) Then
- sheetId = sheets.Elements(Of Sheet).Select(Function(s) s.SheetId.Value).Max + 1
- End If
-
- ' Give the new worksheet a name.
- Dim sheetName As String = ("Sheet" + sheetId.ToString())
-
- ' Append the new worksheet and associate it with the workbook.
- Dim sheet As Sheet = New Sheet
- sheet.Id = relationshipId
- sheet.SheetId = sheetId
- sheet.Name = sheetName
- sheets.Append(sheet)
- mySpreadsheetDocument.WorkbookPart.Workbook.Save()
-
- 'Close the document handle.
- mySpreadsheetDocument.Close()
-
- 'Caller must close the stream.
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/open_from_a_stream/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-parse-and-read-a-large-spreadsheet.md b/docs/how-to-parse-and-read-a-large-spreadsheet.md
index d060b582..82400019 100644
--- a/docs/how-to-parse-and-read-a-large-spreadsheet.md
+++ b/docs/how-to-parse-and-read-a-large-spreadsheet.md
@@ -183,96 +183,11 @@ exclude.
The following is the complete code sample in both C\# and Visual Basic.
-```csharp
- // The DOM approach.
- // Note that the code below works only for cells that contain numeric values.
- //
- static void ReadExcelFileDOM(string fileName)
- {
- using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
- {
- WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
- WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
- SheetData sheetData = worksheetPart.Worksheet.Elements().First();
- string text;
- foreach (Row r in sheetData.Elements())
- {
- foreach (Cell c in r.Elements())
- {
- text = c.CellValue.Text;
- Console.Write(text + " ");
- }
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs)]
- // The SAX approach.
- static void ReadExcelFileSAX(string fileName)
- {
- using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
- {
- WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
- WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
-
- OpenXmlReader reader = OpenXmlReader.Create(worksheetPart);
- string text;
- while (reader.Read())
- {
- if (reader.ElementType == typeof(CellValue))
- {
- text = reader.GetText();
- Console.Write(text + " ");
- }
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
-```
-
-```vb
- ' The DOM approach.
- ' Note that the this code works only for cells that contain numeric values.
-
-
- Private Sub ReadExcelFileDOM(ByVal fileName As String)
- Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
- Dim workbookPart As WorkbookPart = spreadsheetDocument.WorkbookPart
- Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
- Dim sheetData As SheetData = worksheetPart.Worksheet.Elements(Of SheetData)().First()
- Dim text As String
- For Each r As Row In sheetData.Elements(Of Row)()
- For Each c As Cell In r.Elements(Of Cell)()
- text = c.CellValue.Text
- Console.Write(text & " ")
- Next
- Next
- Console.WriteLine()
- Console.ReadKey()
- End Using
- End Sub
-
- ' The SAX approach.
- Private Sub ReadExcelFileSAX(ByVal fileName As String)
- Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
- Dim workbookPart As WorkbookPart = spreadsheetDocument.WorkbookPart
- Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
-
- Dim reader As OpenXmlReader = OpenXmlReader.Create(worksheetPart)
- Dim text As String
- While reader.Read()
- If reader.ElementType = GetType(CellValue) Then
- text = reader.GetText()
- Console.Write(text & " ")
- End If
- End While
- Console.WriteLine()
- Console.ReadKey()
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-remove-hidden-text-from-a-word-processing-document.md b/docs/how-to-remove-hidden-text-from-a-word-processing-document.md
index 736872e7..0e430f7c 100644
--- a/docs/how-to-remove-hidden-text-from-a-word-processing-document.md
+++ b/docs/how-to-remove-hidden-text-from-a-word-processing-document.md
@@ -20,20 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to programmatically remove hidden text from a word processing
document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.IO;
- using DocumentFormat.OpenXml.Packaging;
- using System.Xml;
-```
-
-```vb
- Imports System.IO
- Imports DocumentFormat.OpenXml.Packaging
- Imports System.Xml
-```
---------------------------------------------------------------------------------
## Getting a WordprocessingDocument Object
@@ -192,71 +179,11 @@ named "Word14.docx."
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void WDDeleteHiddenText(string docName)
- {
- // Given a document name, delete all the hidden text.
- const string wordmlNamespace = "https://schemas.openxmlformats.org/wordprocessingml/2006/main";
-
- using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(docName, true))
- {
- // Manage namespaces to perform XPath queries.
- NameTable nt = new NameTable();
- XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
- nsManager.AddNamespace("w", wordmlNamespace);
-
- // Get the document part from the package.
- // Load the XML in the document part into an XmlDocument instance.
- XmlDocument xdoc = new XmlDocument(nt);
- xdoc.Load(wdDoc.MainDocumentPart.GetStream());
- XmlNodeList hiddenNodes = xdoc.SelectNodes("//w:vanish", nsManager);
- foreach (System.Xml.XmlNode hiddenNode in hiddenNodes)
- {
- XmlNode topNode = hiddenNode.ParentNode.ParentNode;
- XmlNode topParentNode = topNode.ParentNode;
- topParentNode.RemoveChild(topNode);
- if (!(topParentNode.HasChildNodes))
- {
- topParentNode.ParentNode.RemoveChild(topParentNode);
- }
- }
-
- // Save the document XML back to its document part.
- xdoc.Save(wdDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write));
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/remove_hidden_text/cs/Program.cs)]
-```vb
- Public Sub WDDeleteHiddenText(ByVal docName As String)
- ' Given a document name, delete all the hidden text.
- Const wordmlNamespace As String = "https://schemas.openxmlformats.org/wordprocessingml/2006/main"
-
- Using wdDoc As WordprocessingDocument = WordprocessingDocument.Open(docName, True)
- ' Manage namespaces to perform XPath queries.
- Dim nt As New NameTable()
- Dim nsManager As New XmlNamespaceManager(nt)
- nsManager.AddNamespace("w", wordmlNamespace)
-
- ' Get the document part from the package.
- ' Load the XML in the document part into an XmlDocument instance.
- Dim xdoc As New XmlDocument(nt)
- xdoc.Load(wdDoc.MainDocumentPart.GetStream())
- Dim hiddenNodes As XmlNodeList = xdoc.SelectNodes("//w:vanish", nsManager)
- For Each hiddenNode As System.Xml.XmlNode In hiddenNodes
- Dim topNode As XmlNode = hiddenNode.ParentNode.ParentNode
- Dim topParentNode As XmlNode = topNode.ParentNode
- topParentNode.RemoveChild(topNode)
- If Not (topParentNode.HasChildNodes) Then
- topParentNode.ParentNode.RemoveChild(topParentNode)
- End If
- Next
-
- ' Save the document XML back to its document part.
- xdoc.Save(wdDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write))
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/remove_hidden_text/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-remove-the-headers-and-footers-from-a-word-processing-document.md b/docs/how-to-remove-the-headers-and-footers-from-a-word-processing-document.md
index 17979a39..cf40e7ed 100644
--- a/docs/how-to-remove-the-headers-and-footers-from-a-word-processing-document.md
+++ b/docs/how-to-remove-the-headers-and-footers-from-a-word-processing-document.md
@@ -259,110 +259,11 @@ the operation with the footer elements.
The following is the complete **RemoveHeadersAndFooters** code sample in C\# and
Visual Basic.
-```csharp
- // Remove all of the headers and footers from a document.
- public static void RemoveHeadersAndFooters(string filename)
- {
- // Given a document name, remove all of the headers and footers
- // from the document.
- using (WordprocessingDocument doc =
- WordprocessingDocument.Open(filename, true))
- {
- // Get a reference to the main document part.
- var docPart = doc.MainDocumentPart;
-
- // Count the header and footer parts and continue if there
- // are any.
- if (docPart.HeaderParts.Count() > 0 ||
- docPart.FooterParts.Count() > 0)
- {
- // Remove the header and footer parts.
- docPart.DeleteParts(docPart.HeaderParts);
- docPart.DeleteParts(docPart.FooterParts);
-
- // Get a reference to the root element of the main
- // document part.
- Document document = docPart.Document;
-
- // Remove all references to the headers and footers.
-
- // First, create a list of all descendants of type
- // HeaderReference. Then, navigate the list and call
- // Remove on each item to delete the reference.
- var headers =
- document.Descendants().ToList();
- foreach (var header in headers)
- {
- header.Remove();
- }
-
- // First, create a list of all descendants of type
- // FooterReference. Then, navigate the list and call
- // Remove on each item to delete the reference.
- var footers =
- document.Descendants().ToList();
- foreach (var footer in footers)
- {
- footer.Remove();
- }
-
- // Save the changes.
- document.Save();
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/remove_the_headers_and_footers/cs/Program.cs)]
-```vb
- ' To remove all of the headers and footers in a document.
- Public Sub RemoveHeadersAndFooters(ByVal filename As String)
-
- ' Given a document name, remove all of the headers and footers
- ' from the document.
- Using doc = WordprocessingDocument.Open(filename, True)
-
- ' Get a reference to the main document part.
- Dim docPart = doc.MainDocumentPart
-
- ' Count the header and footer parts and continue if there
- ' are any.
- If (docPart.HeaderParts.Count > 0) Or
- (docPart.FooterParts.Count > 0) Then
-
- ' Remove the header and footer parts.
- docPart.DeleteParts(docPart.HeaderParts)
- docPart.DeleteParts(docPart.FooterParts)
-
- ' Get a reference to the root element of the main
- ' document part.
- Dim document As Document = docPart.Document
-
- ' Remove all references to the headers and footers.
-
- ' First, create a list of all descendants of type
- ' HeaderReference. Then, navigate the list and call
- ' Remove on each item to delete the reference.
- Dim headers = _
- document.Descendants(Of HeaderReference).ToList()
- For Each header In headers
- header.Remove()
- Next
-
- ' First, create a list of all descendants of type
- ' FooterReference. Then, navigate the list and call
- ' Remove on each item to delete the reference.
- Dim footers = _
- document.Descendants(Of FooterReference).ToList()
- For Each footer In footers
- footer.Remove()
- Next
-
- ' Save the changes.
- document.Save()
- End If
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/remove_the_headers_and_footers/vb/Program.vb)]
## See also
diff --git a/docs/how-to-replace-the-header-in-a-word-processing-document.md b/docs/how-to-replace-the-header-in-a-word-processing-document.md
index 7bb72890..a81ab085 100644
--- a/docs/how-to-replace-the-header-in-a-word-processing-document.md
+++ b/docs/how-to-replace-the-header-in-a-word-processing-document.md
@@ -150,93 +150,11 @@ segment as an example.
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void AddHeaderFromTo(string filepathFrom, string filepathTo)
- {
- // Replace header in target document with header of source document.
- using (WordprocessingDocument
- wdDoc = WordprocessingDocument.Open(filepathTo, true))
- {
- MainDocumentPart mainPart = wdDoc.MainDocumentPart;
-
- // Delete the existing header part.
- mainPart.DeleteParts(mainPart.HeaderParts);
-
- // Create a new header part.
- DocumentFormat.OpenXml.Packaging.HeaderPart headerPart =
- mainPart.AddNewPart();
-
- // Get Id of the headerPart.
- string rId = mainPart.GetIdOfPart(headerPart);
-
- // Feed target headerPart with source headerPart.
- using (WordprocessingDocument wdDocSource =
- WordprocessingDocument.Open(filepathFrom, true))
- {
- DocumentFormat.OpenXml.Packaging.HeaderPart firstHeader =
- wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault();
-
- wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault();
-
- if (firstHeader != null)
- {
- headerPart.FeedData(firstHeader.GetStream());
- }
- }
-
- // Get SectionProperties and Replace HeaderReference with new Id.
- IEnumerable sectPrs =
- mainPart.Document.Body.Elements();
- foreach (var sectPr in sectPrs)
- {
- // Delete existing references to headers.
- sectPr.RemoveAllChildren();
-
- // Create the new header reference node.
- sectPr.PrependChild(new HeaderReference() { Id = rId });
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/replace_the_header/cs/Program.cs)]
-```vb
- Public Sub AddHeaderFromTo(ByVal filepathFrom As String, ByVal filepathTo As String)
- ' Replace header in target document with header of source document.
- Using wdDoc As WordprocessingDocument = _
- WordprocessingDocument.Open(filepathTo, True)
- Dim mainPart As MainDocumentPart = wdDoc.MainDocumentPart
-
- ' Delete the existing header part.
- mainPart.DeleteParts(mainPart.HeaderParts)
-
- ' Create a new header part.
- Dim headerPart = mainPart.AddNewPart(Of HeaderPart)()
-
- ' Get Id of the headerPart.
- Dim rId As String = mainPart.GetIdOfPart(headerPart)
-
- ' Feed target headerPart with source headerPart.
- Using wdDocSource As WordprocessingDocument = _
- WordprocessingDocument.Open(filepathFrom, True)
- Dim firstHeader = wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault()
-
- If firstHeader IsNot Nothing Then
- headerPart.FeedData(firstHeader.GetStream())
- End If
- End Using
-
- ' Get SectionProperties and Replace HeaderReference with new Id.
- Dim sectPrs = mainPart.Document.Body.Elements(Of SectionProperties)()
- For Each sectPr In sectPrs
- ' Delete existing references to headers.
- sectPr.RemoveAllChildren(Of HeaderReference)()
-
- ' Create the new header reference node.
- sectPr.PrependChild(Of HeaderReference)(New HeaderReference() With { .Id = rId })
- Next
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/replace_the_header/vb/Program.vb)]
## See also
diff --git a/docs/how-to-replace-the-styles-parts-in-a-word-processing-document.md b/docs/how-to-replace-the-styles-parts-in-a-word-processing-document.md
index 179d641e..9b7995b5 100644
--- a/docs/how-to-replace-the-styles-parts-in-a-word-processing-document.md
+++ b/docs/how-to-replace-the-styles-parts-in-a-word-processing-document.md
@@ -318,181 +318,11 @@ the XDocument, saving its contents into the styles part.
The following is the complete **ReplaceStyles**, **ReplaceStylesPart**, and **ExtractStylesPart** methods in C\# and Visual
Basic.
-```csharp
- // Replace the styles in the "to" document with the styles in
- // the "from" document.
- public static void ReplaceStyles(string fromDoc, string toDoc)
- {
- // Extract and replace the styles part.
- var node = ExtractStylesPart(fromDoc, false);
- if (node != null)
- ReplaceStylesPart(toDoc, node, false);
-
- // Extract and replace the stylesWithEffects part. To fully support
- // round-tripping from Word 2010 to Word 2007, you should
- // replace this part, as well.
- node = ExtractStylesPart(fromDoc);
- if (node != null)
- ReplaceStylesPart(toDoc, node);
- return;
- }
-
- // Given a file and an XDocument instance that contains the content of
- // a styles or stylesWithEffects part, replace the styles in the file
- // with the styles in the XDocument.
- public static void ReplaceStylesPart(string fileName, XDocument newStyles,
- bool setStylesWithEffectsPart = true)
- {
- // Open the document for write access and get a reference.
- using (var document =
- WordprocessingDocument.Open(fileName, true))
- {
- // Get a reference to the main document part.
- var docPart = document.MainDocumentPart;
-
- // Assign a reference to the appropriate part to the
- // stylesPart variable.
- StylesPart stylesPart = null;
- if (setStylesWithEffectsPart)
- stylesPart = docPart.StylesWithEffectsPart;
- else
- stylesPart = docPart.StyleDefinitionsPart;
-
- // If the part exists, populate it with the new styles.
- if (stylesPart != null)
- {
- newStyles.Save(new StreamWriter(stylesPart.GetStream(
- FileMode.Create, FileAccess.Write)));
- }
- }
- }
-
- // Extract the styles or stylesWithEffects part from a
- // word processing document as an XDocument instance.
- public static XDocument ExtractStylesPart(
- string fileName,
- bool getStylesWithEffectsPart = true)
- {
- // Declare a variable to hold the XDocument.
- XDocument styles = null;
-
- // Open the document for read access and get a reference.
- using (var document =
- WordprocessingDocument.Open(fileName, false))
- {
- // Get a reference to the main document part.
- var docPart = document.MainDocumentPart;
-
- // Assign a reference to the appropriate part to the
- // stylesPart variable.
- StylesPart stylesPart = null;
- if (getStylesWithEffectsPart)
- stylesPart = docPart.StylesWithEffectsPart;
- else
- stylesPart = docPart.StyleDefinitionsPart;
-
- // If the part exists, read it into the XDocument.
- if (stylesPart != null)
- {
- using (var reader = XmlNodeReader.Create(
- stylesPart.GetStream(FileMode.Open, FileAccess.Read)))
- {
- // Create the XDocument.
- styles = XDocument.Load(reader);
- }
- }
- }
- // Return the XDocument instance.
- return styles;
- }
-```
-
-```vb
- ' Replace the styles in the "to" document with the styles
- ' in the "from" document.
- Public Sub ReplaceStyles(fromDoc As String, toDoc As String)
- ' Extract and copy the styles part.
- Dim node = ExtractStylesPart(fromDoc, False)
- If node IsNot Nothing Then
- ReplaceStylesPart(toDoc, node, False)
- End If
-
- ' Extract and copy the stylesWithEffects part. To fully support
- ' round-tripping from Word 2013 to Word 2010, you should
- ' replace this part, as well.
- node = ExtractStylesPart(fromDoc, True)
- If node IsNot Nothing Then
- ReplaceStylesPart(toDoc, node, True)
- End If
- End Sub
-
- ' Given a file and an XDocument instance that contains the content of
- ' a styles or stylesWithEffects part, replace the styles in the file
- ' with the styles in the XDocument.
- Public Sub ReplaceStylesPart(
- ByVal fileName As String, ByVal newStyles As XDocument,
- Optional ByVal setStylesWithEffectsPart As Boolean = True)
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/replace_the_styles_parts/cs/Program.cs)]
- ' Open the document for write access and get a reference.
- Using document = WordprocessingDocument.Open(fileName, True)
-
- ' Get a reference to the main document part.
- Dim docPart = document.MainDocumentPart
-
- ' Assign a reference to the appropriate part to the
- ' stylesPart variable.
- Dim stylesPart As StylesPart = Nothing
- If setStylesWithEffectsPart Then
- stylesPart = docPart.StylesWithEffectsPart
- Else
- stylesPart = docPart.StyleDefinitionsPart
- End If
-
- ' If the part exists, populate it with the new styles.
- If stylesPart IsNot Nothing Then
- newStyles.Save(New StreamWriter(
- stylesPart.GetStream(FileMode.Create, FileAccess.Write)))
- End If
- End Using
- End Sub
-
- ' Extract the styles or stylesWithEffects part from a
- ' word processing document as an XDocument instance.
- Public Function ExtractStylesPart(
- ByVal fileName As String,
- Optional ByVal getStylesWithEffectsPart As Boolean = True) As XDocument
-
- ' Declare a variable to hold the XDocument.
- Dim styles As XDocument = Nothing
-
- ' Open the document for read access and get a reference.
- Using document = WordprocessingDocument.Open(fileName, False)
-
- ' Get a reference to the main document part.
- Dim docPart = document.MainDocumentPart
-
- ' Assign a reference to the appropriate part to the
- ' stylesPart variable.
- Dim stylesPart As StylesPart = Nothing
- If getStylesWithEffectsPart Then
- stylesPart = docPart.StylesWithEffectsPart
- Else
- stylesPart = docPart.StyleDefinitionsPart
- End If
-
- ' If the part exists, read it into the XDocument.
- If stylesPart IsNot Nothing Then
- Using reader = XmlNodeReader.Create(
- stylesPart.GetStream(FileMode.Open, FileAccess.Read))
- ' Create the XDocument:
- styles = XDocument.Load(reader)
- End Using
- End If
- End Using
- ' Return the XDocument instance.
- Return styles
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/replace_the_styles_parts/vb/Program.vb)]
---------------------------------------------------------------------------------
diff --git a/docs/how-to-replace-the-theme-part-in-a-word-processing-document.md b/docs/how-to-replace-the-theme-part-in-a-word-processing-document.md
index 89ecb512..0e8d22a2 100644
--- a/docs/how-to-replace-the-theme-part-in-a-word-processing-document.md
+++ b/docs/how-to-replace-the-theme-part-in-a-word-processing-document.md
@@ -20,18 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to programmatically replace a document part in a word processing
document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.IO;
- using DocumentFormat.OpenXml.Packaging;
-```
-
-```vb
- Imports System.IO
- Imports DocumentFormat.OpenXml.Packaging
-```
## Packages and Document Parts
@@ -236,54 +225,11 @@ font.
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // This method can be used to replace the theme part in a package.
- public static void ReplaceTheme(string document, string themeFile)
- {
- using (WordprocessingDocument wordDoc =
- WordprocessingDocument.Open(document, true))
- {
- MainDocumentPart mainPart = wordDoc.MainDocumentPart;
-
- // Delete the old document part.
- mainPart.DeletePart(mainPart.ThemePart);
-
- // Add a new document part and then add content.
- ThemePart themePart = mainPart.AddNewPart();
-
- using (StreamReader streamReader = new StreamReader(themeFile))
- using (StreamWriter streamWriter =
- new StreamWriter(themePart.GetStream(FileMode.Create)))
- {
- streamWriter.Write(streamReader.ReadToEnd());
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/replace_the_theme_part/cs/Program.cs)]
-```vb
- ' This method can be used to replace a document part in a package.
- Public Sub ReplaceTheme(ByVal document As String, ByVal themeFile As String)
- Using wordDoc As WordprocessingDocument = _
- WordprocessingDocument.Open(document, True)
- Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart
-
- ' Delete the old document part.
- mainPart.DeletePart(mainPart.ThemePart)
-
- ' Add a new document part and then add content.
- Dim themePart As ThemePart = mainPart.AddNewPart(Of ThemePart)()
-
- Using streamReader As New StreamReader(themeFile)
- Using streamWriter As _
- New StreamWriter(themePart.GetStream(FileMode.Create))
-
- streamWriter.Write(streamReader.ReadToEnd())
- End Using
- End Using
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/replace_the_theme_part/vb/Program.vb)]
## See also
diff --git a/docs/how-to-retrieve-a-dictionary-of-all-named-ranges-in-a-spreadsheet.md b/docs/how-to-retrieve-a-dictionary-of-all-named-ranges-in-a-spreadsheet.md
index 9a4287e9..83853c58 100644
--- a/docs/how-to-retrieve-a-dictionary-of-all-named-ranges-in-a-spreadsheet.md
+++ b/docs/how-to-retrieve-a-dictionary-of-all-named-ranges-in-a-spreadsheet.md
@@ -171,63 +171,11 @@ defined names that are contained within the workbook. If the property returns a
The following is the complete **GetDefinedNames** code sample in C\# and Visual Basic.
-```csharp
- public static Dictionary
- GetDefinedNames(String fileName)
- {
- // Given a workbook name, return a dictionary of defined names.
- // The pairs include the range name and a string representing the range.
- var returnValue = new Dictionary();
-
- // Open the spreadsheet document for read-only access.
- using (SpreadsheetDocument document =
- SpreadsheetDocument.Open(fileName, false))
- {
- // Retrieve a reference to the workbook part.
- var wbPart = document.WorkbookPart;
-
- // Retrieve a reference to the defined names collection.
- DefinedNames definedNames = wbPart.Workbook.DefinedNames;
-
- // If there are defined names, add them to the dictionary.
- if (definedNames != null)
- {
- foreach (DefinedName dn in definedNames)
- returnValue.Add(dn.Name.Value, dn.Text);
- }
- }
- return returnValue;
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs)]
-```vb
- Public Function GetDefinedNames(
- ByVal fileName As String) As Dictionary(Of String, String)
-
- ' Given a workbook name, return a dictionary of defined names.
- ' The pairs include the range name and a string representing the range.
- Dim returnValue As New Dictionary(Of String, String)
-
- ' Open the spreadsheet document for read-only access.
- Using document As SpreadsheetDocument =
- SpreadsheetDocument.Open(fileName, False)
-
- ' Retrieve a reference to the workbook part.
- Dim wbPart As WorkbookPart = document.WorkbookPart
-
- ' Retrieve a reference to the defined names collection.
- Dim definedNames As DefinedNames = wbPart.Workbook.DefinedNames
-
- ' If there are defined names, add them to the dictionary.
- If definedNames IsNot Nothing Then
- For Each dn As DefinedName In definedNames
- returnValue.Add(dn.Name.Value, dn.Text)
- Next
- End If
- End Using
- Return returnValue
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/Program.vb)]
## See also
diff --git a/docs/how-to-retrieve-a-list-of-the-hidden-rows-or-columns-in-a-spreadsheet.md b/docs/how-to-retrieve-a-list-of-the-hidden-rows-or-columns-in-a-spreadsheet.md
index 752e61fb..30c841ca 100644
--- a/docs/how-to-retrieve-a-list-of-the-hidden-rows-or-columns-in-a-spreadsheet.md
+++ b/docs/how-to-retrieve-a-list-of-the-hidden-rows-or-columns-in-a-spreadsheet.md
@@ -252,112 +252,11 @@ Retrieving the list of hidden columns is a bit trickier, because Excel collapses
The following is the complete **GetHiddenRowsOrCols** code sample in C\# and Visual Basic.
-```csharp
- public static List GetHiddenRowsOrCols(
- string fileName, string sheetName, bool detectRows)
- {
- // Given a workbook and a worksheet name, return
- // either a list of hidden row numbers, or a list
- // of hidden column numbers. If detectRows is true, return
- // hidden rows. If detectRows is false, return hidden columns.
- // Rows and columns are numbered starting with 1.
-
- List itemList = new List();
-
- using (SpreadsheetDocument document =
- SpreadsheetDocument.Open(fileName, false))
- {
- WorkbookPart wbPart = document.WorkbookPart;
-
- Sheet theSheet = wbPart.Workbook.Descendants().
- Where((s) => s.Name == sheetName).FirstOrDefault();
- if (theSheet == null)
- {
- throw new ArgumentException("sheetName");
- }
- else
- {
- // The sheet does exist.
- WorksheetPart wsPart =
- (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
- Worksheet ws = wsPart.Worksheet;
-
- if (detectRows)
- {
- // Retrieve hidden rows.
- itemList = ws.Descendants().
- Where((r) => r.Hidden != null && r.Hidden.Value).
- Select(r => r.RowIndex.Value).ToList();
- }
- else
- {
- // Retrieve hidden columns.
- var cols = ws.Descendants().
- Where((c) => c.Hidden != null && c.Hidden.Value);
- foreach (Column item in cols)
- {
- for (uint i = item.Min.Value; i <= item.Max.Value; i++)
- {
- itemList.Add(i);
- }
- }
- }
- }
- }
- return itemList;
- }
-```
-
-```vb
- Public Function GetHiddenRowsOrCols(
- ByVal fileName As String, ByVal sheetName As String,
- ByVal detectRows As Boolean) As List(Of UInteger)
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs)]
- ' Given a workbook and a worksheet name, return either
- ' a list of hidden row numbers, or a list of hidden
- ' column numbers. If detectRows is True, return
- ' hidden rows. If detectRows is False, return hidden columns.
- ' Rows and columns are numbered starting with 1.
-
- Dim itemList As New List(Of UInteger)
-
- Using document As SpreadsheetDocument =
- SpreadsheetDocument.Open(fileName, False)
-
- Dim wbPart As WorkbookPart = document.WorkbookPart
-
- Dim theSheet As Sheet = wbPart.Workbook.Descendants(Of Sheet)().
- Where(Function(s) s.Name = sheetName).FirstOrDefault()
- If theSheet Is Nothing Then
- Throw New ArgumentException("sheetName")
- Else
- ' The sheet does exist.
- Dim wsPart As WorksheetPart =
- CType(wbPart.GetPartById(theSheet.Id), WorksheetPart)
- Dim ws As Worksheet = wsPart.Worksheet
-
- If detectRows Then
- ' Retrieve hidden rows.
- itemList = ws.Descendants(Of Row).
- Where(Function(r) r.Hidden IsNot Nothing AndAlso
- r.Hidden.Value).
- Select(Function(r) r.RowIndex.Value).ToList()
- Else
- ' Retrieve hidden columns.
- Dim cols = ws.Descendants(Of Column).
- Where(Function(c) c.Hidden IsNot Nothing AndAlso
- c.Hidden.Value)
- For Each item As Column In cols
- For i As UInteger = item.Min.Value To item.Max.Value
- itemList.Add(i)
- Next
- Next
- End If
- End If
- End Using
- Return itemList
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/Program.vb)]
---------------------------------------------------------------------------------
diff --git a/docs/how-to-retrieve-a-list-of-the-hidden-worksheets-in-a-spreadsheet.md b/docs/how-to-retrieve-a-list-of-the-hidden-worksheets-in-a-spreadsheet.md
index e289925a..3515cfac 100644
--- a/docs/how-to-retrieve-a-list-of-the-hidden-worksheets-in-a-spreadsheet.md
+++ b/docs/how-to-retrieve-a-list-of-the-hidden-worksheets-in-a-spreadsheet.md
@@ -157,54 +157,11 @@ Finally, the following code calls the **[ToList\](https://msdn2.micros
The following is the complete **GetHiddenSheets** code sample in C\# and Visual Basic.
-```csharp
- public static List GetHiddenSheets(string fileName)
- {
- List returnVal = new List();
-
- using (SpreadsheetDocument document =
- SpreadsheetDocument.Open(fileName, false))
- {
- WorkbookPart wbPart = document.WorkbookPart;
- var sheets = wbPart.Workbook.Descendants();
-
- // Look for sheets where there is a State attribute defined,
- // where the State has a value,
- // and where the value is either Hidden or VeryHidden.
- var hiddenSheets = sheets.Where((item) => item.State != null &&
- item.State.HasValue &&
- (item.State.Value == SheetStateValues.Hidden ||
- item.State.Value == SheetStateValues.VeryHidden));
-
- returnVal = hiddenSheets.ToList();
- }
- return returnVal;
- }
-```
-
-```vb
- Public Function GetHiddenSheets(ByVal fileName As String) As List(Of Sheet)
- Dim returnVal As New List(Of Sheet)
-
- Using document As SpreadsheetDocument =
- SpreadsheetDocument.Open(fileName, False)
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs)]
- Dim wbPart As WorkbookPart = document.WorkbookPart
- Dim sheets = wbPart.Workbook.Descendants(Of Sheet)()
-
- ' Look for sheets where there is a State attribute defined,
- ' where the State has a value,
- ' and where the value is either Hidden or VeryHidden:
- Dim hiddenSheets = sheets.Where(Function(item) item.State IsNot
- Nothing AndAlso item.State.HasValue _
- AndAlso (item.State.Value = SheetStateValues.Hidden Or _
- item.State.Value = SheetStateValues.VeryHidden))
-
- returnVal = hiddenSheets.ToList()
- End Using
- Return returnVal
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/Program.vb)]
## See also
diff --git a/docs/how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md b/docs/how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md
index 7f7196d7..b490d436 100644
--- a/docs/how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md
+++ b/docs/how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md
@@ -160,80 +160,11 @@ To get access to the **[Workbook](https://msdn.microsoft.com/library/office/docu
The following is the complete **GetAllWorksheets** code sample in C\# and Visual
Basic.
-```csharp
- using System;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Spreadsheet;
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs)]
- namespace GetAllWorkheets
- {
- class Program
- {
- const string DEMOFILE =
- @"C:\Users\Public\Documents\SampleWorkbook.xlsx";
-
- static void Main(string[] args)
- {
- var results = GetAllWorksheets(DEMOFILE);
- foreach (Sheet item in results)
- {
- Console.WriteLine(item.Name);
- }
- }
-
- // Retrieve a List of all the sheets in a workbook.
- // The Sheets class contains a collection of
- // OpenXmlElement objects, each representing one of
- // the sheets.
- public static Sheets GetAllWorksheets(string fileName)
- {
- Sheets theSheets = null;
-
- using (SpreadsheetDocument document =
- SpreadsheetDocument.Open(fileName, false))
- {
- WorkbookPart wbPart = document.WorkbookPart;
- theSheets = wbPart.Workbook.Sheets;
- }
- return theSheets;
- }
- }
- }
-```
-
-```vb
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Spreadsheet
-
- Module Module1
-
- Const DEMOFILE As String =
- "C:\Users\Public\Documents\SampleWorkbook.xlsx"
-
- Sub Main()
- Dim results = GetAllWorksheets(DEMOFILE)
- ' Because Sheet inherits from OpenXmlElement, you can cast
- ' each item in the collection to be a Sheet instance.
- For Each item As Sheet In results
- Console.WriteLine(item.Name)
- Next
- End Sub
-
- ' Retrieve a list of all the sheets in a Workbook.
- ' The Sheets class contains a collection of
- ' OpenXmlElement objects, each representing
- ' one of the sheets.
- Public Function GetAllWorksheets(ByVal fileName As String) As Sheets
- Dim theSheets As Sheets
- Using document As SpreadsheetDocument =
- SpreadsheetDocument.Open(fileName, False)
- Dim wbPart As WorkbookPart = document.WorkbookPart
- theSheets = wbPart.Workbook.Sheets()
- End Using
- Return theSheets
- End Function
- End Module
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/Program.vb)]
--------------------------------------------------------------------------------
diff --git a/docs/how-to-retrieve-application-property-values-from-a-word-processing-document.md b/docs/how-to-retrieve-application-property-values-from-a-word-processing-document.md
index 4fd73f7a..b99e22c0 100644
--- a/docs/how-to-retrieve-application-property-values-from-a-word-processing-document.md
+++ b/docs/how-to-retrieve-application-property-values-from-a-word-processing-document.md
@@ -104,66 +104,11 @@ document properties aren't available if you (or the application) haven't specifi
The following is the complete code sample in C\# and Visual Basic.
-```csharp
- using System;
- using DocumentFormat.OpenXml.Packaging;
-
- namespace GetApplicationProperty
- {
- class Program
- {
- private const string FILENAME =
- @"C:\Users\Public\Documents\DocumentProperties.docx";
-
- static void Main(string[] args)
- {
- using (WordprocessingDocument document =
- WordprocessingDocument.Open(FILENAME, false))
- {
- var props = document.ExtendedFilePropertiesPart.Properties;
-
- if (props.Company != null)
- Console.WriteLine("Company = " + props.Company.Text);
-
- if (props.Lines != null)
- Console.WriteLine("Lines = " + props.Lines.Text);
-
- if (props.Manager != null)
- Console.WriteLine("Manager = " + props.Manager.Text);
- }
- }
- }
- }
-```
-
-```vb
- Imports DocumentFormat.OpenXml.Packaging
-
- Module Module1
-
- Private Const FILENAME As String =
- "C:\Users\Public\Documents\DocumentProperties.docx"
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/retrieve_application_property_values/cs/Program.cs)]
- Sub Main()
- Using document As WordprocessingDocument =
- WordprocessingDocument.Open(FILENAME, False)
-
- Dim props = document.ExtendedFilePropertiesPart.Properties
- If props.Company IsNot Nothing Then
- Console.WriteLine("Company = " & props.Company.Text)
- End If
-
- If props.Lines IsNot Nothing Then
- Console.WriteLine("Lines = " & props.Lines.Text)
- End If
-
- If props.Manager IsNot Nothing Then
- Console.WriteLine("Manager = " & props.Manager.Text)
- End If
- End Using
- End Sub
- End Module
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/retrieve_application_property_values/vb/Program.vb)]
## See also
diff --git a/docs/how-to-retrieve-comments-from-a-word-processing-document.md b/docs/how-to-retrieve-comments-from-a-word-processing-document.md
index 8a9b8a99..7b8ce76a 100644
--- a/docs/how-to-retrieve-comments-from-a-word-processing-document.md
+++ b/docs/how-to-retrieve-comments-from-a-word-processing-document.md
@@ -20,20 +20,7 @@ This topic describes how to use the classes in the Open XML SDK for
Office to programmatically retrieve the comments from the main document
part in a word processing document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Wordprocessing;
-```
-
-```vb
- Imports System
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Wordprocessing
-```
--------------------------------------------------------------------------------
## Open the Existing Document for Read-only Access
@@ -195,44 +182,11 @@ example.
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void GetCommentsFromDocument(string fileName)
- {
- using (WordprocessingDocument wordDoc =
- WordprocessingDocument.Open(fileName, false))
- {
- WordprocessingCommentsPart commentsPart =
- wordDoc.MainDocumentPart.WordprocessingCommentsPart;
-
- if (commentsPart != null && commentsPart.Comments != null)
- {
- foreach (Comment comment in commentsPart.Comments.Elements())
- {
- Console.WriteLine(comment.InnerText);
- }
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/retrieve_comments/cs/Program.cs)]
-```vb
- Public Sub GetCommentsFromDocument(ByVal fileName As String)
- Using wordDoc As WordprocessingDocument = _
- WordprocessingDocument.Open(fileName, False)
-
- Dim commentsPart As WordprocessingCommentsPart = _
- wordDoc.MainDocumentPart.WordprocessingCommentsPart
-
- If commentsPart IsNot Nothing AndAlso _
- commentsPart.Comments IsNot Nothing Then
- For Each comment As Comment In _
- commentsPart.Comments.Elements(Of Comment)()
- Console.WriteLine(comment.InnerText)
- Next
- End If
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/retrieve_comments/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-retrieve-the-number-of-slides-in-a-presentation-document.md b/docs/how-to-retrieve-the-number-of-slides-in-a-presentation-document.md
index 2453a1d5..b68881d7 100644
--- a/docs/how-to-retrieve-the-number-of-slides-in-a-presentation-document.md
+++ b/docs/how-to-retrieve-the-number-of-slides-in-a-presentation-document.md
@@ -181,68 +181,11 @@ function with a lambda expression to do the work.
The following is the complete **RetrieveNumberOfSlides** code sample in C\# and
Visual Basic.
-```csharp
- public static int RetrieveNumberOfSlides(string fileName,
- bool includeHidden = true)
- {
- int slidesCount = 0;
-
- using (PresentationDocument doc =
- PresentationDocument.Open(fileName, false))
- {
- // Get the presentation part of the document.
- PresentationPart presentationPart = doc.PresentationPart;
- if (presentationPart != null)
- {
- if (includeHidden)
- {
- slidesCount = presentationPart.SlideParts.Count();
- }
- else
- {
- // Each slide can include a Show property, which if hidden
- // will contain the value "0". The Show property may not
- // exist, and most likely will not, for non-hidden slides.
- var slides = presentationPart.SlideParts.Where(
- (s) => (s.Slide != null) &&
- ((s.Slide.Show == null) || (s.Slide.Show.HasValue &&
- s.Slide.Show.Value)));
- slidesCount = slides.Count();
- }
- }
- }
- return slidesCount;
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/presentation/retrieve_the_number_of_slides/cs/Program.cs)]
-```vb
- Public Function RetrieveNumberOfSlides(ByVal fileName As String,
- Optional ByVal includeHidden As Boolean = True) As Integer
- Dim slidesCount As Integer = 0
-
- Using doc As PresentationDocument =
- PresentationDocument.Open(fileName, False)
- ' Get the presentation part of the document.
- Dim presentationPart As PresentationPart = doc.PresentationPart
- If presentationPart IsNot Nothing Then
- If includeHidden Then
- slidesCount = presentationPart.SlideParts.Count()
- Else
- ' Each slide can include a Show property, which if
- ' hidden will contain the value "0". The Show property may
- ' not exist, and most likely will not, for non-hidden slides.
- Dim slides = presentationPart.SlideParts.
- Where(Function(s) (s.Slide IsNot Nothing) AndAlso
- ((s.Slide.Show Is Nothing) OrElse
- (s.Slide.Show.HasValue AndAlso
- s.Slide.Show.Value)))
- slidesCount = slides.Count()
- End If
- End If
- End Using
- Return slidesCount
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/presentation/retrieve_the_number_of_slides/vb/Program.vb)]
---------------------------------------------------------------------------------
diff --git a/docs/how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md b/docs/how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md
index 40c9a043..c118e801 100644
--- a/docs/how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md
+++ b/docs/how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md
@@ -370,173 +370,11 @@ Finally, the procedure returns the variable **value**, which contains the reques
The following is the complete **GetCellValue** code sample in C\# and Visual Basic.
-```csharp
- // Retrieve the value of a cell, given a file name, sheet name,
- // and address name.
- public static string GetCellValue(string fileName,
- string sheetName,
- string addressName)
- {
- string value = null;
-
- // Open the spreadsheet document for read-only access.
- using (SpreadsheetDocument document =
- SpreadsheetDocument.Open(fileName, false))
- {
- // Retrieve a reference to the workbook part.
- WorkbookPart wbPart = document.WorkbookPart;
-
- // Find the sheet with the supplied name, and then use that
- // Sheet object to retrieve a reference to the first worksheet.
- Sheet theSheet = wbPart.Workbook.Descendants().
- Where(s => s.Name == sheetName).FirstOrDefault();
-
- // Throw an exception if there is no sheet.
- if (theSheet == null)
- {
- throw new ArgumentException("sheetName");
- }
-
- // Retrieve a reference to the worksheet part.
- WorksheetPart wsPart =
- (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
-
- // Use its Worksheet property to get a reference to the cell
- // whose address matches the address you supplied.
- Cell theCell = wsPart.Worksheet.Descendants().
- Where(c => c.CellReference == addressName).FirstOrDefault();
-
- // If the cell does not exist, return an empty string.
- if (theCell.InnerText.Length > 0)
- {
- value = theCell.InnerText;
-
- // If the cell represents an integer number, you are done.
- // For dates, this code returns the serialized value that
- // represents the date. The code handles strings and
- // Booleans individually. For shared strings, the code
- // looks up the corresponding value in the shared string
- // table. For Booleans, the code converts the value into
- // the words TRUE or FALSE.
- if (theCell.DataType != null)
- {
- switch (theCell.DataType.Value)
- {
- case CellValues.SharedString:
-
- // For shared strings, look up the value in the
- // shared strings table.
- var stringTable =
- wbPart.GetPartsOfType()
- .FirstOrDefault();
-
- // If the shared string table is missing, something
- // is wrong. Return the index that is in
- // the cell. Otherwise, look up the correct text in
- // the table.
- if (stringTable != null)
- {
- value =
- stringTable.SharedStringTable
- .ElementAt(int.Parse(value)).InnerText;
- }
- break;
-
- case CellValues.Boolean:
- switch (value)
- {
- case "0":
- value = "FALSE";
- break;
- default:
- value = "TRUE";
- break;
- }
- break;
- }
- }
- }
- }
- return value;
- }
-```
-
-```vb
- Public Function GetCellValue(ByVal fileName As String,
- ByVal sheetName As String,
- ByVal addressName As String) As String
+### [C#](#tab/cs)
+[!code-csharp[](../samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs)]
- Dim value As String = Nothing
-
- ' Open the spreadsheet document for read-only access.
- Using document As SpreadsheetDocument =
- SpreadsheetDocument.Open(fileName, False)
-
- ' Retrieve a reference to the workbook part.
- Dim wbPart As WorkbookPart = document.WorkbookPart
-
- ' Find the sheet with the supplied name, and then use that Sheet object
- ' to retrieve a reference to the appropriate worksheet.
- Dim theSheet As Sheet = wbPart.Workbook.Descendants(Of Sheet)().
- Where(Function(s) s.Name = sheetName).FirstOrDefault()
-
- ' Throw an exception if there is no sheet.
- If theSheet Is Nothing Then
- Throw New ArgumentException("sheetName")
- End If
-
- ' Retrieve a reference to the worksheet part.
- Dim wsPart As WorksheetPart =
- CType(wbPart.GetPartById(theSheet.Id), WorksheetPart)
-
- ' Use its Worksheet property to get a reference to the cell
- ' whose address matches the address you supplied.
- Dim theCell As Cell = wsPart.Worksheet.Descendants(Of Cell).
- Where(Function(c) c.CellReference = addressName).FirstOrDefault
-
- ' If the cell does not exist, return an empty string.
- If theCell IsNot Nothing Then
- value = theCell.InnerText
-
- ' If the cell represents an numeric value, you are done.
- ' For dates, this code returns the serialized value that
- ' represents the date. The code handles strings and
- ' Booleans individually. For shared strings, the code
- ' looks up the corresponding value in the shared string
- ' table. For Booleans, the code converts the value into
- ' the words TRUE or FALSE.
- If theCell.DataType IsNot Nothing Then
- Select Case theCell.DataType.Value
- Case CellValues.SharedString
-
- ' For shared strings, look up the value in the
- ' shared strings table.
- Dim stringTable = wbPart.
- GetPartsOfType(Of SharedStringTablePart).FirstOrDefault()
-
- ' If the shared string table is missing, something
- ' is wrong. Return the index that is in
- ' the cell. Otherwise, look up the correct text in
- ' the table.
- If stringTable IsNot Nothing Then
- value = stringTable.SharedStringTable.
- ElementAt(Integer.Parse(value)).InnerText
- End If
-
- Case CellValues.Boolean
- Select Case value
- Case "0"
- value = "FALSE"
- Case Else
- value = "TRUE"
- End Select
- End Select
- End If
- End If
- End Using
- Return value
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/spreadsheet/retrieve_the_values_of_cells/vb/Program.vb)]
## See also
diff --git a/docs/how-to-search-and-replace-text-in-a-document-part.md b/docs/how-to-search-and-replace-text-in-a-document-part.md
index 39216166..e239f6aa 100644
--- a/docs/how-to-search-and-replace-text-in-a-document-part.md
+++ b/docs/how-to-search-and-replace-text-in-a-document-part.md
@@ -20,20 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to programmatically search and replace a text value in a word
processing document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.IO;
- using System.Text.RegularExpressions;
- using DocumentFormat.OpenXml.Packaging;
-```
-
-```vb
- Imports System.IO
- Imports System.Text.RegularExpressions
- Imports DocumentFormat.OpenXml.Packaging
-```
--------------------------------------------------------------------------------
## Packages and Document Parts
@@ -87,40 +74,6 @@ when you exit the block, you do not have to explicitly call **Save** and **Close
long as you use **using**.
---------------------------------------------------------------------------------
-## How the Sample Code Works
-After you have opened the file for editing, you read it by using a **StreamReader** object.
-
-```csharp
- using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
- {
- docText = sr.ReadToEnd();
- }
-```
-
-```vb
- Dim sr As StreamReader = New StreamReader(wordDoc.MainDocumentPart.GetStream)
-
- using (sr)
- docText = sr.ReadToEnd
- End using
-```
-
-The code then creates a regular expression object that contains the
-string "Hello world!" It then replaces the text value with the text "Hi
-Everyone!." For more information about regular expressions, see [Regular
-Expressions](https://msdn.microsoft.com/library/hs600312.aspx)
-
-```csharp
- Regex regexText = new Regex("Hello world!");
- docText = regexText.Replace(docText, "Hi Everyone!");
-```
-
-```vb
- Dim regexText As Regex = New Regex("Hello world!")
- docText = regexText.Replace(docText, "Hi Everyone!")
-```
-
--------------------------------------------------------------------------------
## Sample Code
The following example demonstrates a quick and easy way to search and
@@ -149,51 +102,11 @@ the text, "Hello world!"
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // To search and replace content in a document part.
- public static void SearchAndReplace(string document)
- {
- using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
- {
- string docText = null;
- using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
- {
- docText = sr.ReadToEnd();
- }
-
- Regex regexText = new Regex("Hello world!");
- docText = regexText.Replace(docText, "Hi Everyone!");
-
- using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
- {
- sw.Write(docText);
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/search_and_replace_text_a_part/cs/Program.cs)]
-```vb
- ' To search and replace content in a document part.
- Public Sub SearchAndReplace(ByVal document As String)
- Dim wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
- using (wordDoc)
- Dim docText As String = Nothing
- Dim sr As StreamReader = New StreamReader(wordDoc.MainDocumentPart.GetStream)
-
- using (sr)
- docText = sr.ReadToEnd
- End using
-
- Dim regexText As Regex = New Regex("Hello world!")
- docText = regexText.Replace(docText, "Hi Everyone!")
- Dim sw As StreamWriter = New StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create))
-
- using (sw)
- sw.Write(docText)
- End using
- End using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/search_and_replace_text_a_part/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-set-a-custom-property-in-a-word-processing-document.md b/docs/how-to-set-a-custom-property-in-a-word-processing-document.md
index 2f8fcf28..d6ed0791 100644
--- a/docs/how-to-set-a-custom-property-in-a-word-processing-document.md
+++ b/docs/how-to-set-a-custom-property-in-a-word-processing-document.md
@@ -471,260 +471,11 @@ Finally, the code returns the stored original property value.
The following is the complete **SetCustomProperty** code sample in C\# and Visual Basic.
-```csharp
- public enum PropertyTypes : int
- {
- YesNo,
- Text,
- DateTime,
- NumberInteger,
- NumberDouble
- }
-
- public static string SetCustomProperty(
- string fileName,
- string propertyName,
- object propertyValue,
- PropertyTypes propertyType)
- {
- // Given a document name, a property name/value, and the property type,
- // add a custom property to a document. The method returns the original
- // value, if it existed.
-
- string returnValue = null;
-
- var newProp = new CustomDocumentProperty();
- bool propSet = false;
-
- // Calculate the correct type.
- switch (propertyType)
- {
- case PropertyTypes.DateTime:
-
- // Be sure you were passed a real date,
- // and if so, format in the correct way.
- // The date/time value passed in should
- // represent a UTC date/time.
- if ((propertyValue) is DateTime)
- {
- newProp.VTFileTime =
- new VTFileTime(string.Format("{0:s}Z",
- Convert.ToDateTime(propertyValue)));
- propSet = true;
- }
-
- break;
-
- case PropertyTypes.NumberInteger:
- if ((propertyValue) is int)
- {
- newProp.VTInt32 = new VTInt32(propertyValue.ToString());
- propSet = true;
- }
-
- break;
-
- case PropertyTypes.NumberDouble:
- if (propertyValue is double)
- {
- newProp.VTFloat = new VTFloat(propertyValue.ToString());
- propSet = true;
- }
-
- break;
-
- case PropertyTypes.Text:
- newProp.VTLPWSTR = new VTLPWSTR(propertyValue.ToString());
- propSet = true;
-
- break;
-
- case PropertyTypes.YesNo:
- if (propertyValue is bool)
- {
- // Must be lowercase.
- newProp.VTBool = new VTBool(
- Convert.ToBoolean(propertyValue).ToString().ToLower());
- propSet = true;
- }
- break;
- }
-
- if (!propSet)
- {
- // If the code was not able to convert the
- // property to a valid value, throw an exception.
- throw new InvalidDataException("propertyValue");
- }
-
- // Now that you have handled the parameters, start
- // working on the document.
- newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
- newProp.Name = propertyName;
-
- using (var document = WordprocessingDocument.Open(fileName, true))
- {
- var customProps = document.CustomFilePropertiesPart;
- if (customProps == null)
- {
- // No custom properties? Add the part, and the
- // collection of properties now.
- customProps = document.AddCustomFilePropertiesPart();
- customProps.Properties =
- new DocumentFormat.OpenXml.CustomProperties.Properties();
- }
-
- var props = customProps.Properties;
- if (props != null)
- {
- // This will trigger an exception if the property's Name
- // property is null, but if that happens, the property is damaged,
- // and probably should raise an exception.
- var prop =
- props.Where(
- p => ((CustomDocumentProperty)p).Name.Value
- == propertyName).FirstOrDefault();
-
- // Does the property exist? If so, get the return value,
- // and then delete the property.
- if (prop != null)
- {
- returnValue = prop.InnerText;
- prop.Remove();
- }
-
- // Append the new property, and
- // fix up all the property ID values.
- // The PropertyId value must start at 2.
- props.AppendChild(newProp);
- int pid = 2;
- foreach (CustomDocumentProperty item in props)
- {
- item.PropertyId = pid++;
- }
- props.Save();
- }
- }
- return returnValue;
- }
-```
-
-```vb
- Public Enum PropertyTypes
- YesNo
- Text
- DateTime
- NumberInteger
- NumberDouble
- End Enum
-
- Public Function SetCustomProperty( _
- ByVal fileName As String,
- ByVal propertyName As String, _
- ByVal propertyValue As Object,
- ByVal propertyType As PropertyTypes) As String
-
- ' Given a document name, a property name/value, and the property type,
- ' add a custom property to a document. The method returns the original
- ' value, if it existed.
-
- Dim returnValue As String = Nothing
-
- Dim newProp As New CustomDocumentProperty
- Dim propSet As Boolean = False
-
- ' Calculate the correct type:
- Select Case propertyType
-
- Case PropertyTypes.DateTime
- ' Make sure you were passed a real date,
- ' and if so, format in the correct way.
- ' The date/time value passed in should
- ' represent a UTC date/time.
- If TypeOf (propertyValue) Is DateTime Then
- newProp.VTFileTime = _
- New VTFileTime(String.Format("{0:s}Z",
- Convert.ToDateTime(propertyValue)))
- propSet = True
- End If
-
- Case PropertyTypes.NumberInteger
- If TypeOf (propertyValue) Is Integer Then
- newProp.VTInt32 = New VTInt32(propertyValue.ToString())
- propSet = True
- End If
-
- Case PropertyTypes.NumberDouble
- If TypeOf propertyValue Is Double Then
- newProp.VTFloat = New VTFloat(propertyValue.ToString())
- propSet = True
- End If
-
- Case PropertyTypes.Text
- newProp.VTLPWSTR = New VTLPWSTR(propertyValue.ToString())
- propSet = True
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/set_a_custom_property/cs/Program.cs)]
- Case PropertyTypes.YesNo
- If TypeOf propertyValue Is Boolean Then
- ' Must be lowercase.
- newProp.VTBool = _
- New VTBool(Convert.ToBoolean(propertyValue).ToString().ToLower())
- propSet = True
- End If
- End Select
-
- If Not propSet Then
- ' If the code was not able to convert the
- ' property to a valid value, throw an exception.
- Throw New InvalidDataException("propertyValue")
- End If
-
- ' Now that you have handled the parameters, start
- ' working on the document.
- newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
- newProp.Name = propertyName
-
- Using document = WordprocessingDocument.Open(fileName, True)
- Dim customProps = document.CustomFilePropertiesPart
- If customProps Is Nothing Then
- ' No custom properties? Add the part, and the
- ' collection of properties now.
- customProps = document.AddCustomFilePropertiesPart
- customProps.Properties = New Properties
- End If
-
- Dim props = customProps.Properties
- If props IsNot Nothing Then
- ' This will trigger an exception is the property's Name property
- ' is null, but if that happens, the property is damaged, and
- ' probably should raise an exception.
- Dim prop = props.
- Where(Function(p) CType(p, CustomDocumentProperty).
- Name.Value = propertyName).FirstOrDefault()
- ' Does the property exist? If so, get the return value,
- ' and then delete the property.
- If prop IsNot Nothing Then
- returnValue = prop.InnerText
- prop.Remove()
- End If
-
- ' Append the new property, and
- ' fix up all the property ID values.
- ' The PropertyId value must start at 2.
- props.AppendChild(newProp)
- Dim pid As Integer = 2
- For Each item As CustomDocumentProperty In props
- item.PropertyId = pid
- pid += 1
- Next
- props.Save()
- End If
- End Using
-
- Return returnValue
-
- End Function
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/set_a_custom_property/vb/Program.vb)]
## See also
diff --git a/docs/how-to-set-the-font-for-a-text-run.md b/docs/how-to-set-the-font-for-a-text-run.md
index 8079fc0b..68639d29 100644
--- a/docs/how-to-set-the-font-for-a-text-run.md
+++ b/docs/how-to-set-the-font-for-a-text-run.md
@@ -20,20 +20,7 @@ This topic shows how to use the classes in the Open XML SDK for
Office to set the font for a portion of text within a word processing
document programmatically.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System.Linq;
- using DocumentFormat.OpenXml.Wordprocessing;
- using DocumentFormat.OpenXml.Packaging;
-```
-
-```vb
- Imports System.Linq
- Imports DocumentFormat.OpenXml.Wordprocessing
- Imports DocumentFormat.OpenXml.Packaging
-```
--------------------------------------------------------------------------------
## Packages and Document Parts
@@ -223,47 +210,11 @@ changed font.
The following is the complete sample code in both C\# and Visual Basic.
-```csharp
- // Set the font for a text run.
- public static void SetRunFont(string fileName)
- {
- // Open a Wordprocessing document for editing.
- using (WordprocessingDocument package = WordprocessingDocument.Open(fileName, true))
- {
- // Set the font to Arial to the first Run.
- // Use an object initializer for RunProperties and rPr.
- RunProperties rPr = new RunProperties(
- new RunFonts()
- {
- Ascii = "Arial"
- });
-
- Run r = package.MainDocumentPart.Document.Descendants().First();
- r.PrependChild(rPr);
-
- // Save changes to the MainDocumentPart part.
- package.MainDocumentPart.Document.Save();
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/set_the_font_for_a_text_run/cs/Program.cs)]
-```vb
- ' Set the font for a text run.
- Public Sub SetRunFont(ByVal fileName As String)
- ' Open a Wordprocessing document for editing.
- Dim package As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
- Using (package)
- ' Set the font to Arial to the first Run.
- Dim rPr As RunProperties = New RunProperties(New RunFonts With {.Ascii = "Arial"})
- Dim r As Run = package.MainDocumentPart.Document.Descendants(Of Run).First
-
- r.PrependChild(Of RunProperties)(rPr)
-
- ' Save changes to the main document part.
- package.MainDocumentPart.Document.Save()
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/set_the_font_for_a_text_run/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/docs/how-to-validate-a-word-processing-document.md b/docs/how-to-validate-a-word-processing-document.md
index 0c24ffaa..fd0f2b55 100644
--- a/docs/how-to-validate-a-word-processing-document.md
+++ b/docs/how-to-validate-a-word-processing-document.md
@@ -19,22 +19,7 @@ ms.localizationpriority: high
This topic shows how to use the classes in the Open XML SDK for
Office to programmatically validate a word processing document.
-The following assembly directives are required to compile the code in
-this topic.
-```csharp
- using System;
- using DocumentFormat.OpenXml.Packaging;
- using DocumentFormat.OpenXml.Validation;
- using DocumentFormat.OpenXml.Wordprocessing;
-```
-
-```vb
- Imports System
- Imports DocumentFormat.OpenXml.Packaging
- Imports DocumentFormat.OpenXml.Validation
- Imports DocumentFormat.OpenXml.Wordprocessing
-```
--------------------------------------------------------------------------------
## How the Sample Code Works
@@ -83,137 +68,11 @@ following example that validates a file named "Word18.docx.".
Following is the complete sample code in both C\# and Visual Basic.
-```csharp
- public static void ValidateWordDocument(string filepath)
- {
- using (WordprocessingDocument wordprocessingDocument =
- WordprocessingDocument.Open(filepath, true))
- {
- try
- {
- OpenXmlValidator validator = new OpenXmlValidator();
- int count = 0;
- foreach (ValidationErrorInfo error in
- validator.Validate(wordprocessingDocument))
- {
- count++;
- Console.WriteLine("Error " + count);
- Console.WriteLine("Description: " + error.Description);
- Console.WriteLine("ErrorType: " + error.ErrorType);
- Console.WriteLine("Node: " + error.Node);
- Console.WriteLine("Path: " + error.Path.XPath);
- Console.WriteLine("Part: " + error.Part.Uri);
- Console.WriteLine("-------------------------------------------");
- }
-
- Console.WriteLine("count={0}", count);
- }
-
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
-
- wordprocessingDocument.Close();
- }
- }
-
- public static void ValidateCorruptedWordDocument(string filepath)
- {
- // Insert some text into the body, this would cause Schema Error
- using (WordprocessingDocument wordprocessingDocument =
- WordprocessingDocument.Open(filepath, true))
- {
- // Insert some text into the body, this would cause Schema Error
- Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
- Run run = new Run(new Text("some text"));
- body.Append(run);
-
- try
- {
- OpenXmlValidator validator = new OpenXmlValidator();
- int count = 0;
- foreach (ValidationErrorInfo error in
- validator.Validate(wordprocessingDocument))
- {
- count++;
- Console.WriteLine("Error " + count);
- Console.WriteLine("Description: " + error.Description);
- Console.WriteLine("ErrorType: " + error.ErrorType);
- Console.WriteLine("Node: " + error.Node);
- Console.WriteLine("Path: " + error.Path.XPath);
- Console.WriteLine("Part: " + error.Part.Uri);
- Console.WriteLine("-------------------------------------------");
- }
-
- Console.WriteLine("count={0}", count);
- }
-
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
-```
+### [C#](#tab/cs)
+[!code-csharp[](../samples/word/validate/cs/Program.cs)]
-```vb
- Public Sub ValidateWordDocument(ByVal filepath As String)
- Using wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
- Try
- Dim validator As New OpenXmlValidator()
- Dim count As Integer = 0
- For Each [error] As ValidationErrorInfo In validator.Validate(wordprocessingDocument__1)
- count += 1
- Console.WriteLine("Error " & count)
- Console.WriteLine("Description: " & [error].Description)
- Console.WriteLine("ErrorType: " & [error].ErrorType)
- Console.WriteLine("Node: " & [error].Node.ToString())
- Console.WriteLine("Path: " & [error].Path.XPath)
- Console.WriteLine("Part: " & [error].Part.Uri.ToString())
- Console.WriteLine("-------------------------------------------")
- Next
-
- Console.WriteLine("count={0}", count)
-
- Catch ex As Exception
- Console.WriteLine(ex.Message)
- End Try
-
- wordprocessingDocument__1.Close()
- End Using
- End Sub
-
- Public Sub ValidateCorruptedWordDocument(ByVal filepath As String)
- ' Insert some text into the body, this would cause Schema Error
- Using wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
- ' Insert some text into the body, this would cause Schema Error
- Dim body As Body = wordprocessingDocument__1.MainDocumentPart.Document.Body
- Dim run As New Run(New Text("some text"))
- body.Append(run)
-
- Try
- Dim validator As New OpenXmlValidator()
- Dim count As Integer = 0
- For Each [error] As ValidationErrorInfo In validator.Validate(wordprocessingDocument__1)
- count += 1
- Console.WriteLine("Error " & count)
- Console.WriteLine("Description: " & [error].Description)
- Console.WriteLine("ErrorType: " & [error].ErrorType)
- Console.WriteLine("Node: " & [error].Node.ToString())
- Console.WriteLine("Path: " & [error].Path.XPath)
- Console.WriteLine("Part: " & [error].Part.Uri.ToString())
- Console.WriteLine("-------------------------------------------")
- Next
-
- Console.WriteLine("count={0}", count)
-
- Catch ex As Exception
- Console.WriteLine(ex.Message)
- End Try
- End Using
- End Sub
-```
+### [Visual Basic](#tab/vb)
+[!code-vb[](../samples/word/validate/vb/Program.vb)]
--------------------------------------------------------------------------------
## See also
diff --git a/samples/.editorconfig b/samples/.editorconfig
new file mode 100644
index 00000000..a85df58e
--- /dev/null
+++ b/samples/.editorconfig
@@ -0,0 +1,4 @@
+[*.cs]
+
+# CS8321: Local function is declared but never used
+dotnet_diagnostic.CS8321.severity = none
diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props
index 6aee36e9..08c8963d 100644
--- a/samples/Directory.Build.props
+++ b/samples/Directory.Build.props
@@ -2,7 +2,8 @@
net8.0disable
- disable
+ enable
+ NullableExe
\ No newline at end of file
diff --git a/samples/migrate-sample.ps1 b/samples/migrate-sample.ps1
index b07ea5f7..2007aa30 100644
--- a/samples/migrate-sample.ps1
+++ b/samples/migrate-sample.ps1
@@ -1,3 +1,3 @@
param($path)
-dotnet run "$(PSScriptRoot)\tools\migrator.csproj" -- $path
\ No newline at end of file
+dotnet run --project "$PSScriptRoot\tools\migrator\migrator.csproj" -- $path
\ No newline at end of file
diff --git a/samples/presentation/add_comment/cs/Program.cs b/samples/presentation/add_comment/cs/Program.cs
index cbe7f9c2..9d81e847 100644
--- a/samples/presentation/add_comment/cs/Program.cs
+++ b/samples/presentation/add_comment/cs/Program.cs
@@ -13,58 +13,23 @@ static void AddCommentToPresentation(string file, string initials, string name,
// Declare a CommentAuthorsPart object.
CommentAuthorsPart authorsPart;
- // Verify that there is an existing comment authors part.
- if (doc.PresentationPart.CommentAuthorsPart == null)
- {
- // If not, add a new one.
- authorsPart = doc.PresentationPart.AddNewPart();
- }
- else
- {
- authorsPart = doc.PresentationPart.CommentAuthorsPart;
- }
-
- // Verify that there is a comment author list in the comment authors part.
- if (authorsPart.CommentAuthorList == null)
- {
- // If not, add a new one.
- authorsPart.CommentAuthorList = new CommentAuthorList();
- }
-
- // Declare a new author ID.
- uint authorId = 0;
- CommentAuthor author = null;
-
- // If there are existing child elements in the comment authors list...
- if (authorsPart.CommentAuthorList.HasChildren)
- {
- // Verify that the author passed in is on the list.
- var authors = authorsPart.CommentAuthorList.Elements().Where(a => a.Name == name && a.Initials == initials);
-
- // If so...
- if (authors.Any())
- {
- // Assign the new comment author the existing author ID.
- author = authors.First();
- authorId = author.Id;
- }
-
- // If not...
- if (author == null)
- {
- // Assign the author passed in a new ID
- authorId = authorsPart.CommentAuthorList.Elements().Select(a => a.Id.Value).Max();
- }
- }
-
- // If there are no existing child elements in the comment authors list.
- if (author == null)
- {
-
- authorId++;
-
- // Add a new child element(comment author) to the comment author list.
- author = authorsPart.CommentAuthorList.AppendChild
+ // If the presentation does not contain a comment authors part, add a new one.
+ PresentationPart presentationPart = doc.PresentationPart ?? doc.AddPresentationPart();
+
+ // Verify that there is an existing comment authors part and add a new one if not.
+ authorsPart = presentationPart.CommentAuthorsPart ?? presentationPart.AddNewPart();
+
+ // Verify that there is a comment author list in the comment authors part and add one if not.
+ CommentAuthorList authorList = authorsPart.CommentAuthorList ?? new CommentAuthorList();
+ authorsPart.CommentAuthorList = authorList;
+
+ // Declare a new author ID as either the max existing ID + 1 or 1 if there are no existing IDs.
+ uint authorId = authorList.Elements().Select(a => a.Id?.Value).Max() ?? 0;
+ authorId++;
+ // If there is an existing author with matching name and initials, use that author otherwise create a new CommentAuthor.
+ var foo = authorList.Elements().Where(a => a.Name == name && a.Initials == initials).FirstOrDefault();
+ CommentAuthor author = foo ??
+ authorList.AppendChild
(new CommentAuthor()
{
Id = authorId,
@@ -72,7 +37,8 @@ static void AddCommentToPresentation(string file, string initials, string name,
Initials = initials,
ColorIndex = 0
});
- }
+ // get the author id
+ authorId = author.Id ?? authorId;
// Get the first slide, using the GetFirstSlide method.
SlidePart slidePart1 = GetFirstSlide(doc);
@@ -93,14 +59,14 @@ static void AddCommentToPresentation(string file, string initials, string name,
}
// If the comment list does not exist.
- if (commentsPart.CommentList == null)
+ if (commentsPart.CommentList is null)
{
// Add a new comments list.
commentsPart.CommentList = new CommentList();
}
// Get the new comment ID.
- uint commentIdx = author.LastIndex == null ? 1 : author.LastIndex + 1;
+ uint commentIdx = author.LastIndex is null ? 1 : author.LastIndex + 1;
author.LastIndex = commentIdx;
// Add a new comment.
@@ -118,7 +84,7 @@ static void AddCommentToPresentation(string file, string initials, string name,
new Text() { Text = text });
// Save the comment authors part.
- authorsPart.CommentAuthorList.Save();
+ authorList.Save();
// Save the comments part.
commentsPart.CommentList.Save();
@@ -126,15 +92,23 @@ static void AddCommentToPresentation(string file, string initials, string name,
}
// Get the slide part of the first slide in the presentation document.
-static SlidePart GetFirstSlide(PresentationDocument presentationDocument)
+static SlidePart GetFirstSlide(PresentationDocument? presentationDocument)
{
// Get relationship ID of the first slide
- PresentationPart part = presentationDocument.PresentationPart;
- SlideId slideId = part.Presentation.SlideIdList.GetFirstChild();
- string relId = slideId.RelationshipId;
-
+ PresentationPart? part = presentationDocument?.PresentationPart;
+ SlideId? slideId = part?.Presentation?.SlideIdList?.GetFirstChild();
+ string? relId = slideId?.RelationshipId;
+ if (relId is null)
+ {
+ throw new NullReferenceException("The first slide does not contain a relationship ID.");
+ }
// Get the slide part by the relationship ID.
- SlidePart slidePart = (SlidePart)part.GetPartById(relId);
+ SlidePart? slidePart = part?.GetPartById(relId) as SlidePart;
+
+ if (slidePart is null)
+ {
+ throw new NullReferenceException("The slide part is null.");
+ }
return slidePart;
}
diff --git a/samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs b/samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs
new file mode 100644
index 00000000..03360333
--- /dev/null
+++ b/samples/presentation/change_the_fill_color_of_a_shape/cs/Program.cs
@@ -0,0 +1,55 @@
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Presentation;
+using Drawing = DocumentFormat.OpenXml.Drawing;
+
+SetPPTShapeColor(args[0]);
+
+// Change the fill color of a shape.
+// The test file must have a filled shape as the first shape on the first slide.
+static void SetPPTShapeColor(string docName)
+{
+ using (PresentationDocument ppt = PresentationDocument.Open(docName, true))
+ {
+ // Get the relationship ID of the first slide.
+ PresentationPart presentationPart = ppt.PresentationPart ?? ppt.AddPresentationPart();
+ SlideIdList slideIdList = presentationPart.Presentation.SlideIdList ?? presentationPart.Presentation.AppendChild(new SlideIdList());
+ SlideId? slideId = slideIdList.GetFirstChild();
+
+ if (slideId is not null)
+ {
+ string? relId = slideId.RelationshipId;
+
+ if (relId is not null)
+ {
+ // Get the slide part from the relationship ID.
+ SlidePart slidePart = (SlidePart)presentationPart.GetPartById(relId);
+
+ if (slidePart is not null && slidePart.Slide is not null && slidePart.Slide.CommonSlideData is not null && slidePart.Slide.CommonSlideData.ShapeTree is not null)
+ {
+
+ // Get the shape tree that contains the shape to change.
+ ShapeTree tree = slidePart.Slide.CommonSlideData.ShapeTree;
+
+ // Get the first shape in the shape tree.
+ Shape? shape = tree.GetFirstChild();
+
+ if (shape is not null && shape.ShapeStyle is not null && shape.ShapeStyle.FillReference is not null)
+ {
+ // Get the style of the shape.
+ ShapeStyle style = shape.ShapeStyle;
+
+ // Get the fill reference.
+ Drawing.FillReference fillRef = style.FillReference;
+
+ // Set the fill color to SchemeColor Accent 6;
+ fillRef.SchemeColor = new Drawing.SchemeColor();
+ fillRef.SchemeColor.Val = Drawing.SchemeColorValues.Accent6;
+
+ // Save the modified slide.
+ slidePart.Slide.Save();
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/presentation/change_the_fill_color_of_a_shape/cs/change_the_fill_color_of_a_shape_cs.csproj b/samples/presentation/change_the_fill_color_of_a_shape/cs/change_the_fill_color_of_a_shape_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/presentation/change_the_fill_color_of_a_shape/cs/change_the_fill_color_of_a_shape_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb b/samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb
new file mode 100644
index 00000000..f52a4eea
--- /dev/null
+++ b/samples/presentation/change_the_fill_color_of_a_shape/vb/Program.vb
@@ -0,0 +1,48 @@
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Presentation
+Imports Drawing = DocumentFormat.OpenXml.Drawing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Change the fill color of a shape.
+ ' The test file must have a filled shape as the first shape on the first slide.
+ Public Sub SetPPTShapeColor(ByVal docName As String)
+ Using ppt As PresentationDocument = PresentationDocument.Open(docName, True)
+ ' Get the relationship ID of the first slide.
+ Dim part As PresentationPart = ppt.PresentationPart
+ Dim slideIds As OpenXmlElementList = part.Presentation.SlideIdList.ChildElements
+ Dim relId As String = TryCast(slideIds(0), SlideId).RelationshipId
+
+ ' Get the slide part from the relationship ID.
+ Dim slide As SlidePart = DirectCast(part.GetPartById(relId), SlidePart)
+
+ If slide IsNot Nothing Then
+ ' Get the shape tree that contains the shape to change.
+ Dim tree As ShapeTree = slide.Slide.CommonSlideData.ShapeTree
+
+ ' Get the first shape in the shape tree.
+ Dim shape As Shape = tree.GetFirstChild(Of Shape)()
+
+ If shape IsNot Nothing Then
+ ' Get the style of the shape.
+ Dim style As ShapeStyle = shape.ShapeStyle
+
+ ' Get the fill reference.
+ Dim fillRef As Drawing.FillReference = style.FillReference
+
+ ' Set the fill color to SchemeColor Accent 6;
+ fillRef.SchemeColor = New Drawing.SchemeColor()
+ fillRef.SchemeColor.Val = Drawing.SchemeColorValues.Accent6
+
+ ' Save the modified slide.
+ slide.Slide.Save()
+ End If
+ End If
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/presentation/change_the_fill_color_of_a_shape/vb/change_the_fill_color_of_a_shape_vb.vbproj b/samples/presentation/change_the_fill_color_of_a_shape/vb/change_the_fill_color_of_a_shape_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/presentation/change_the_fill_color_of_a_shape/vb/change_the_fill_color_of_a_shape_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/presentation/create_by_providing_a_file_name/cs/Program.cs b/samples/presentation/create_by_providing_a_file_name/cs/Program.cs
new file mode 100644
index 00000000..9aa90187
--- /dev/null
+++ b/samples/presentation/create_by_providing_a_file_name/cs/Program.cs
@@ -0,0 +1,294 @@
+#nullable disable
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Drawing;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Presentation;
+using D = DocumentFormat.OpenXml.Drawing;
+using P = DocumentFormat.OpenXml.Presentation;
+
+namespace CreatePresentationDocument
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ string filepath = @"C:\Users\username\Documents\PresentationFromFilename.pptx";
+ CreatePresentation(filepath);
+ }
+
+ public static void CreatePresentation(string filepath)
+ {
+ // Create a presentation at a specified file path. The presentation document type is pptx, by default.
+ PresentationDocument presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation);
+ PresentationPart presentationPart = presentationDoc.AddPresentationPart();
+ presentationPart.Presentation = new Presentation();
+
+ CreatePresentationParts(presentationPart);
+
+ //Dispose the presentation handle
+ presentationDoc.Dispose();
+ }
+
+ private static void CreatePresentationParts(PresentationPart presentationPart)
+ {
+ SlideMasterIdList slideMasterIdList1 = new SlideMasterIdList(new SlideMasterId() { Id = (UInt32Value)2147483648U, RelationshipId = "rId1" });
+ SlideIdList slideIdList1 = new SlideIdList(new SlideId() { Id = (UInt32Value)256U, RelationshipId = "rId2" });
+ SlideSize slideSize1 = new SlideSize() { Cx = 9144000, Cy = 6858000, Type = SlideSizeValues.Screen4x3 };
+ NotesSize notesSize1 = new NotesSize() { Cx = 6858000, Cy = 9144000 };
+ DefaultTextStyle defaultTextStyle1 = new DefaultTextStyle();
+
+ presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1);
+
+ SlidePart slidePart1;
+ SlideLayoutPart slideLayoutPart1;
+ SlideMasterPart slideMasterPart1;
+ ThemePart themePart1;
+
+
+ slidePart1 = CreateSlidePart(presentationPart);
+ slideLayoutPart1 = CreateSlideLayoutPart(slidePart1);
+ slideMasterPart1 = CreateSlideMasterPart(slideLayoutPart1);
+ themePart1 = CreateTheme(slideMasterPart1);
+
+ slideMasterPart1.AddPart(slideLayoutPart1, "rId1");
+ presentationPart.AddPart(slideMasterPart1, "rId1");
+ presentationPart.AddPart(themePart1, "rId5");
+ }
+
+ private static SlidePart CreateSlidePart(PresentationPart presentationPart)
+ {
+ SlidePart slidePart1 = presentationPart.AddNewPart("rId2");
+ slidePart1.Slide = new Slide(
+ new CommonSlideData(
+ new ShapeTree(
+ new P.NonVisualGroupShapeProperties(
+ new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
+ new P.NonVisualGroupShapeDrawingProperties(),
+ new ApplicationNonVisualDrawingProperties()),
+ new GroupShapeProperties(new TransformGroup()),
+ new P.Shape(
+ new P.NonVisualShapeProperties(
+ new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
+ new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
+ new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
+ new P.ShapeProperties(),
+ new P.TextBody(
+ new BodyProperties(),
+ new ListStyle(),
+ new Paragraph(new EndParagraphRunProperties() { Language = "en-US" }))))),
+ new ColorMapOverride(new MasterColorMapping()));
+ return slidePart1;
+ }
+
+ private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
+ {
+ SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart("rId1");
+ SlideLayout slideLayout = new SlideLayout(
+ new CommonSlideData(new ShapeTree(
+ new P.NonVisualGroupShapeProperties(
+ new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
+ new P.NonVisualGroupShapeDrawingProperties(),
+ new ApplicationNonVisualDrawingProperties()),
+ new GroupShapeProperties(new TransformGroup()),
+ new P.Shape(
+ new P.NonVisualShapeProperties(
+ new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" },
+ new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
+ new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
+ new P.ShapeProperties(),
+ new P.TextBody(
+ new BodyProperties(),
+ new ListStyle(),
+ new Paragraph(new EndParagraphRunProperties()))))),
+ new ColorMapOverride(new MasterColorMapping()));
+ slideLayoutPart1.SlideLayout = slideLayout;
+ return slideLayoutPart1;
+ }
+
+ private static SlideMasterPart CreateSlideMasterPart(SlideLayoutPart slideLayoutPart1)
+ {
+ SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart("rId1");
+ SlideMaster slideMaster = new SlideMaster(
+ new CommonSlideData(new ShapeTree(
+ new P.NonVisualGroupShapeProperties(
+ new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
+ new P.NonVisualGroupShapeDrawingProperties(),
+ new ApplicationNonVisualDrawingProperties()),
+ new GroupShapeProperties(new TransformGroup()),
+ new P.Shape(
+ new P.NonVisualShapeProperties(
+ new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title Placeholder 1" },
+ new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
+ new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Title })),
+ new P.ShapeProperties(),
+ new P.TextBody(
+ new BodyProperties(),
+ new ListStyle(),
+ new Paragraph())))),
+ new P.ColorMap() { Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink },
+ new SlideLayoutIdList(new SlideLayoutId() { Id = (UInt32Value)2147483649U, RelationshipId = "rId1" }),
+ new TextStyles(new TitleStyle(), new BodyStyle(), new OtherStyle()));
+ slideMasterPart1.SlideMaster = slideMaster;
+
+ return slideMasterPart1;
+ }
+
+ private static ThemePart CreateTheme(SlideMasterPart slideMasterPart1)
+ {
+ ThemePart themePart1 = slideMasterPart1.AddNewPart("rId5");
+ D.Theme theme1 = new D.Theme() { Name = "Office Theme" };
+
+ D.ThemeElements themeElements1 = new D.ThemeElements(
+ new D.ColorScheme(
+ new D.Dark1Color(new D.SystemColor() { Val = D.SystemColorValues.WindowText, LastColor = "000000" }),
+ new D.Light1Color(new D.SystemColor() { Val = D.SystemColorValues.Window, LastColor = "FFFFFF" }),
+ new D.Dark2Color(new D.RgbColorModelHex() { Val = "1F497D" }),
+ new D.Light2Color(new D.RgbColorModelHex() { Val = "EEECE1" }),
+ new D.Accent1Color(new D.RgbColorModelHex() { Val = "4F81BD" }),
+ new D.Accent2Color(new D.RgbColorModelHex() { Val = "C0504D" }),
+ new D.Accent3Color(new D.RgbColorModelHex() { Val = "9BBB59" }),
+ new D.Accent4Color(new D.RgbColorModelHex() { Val = "8064A2" }),
+ new D.Accent5Color(new D.RgbColorModelHex() { Val = "4BACC6" }),
+ new D.Accent6Color(new D.RgbColorModelHex() { Val = "F79646" }),
+ new D.Hyperlink(new D.RgbColorModelHex() { Val = "0000FF" }),
+ new D.FollowedHyperlinkColor(new D.RgbColorModelHex() { Val = "800080" }))
+ { Name = "Office" },
+ new D.FontScheme(
+ new D.MajorFont(
+ new D.LatinFont() { Typeface = "Calibri" },
+ new D.EastAsianFont() { Typeface = "" },
+ new D.ComplexScriptFont() { Typeface = "" }),
+ new D.MinorFont(
+ new D.LatinFont() { Typeface = "Calibri" },
+ new D.EastAsianFont() { Typeface = "" },
+ new D.ComplexScriptFont() { Typeface = "" }))
+ { Name = "Office" },
+ new D.FormatScheme(
+ new D.FillStyleList(
+ new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }),
+ new D.GradientFill(
+ new D.GradientStopList(
+ new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 50000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 0 },
+ new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 37000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 35000 },
+ new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 15000 },
+ new D.SaturationModulation() { Val = 350000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 100000 }
+ ),
+ new D.LinearGradientFill() { Angle = 16200000, Scaled = true }),
+ new D.NoFill(),
+ new D.PatternFill(),
+ new D.GroupFill()),
+ new D.LineStyleList(
+ new D.Outline(
+ new D.SolidFill(
+ new D.SchemeColor(
+ new D.Shade() { Val = 95000 },
+ new D.SaturationModulation() { Val = 105000 })
+ { Val = D.SchemeColorValues.PhColor }),
+ new D.PresetDash() { Val = D.PresetLineDashValues.Solid })
+ {
+ Width = 9525,
+ CapType = D.LineCapValues.Flat,
+ CompoundLineType = D.CompoundLineValues.Single,
+ Alignment = D.PenAlignmentValues.Center
+ },
+ new D.Outline(
+ new D.SolidFill(
+ new D.SchemeColor(
+ new D.Shade() { Val = 95000 },
+ new D.SaturationModulation() { Val = 105000 })
+ { Val = D.SchemeColorValues.PhColor }),
+ new D.PresetDash() { Val = D.PresetLineDashValues.Solid })
+ {
+ Width = 9525,
+ CapType = D.LineCapValues.Flat,
+ CompoundLineType = D.CompoundLineValues.Single,
+ Alignment = D.PenAlignmentValues.Center
+ },
+ new D.Outline(
+ new D.SolidFill(
+ new D.SchemeColor(
+ new D.Shade() { Val = 95000 },
+ new D.SaturationModulation() { Val = 105000 })
+ { Val = D.SchemeColorValues.PhColor }),
+ new D.PresetDash() { Val = D.PresetLineDashValues.Solid })
+ {
+ Width = 9525,
+ CapType = D.LineCapValues.Flat,
+ CompoundLineType = D.CompoundLineValues.Single,
+ Alignment = D.PenAlignmentValues.Center
+ }),
+ new D.EffectStyleList(
+ new D.EffectStyle(
+ new D.EffectList(
+ new D.OuterShadow(
+ new D.RgbColorModelHex(
+ new D.Alpha() { Val = 38000 })
+ { Val = "000000" })
+ { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })),
+ new D.EffectStyle(
+ new D.EffectList(
+ new D.OuterShadow(
+ new D.RgbColorModelHex(
+ new D.Alpha() { Val = 38000 })
+ { Val = "000000" })
+ { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })),
+ new D.EffectStyle(
+ new D.EffectList(
+ new D.OuterShadow(
+ new D.RgbColorModelHex(
+ new D.Alpha() { Val = 38000 })
+ { Val = "000000" })
+ { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false }))),
+ new D.BackgroundFillStyleList(
+ new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }),
+ new D.GradientFill(
+ new D.GradientStopList(
+ new D.GradientStop(
+ new D.SchemeColor(new D.Tint() { Val = 50000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 0 },
+ new D.GradientStop(
+ new D.SchemeColor(new D.Tint() { Val = 50000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 0 },
+ new D.GradientStop(
+ new D.SchemeColor(new D.Tint() { Val = 50000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 0 }),
+ new D.LinearGradientFill() { Angle = 16200000, Scaled = true }),
+ new D.GradientFill(
+ new D.GradientStopList(
+ new D.GradientStop(
+ new D.SchemeColor(new D.Tint() { Val = 50000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 0 },
+ new D.GradientStop(
+ new D.SchemeColor(new D.Tint() { Val = 50000 },
+ new D.SaturationModulation() { Val = 300000 })
+ { Val = D.SchemeColorValues.PhColor })
+ { Position = 0 }),
+ new D.LinearGradientFill() { Angle = 16200000, Scaled = true })))
+ { Name = "Office" });
+
+ theme1.Append(themeElements1);
+ theme1.Append(new D.ObjectDefaults());
+ theme1.Append(new D.ExtraColorSchemeList());
+
+ themePart1.Theme = theme1;
+ return themePart1;
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/presentation/create_by_providing_a_file_name/cs/create_by_providing_a_file_name_cs.csproj b/samples/presentation/create_by_providing_a_file_name/cs/create_by_providing_a_file_name_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/presentation/create_by_providing_a_file_name/cs/create_by_providing_a_file_name_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/presentation/create_by_providing_a_file_name/vb/Program.vb b/samples/presentation/create_by_providing_a_file_name/vb/Program.vb
new file mode 100644
index 00000000..b19d40cf
--- /dev/null
+++ b/samples/presentation/create_by_providing_a_file_name/vb/Program.vb
@@ -0,0 +1,340 @@
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Drawing
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Presentation
+Imports D = DocumentFormat.OpenXml.Drawing
+Imports P = DocumentFormat.OpenXml.Presentation
+
+Namespace CreatePresentationDocument
+ Class Program
+ Public Shared Sub Main(ByVal args As String())
+
+ Dim filepath As String = "C:\Users\username\Documents\PresentationFromFilename.pptx"
+ CreatePresentation(filepath)
+
+ End Sub
+
+ Public Shared Sub CreatePresentation(ByVal filepath As String)
+ ' Create a presentation at a specified file path. The presentation document type is pptx, by default.
+ Dim presentationDoc As PresentationDocument = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation)
+ Dim presentationPart As PresentationPart = presentationDoc.AddPresentationPart()
+ presentationPart.Presentation = New Presentation()
+
+ CreatePresentationParts(presentationPart)
+
+ 'Dispose the presentation handle
+ presentationDoc.Dispose()
+ End Sub
+
+ Private Shared Sub CreatePresentationParts(ByVal presentationPart As PresentationPart)
+ Dim slideMasterIdList1 As New SlideMasterIdList(New SlideMasterId() With {
+ .Id = CType(2147483648UI, UInt32Value),
+ .RelationshipId = "rId1"
+ })
+ Dim slideIdList1 As New SlideIdList(New SlideId() With {
+ .Id = CType(256UI, UInt32Value), .RelationshipId = "rId2"
+ })
+ Dim slideSize1 As New SlideSize() With {
+ .Cx = 9144000,
+ .Cy = 6858000,
+ .Type = SlideSizeValues.Screen4x3
+ }
+ Dim notesSize1 As New NotesSize() With {
+ .Cx = 6858000,
+ .Cy = 9144000
+ }
+ Dim defaultTextStyle1 As New DefaultTextStyle()
+
+ Dim slidePart1 As SlidePart
+ Dim slideLayoutPart1 As SlideLayoutPart
+ Dim slideMasterPart1 As SlideMasterPart
+ Dim themePart1 As ThemePart
+
+ presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1)
+
+ slidePart1 = CreateSlidePart(presentationPart)
+ slideLayoutPart1 = CreateSlideLayoutPart(slidePart1)
+ slideMasterPart1 = CreateSlideMasterPart(slideLayoutPart1)
+ themePart1 = CreateTheme(slideMasterPart1)
+
+ slideMasterPart1.AddPart(slideLayoutPart1, "rId1")
+ presentationPart.AddPart(slideMasterPart1, "rId1")
+ presentationPart.AddPart(themePart1, "rId5")
+ End Sub
+
+ Private Shared Function CreateSlidePart(ByVal presentationPart As PresentationPart) As SlidePart
+ Dim slidePart1 As SlidePart = presentationPart.AddNewPart(Of SlidePart)("rId2")
+ slidePart1.Slide = New Slide(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With {
+ .Id = CType(1UI, UInt32Value),
+ .Name = ""
+ }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()), New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With {
+ .Id = CType(2UI, UInt32Value),
+ .Name = "Title 1"
+ }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With {
+ .NoGrouping = True
+ }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New P.TextBody(New BodyProperties(), New ListStyle(), New Paragraph(New EndParagraphRunProperties() With {
+ .Language = "en-US"
+ }))))), New ColorMapOverride(New MasterColorMapping()))
+ Return slidePart1
+ End Function
+
+ Private Shared Function CreateSlideLayoutPart(ByVal slidePart1 As SlidePart) As SlideLayoutPart
+ Dim slideLayoutPart1 As SlideLayoutPart = slidePart1.AddNewPart(Of SlideLayoutPart)("rId1")
+ Dim slideLayout As New SlideLayout(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With {
+ .Id = CType(1UI, UInt32Value),
+ .Name = ""
+ }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()),
+ New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With {
+ .Id = CType(2UI, UInt32Value),
+ .Name = ""
+ }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With {
+ .NoGrouping = True
+ }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New P.TextBody(New BodyProperties(),
+ New ListStyle(), New Paragraph(New EndParagraphRunProperties()))))), New ColorMapOverride(New MasterColorMapping()))
+ slideLayoutPart1.SlideLayout = slideLayout
+ Return slideLayoutPart1
+ End Function
+
+ Private Shared Function CreateSlideMasterPart(ByVal slideLayoutPart1 As SlideLayoutPart) As SlideMasterPart
+ Dim slideMasterPart1 As SlideMasterPart = slideLayoutPart1.AddNewPart(Of SlideMasterPart)("rId1")
+ Dim slideMaster As New SlideMaster(New CommonSlideData(New ShapeTree(New P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With {
+ .Id = CType(1UI, UInt32Value),
+ .Name = ""
+ }, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()),
+ New GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With {
+ .Id = CType(2UI, UInt32Value),
+ .Name = "Title Placeholder 1"
+ }, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With {
+ .NoGrouping = True
+ }), New ApplicationNonVisualDrawingProperties(New PlaceholderShape() With {
+ .Type = PlaceholderValues.Title
+ })), New P.ShapeProperties(), New P.TextBody(New BodyProperties(), New ListStyle(), New Paragraph())))), New P.ColorMap() With {
+ .Background1 = D.ColorSchemeIndexValues.Light1,
+ .Text1 = D.ColorSchemeIndexValues.Dark1,
+ .Background2 = D.ColorSchemeIndexValues.Light2,
+ .Text2 = D.ColorSchemeIndexValues.Dark2,
+ .Accent1 = D.ColorSchemeIndexValues.Accent1,
+ .Accent2 = D.ColorSchemeIndexValues.Accent2,
+ .Accent3 = D.ColorSchemeIndexValues.Accent3,
+ .Accent4 = D.ColorSchemeIndexValues.Accent4,
+ .Accent5 = D.ColorSchemeIndexValues.Accent5,
+ .Accent6 = D.ColorSchemeIndexValues.Accent6,
+ .Hyperlink = D.ColorSchemeIndexValues.Hyperlink,
+ .FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink
+ }, New SlideLayoutIdList(New SlideLayoutId() With {
+ .Id = CType(2147483649UI, UInt32Value),
+ .RelationshipId = "rId1"
+ }), New TextStyles(New TitleStyle(), New BodyStyle(), New OtherStyle()))
+ slideMasterPart1.SlideMaster = slideMaster
+
+ Return slideMasterPart1
+ End Function
+
+ Private Shared Function CreateTheme(ByVal slideMasterPart1 As SlideMasterPart) As ThemePart
+ Dim themePart1 As ThemePart = slideMasterPart1.AddNewPart(Of ThemePart)("rId5")
+ Dim theme1 As New D.Theme() With {
+ .Name = "Office Theme"
+ }
+
+ Dim themeElements1 As New D.ThemeElements(New D.ColorScheme(New D.Dark1Color(New D.SystemColor() With {
+ .Val = D.SystemColorValues.WindowText,
+ .LastColor = "000000"
+ }), New D.Light1Color(New D.SystemColor() With {
+ .Val = D.SystemColorValues.Window,
+ .LastColor = "FFFFFF"
+ }), New D.Dark2Color(New D.RgbColorModelHex() With {
+ .Val = "1F497D"
+ }), New D.Light2Color(New D.RgbColorModelHex() With {
+ .Val = "EEECE1"
+ }), New D.Accent1Color(New D.RgbColorModelHex() With {
+ .Val = "4F81BD"
+ }), New D.Accent2Color(New D.RgbColorModelHex() With {
+ .Val = "C0504D"
+ }),
+ New D.Accent3Color(New D.RgbColorModelHex() With {
+ .Val = "9BBB59"
+ }), New D.Accent4Color(New D.RgbColorModelHex() With {
+ .Val = "8064A2"
+ }), New D.Accent5Color(New D.RgbColorModelHex() With {
+ .Val = "4BACC6"
+ }), New D.Accent6Color(New D.RgbColorModelHex() With {
+ .Val = "F79646"
+ }), New D.Hyperlink(New D.RgbColorModelHex() With {
+ .Val = "0000FF"
+ }), New D.FollowedHyperlinkColor(New D.RgbColorModelHex() With {
+ .Val = "800080"
+ })) With {
+ .Name = "Office"
+ }, New D.FontScheme(New D.MajorFont(New D.LatinFont() With {
+ .Typeface = "Calibri"
+ }, New D.EastAsianFont() With {
+ .Typeface = ""
+ }, New D.ComplexScriptFont() With {
+ .Typeface = ""
+ }), New D.MinorFont(New D.LatinFont() With {
+ .Typeface = "Calibri"
+ }, New D.EastAsianFont() With {
+ .Typeface = ""
+ }, New D.ComplexScriptFont() With {
+ .Typeface = ""
+ })) With {
+ .Name = "Office"
+ }, New D.FormatScheme(New D.FillStyleList(New D.SolidFill(New D.SchemeColor() With {
+ .Val = D.SchemeColorValues.PhColor
+ }), New D.GradientFill(New D.GradientStopList(New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 50000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 0
+ }, New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 37000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 35000
+ }, New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 15000
+ }, New D.SaturationModulation() With {
+ .Val = 350000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 100000
+ }), New D.LinearGradientFill() With {
+ .Angle = 16200000,
+ .Scaled = True
+ }), New D.NoFill(), New D.PatternFill(), New D.GroupFill()), New D.LineStyleList(New D.Outline(New D.SolidFill(New D.SchemeColor(New D.Shade() With {
+ .Val = 95000
+ }, New D.SaturationModulation() With {
+ .Val = 105000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }), New D.PresetDash() With {
+ .Val = D.PresetLineDashValues.Solid
+ }) With {
+ .Width = 9525,
+ .CapType = D.LineCapValues.Flat,
+ .CompoundLineType = D.CompoundLineValues.[Single],
+ .Alignment = D.PenAlignmentValues.Center
+ }, New D.Outline(New D.SolidFill(New D.SchemeColor(New D.Shade() With {
+ .Val = 95000
+ }, New D.SaturationModulation() With {
+ .Val = 105000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }), New D.PresetDash() With {
+ .Val = D.PresetLineDashValues.Solid
+ }) With {
+ .Width = 9525,
+ .CapType = D.LineCapValues.Flat,
+ .CompoundLineType = D.CompoundLineValues.[Single],
+ .Alignment = D.PenAlignmentValues.Center
+ }, New D.Outline(New D.SolidFill(New D.SchemeColor(New D.Shade() With {
+ .Val = 95000
+ }, New D.SaturationModulation() With {
+ .Val = 105000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }), New D.PresetDash() With {
+ .Val = D.PresetLineDashValues.Solid
+ }) With {
+ .Width = 9525,
+ .CapType = D.LineCapValues.Flat,
+ .CompoundLineType = D.CompoundLineValues.[Single],
+ .Alignment = D.PenAlignmentValues.Center
+ }), New D.EffectStyleList(New D.EffectStyle(New D.EffectList(New D.OuterShadow(New D.RgbColorModelHex(New D.Alpha() With {
+ .Val = 38000
+ }) With {
+ .Val = "000000"
+ }) With {
+ .BlurRadius = 40000L,
+ .Distance = 20000L,
+ .Direction = 5400000,
+ .RotateWithShape = False
+ })), New D.EffectStyle(New D.EffectList(New D.OuterShadow(New D.RgbColorModelHex(New D.Alpha() With {
+ .Val = 38000
+ }) With {
+ .Val = "000000"
+ }) With {
+ .BlurRadius = 40000L,
+ .Distance = 20000L,
+ .Direction = 5400000,
+ .RotateWithShape = False
+ })), New D.EffectStyle(New D.EffectList(New D.OuterShadow(New D.RgbColorModelHex(New D.Alpha() With {
+ .Val = 38000
+ }) With {
+ .Val = "000000"
+ }) With {
+ .BlurRadius = 40000L,
+ .Distance = 20000L,
+ .Direction = 5400000,
+ .RotateWithShape = False
+ }))), New D.BackgroundFillStyleList(New D.SolidFill(New D.SchemeColor() With {
+ .Val = D.SchemeColorValues.PhColor
+ }), New D.GradientFill(New D.GradientStopList(New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 50000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 0
+ }, New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 50000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 0
+ }, New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 50000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 0
+ }), New D.LinearGradientFill() With {
+ .Angle = 16200000,
+ .Scaled = True
+ }), New D.GradientFill(New D.GradientStopList(New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 50000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 0
+ }, New D.GradientStop(New D.SchemeColor(New D.Tint() With {
+ .Val = 50000
+ }, New D.SaturationModulation() With {
+ .Val = 300000
+ }) With {
+ .Val = D.SchemeColorValues.PhColor
+ }) With {
+ .Position = 0
+ }), New D.LinearGradientFill() With {
+ .Angle = 16200000,
+ .Scaled = True
+ }))) With {
+ .Name = "Office"
+ })
+
+ theme1.Append(themeElements1)
+ theme1.Append(New D.ObjectDefaults())
+ theme1.Append(New D.ExtraColorSchemeList())
+
+ themePart1.Theme = theme1
+ Return themePart1
+
+ End Function
+
+ End Class
+
+End Namespace
diff --git a/samples/presentation/create_by_providing_a_file_name/vb/create_by_providing_a_file_name_vb.vbproj b/samples/presentation/create_by_providing_a_file_name/vb/create_by_providing_a_file_name_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/presentation/create_by_providing_a_file_name/vb/create_by_providing_a_file_name_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/presentation/retrieve_the_number_of_slides/cs/Program.cs b/samples/presentation/retrieve_the_number_of_slides/cs/Program.cs
new file mode 100644
index 00000000..f87499df
--- /dev/null
+++ b/samples/presentation/retrieve_the_number_of_slides/cs/Program.cs
@@ -0,0 +1,37 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using System;
+using System.Linq;
+
+static int RetrieveNumberOfSlides(string fileName,
+ bool includeHidden = true)
+{
+ int slidesCount = 0;
+
+ using (PresentationDocument doc =
+ PresentationDocument.Open(fileName, false))
+ {
+ // Get the presentation part of the document.
+ PresentationPart presentationPart = doc.PresentationPart;
+ if (presentationPart != null)
+ {
+ if (includeHidden)
+ {
+ slidesCount = presentationPart.SlideParts.Count();
+ }
+ else
+ {
+ // Each slide can include a Show property, which if hidden
+ // will contain the value "0". The Show property may not
+ // exist, and most likely will not, for non-hidden slides.
+ var slides = presentationPart.SlideParts.Where(
+ (s) => (s.Slide != null) &&
+ ((s.Slide.Show == null) || (s.Slide.Show.HasValue &&
+ s.Slide.Show.Value)));
+ slidesCount = slides.Count();
+ }
+ }
+ }
+ return slidesCount;
+}
\ No newline at end of file
diff --git a/samples/presentation/retrieve_the_number_of_slides/cs/retrieve_the_number_of_slides_cs.csproj b/samples/presentation/retrieve_the_number_of_slides/cs/retrieve_the_number_of_slides_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/presentation/retrieve_the_number_of_slides/cs/retrieve_the_number_of_slides_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/presentation/retrieve_the_number_of_slides/vb/Program.vb b/samples/presentation/retrieve_the_number_of_slides/vb/Program.vb
new file mode 100644
index 00000000..811b36b2
--- /dev/null
+++ b/samples/presentation/retrieve_the_number_of_slides/vb/Program.vb
@@ -0,0 +1,35 @@
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Function RetrieveNumberOfSlides(ByVal fileName As String,
+ Optional ByVal includeHidden As Boolean = True) As Integer
+ Dim slidesCount As Integer = 0
+
+ Using doc As PresentationDocument =
+ PresentationDocument.Open(fileName, False)
+ ' Get the presentation part of the document.
+ Dim presentationPart As PresentationPart = doc.PresentationPart
+ If presentationPart IsNot Nothing Then
+ If includeHidden Then
+ slidesCount = presentationPart.SlideParts.Count()
+ Else
+ ' Each slide can include a Show property, which if
+ ' hidden will contain the value "0". The Show property may
+ ' not exist, and most likely will not, for non-hidden slides.
+ Dim slides = presentationPart.SlideParts.
+ Where(Function(s) (s.Slide IsNot Nothing) AndAlso
+ ((s.Slide.Show Is Nothing) OrElse
+ (s.Slide.Show.HasValue AndAlso
+ s.Slide.Show.Value)))
+ slidesCount = slides.Count()
+ End If
+ End If
+ End Using
+ Return slidesCount
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/presentation/retrieve_the_number_of_slides/vb/retrieve_the_number_of_slides_vb.vbproj b/samples/presentation/retrieve_the_number_of_slides/vb/retrieve_the_number_of_slides_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/presentation/retrieve_the_number_of_slides/vb/retrieve_the_number_of_slides_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/samples.sln b/samples/samples.sln
index e7daa0f9..e31e386b 100644
--- a/samples/samples.sln
+++ b/samples/samples.sln
@@ -15,7 +15,154 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "add_comment_cs", "presentat
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "add_comment_vb", "presentation\add_comment\vb\add_comment_vb.vbproj", "{F5204024-B0D0-4106-AE8B-8CB1552C1F87}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "migrator", "tools\migrator\migrator.csproj", "{0470C4B3-18CE-4621-A41C-A1C70DDF8EAD}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "migrator", "tools\migrator\migrator.csproj", "{0470C4B3-18CE-4621-A41C-A1C70DDF8EAD}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "spreadsheet", "spreadsheet", "{7ACDC26B-C774-4004-8553-87E862D1E71F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "add_custom_ui_cs", "spreadsheet\add_custom_ui\cs\add_custom_ui_cs.csproj", "{29E66A2F-4AA6-4AE3-B0FC-AE3376004D34}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "add_custom_ui_vb", "spreadsheet\add_custom_ui\vb\add_custom_ui_vb.vbproj", "{ACDDC408-5095-4300-91A8-A026936E370A}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "add_tables_cs", "word\add_tables\cs\add_tables_cs.csproj", "{88B852C2-60AE-49AB-BD54-711B6FDEB4A4}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "add_tables_vb", "word\add_tables\vb\add_tables_vb.vbproj", "{6F5CF9FC-02AD-476B-B580-4D6A61B8728D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "change_text_a_table_cs", "word\change_text_a_table\cs\change_text_a_table_cs.csproj", "{D0165B95-1EF5-4510-A23E-CE1A5DD94C73}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "change_text_a_table_vb", "word\change_text_a_table\vb\change_text_a_table_vb.vbproj", "{97F968C3-CD44-4703-B103-AF5BAE50A576}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "change_the_fill_color_of_a_shape_cs", "presentation\change_the_fill_color_of_a_shape\cs\change_the_fill_color_of_a_shape_cs.csproj", "{51FC11CF-9386-4C10-BB79-3171662DA20D}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "change_the_fill_color_of_a_shape_vb", "presentation\change_the_fill_color_of_a_shape\vb\change_the_fill_color_of_a_shape_vb.vbproj", "{37A2DA75-58D9-49CA-8EE6-43BA43DC82B6}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "change_the_print_orientation_cs", "word\change_the_print_orientation\cs\change_the_print_orientation_cs.csproj", "{43E06191-76C0-4712-B3CF-8E12CC8F42B2}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "change_the_print_orientation_vb", "word\change_the_print_orientation\vb\change_the_print_orientation_vb.vbproj", "{B75C407E-0421-42FA-A6EE-FE862CBC3D08}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "convert_from_the_docm_to_the_docx_file_format_cs", "word\convert_from_the_docm_to_the_docx_file_format\cs\convert_from_the_docm_to_the_docx_file_format_cs.csproj", "{E9BF7E13-BB77-4490-8419-9D61B15A18A5}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "convert_from_the_docm_to_the_docx_file_format_vb", "word\convert_from_the_docm_to_the_docx_file_format\vb\convert_from_the_docm_to_the_docx_file_format_vb.vbproj", "{7BE20721-C670-448F-AEFB-54BA4366C5A7}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "create_by_providing_a_file_name_cs", "presentation\create_by_providing_a_file_name\cs\create_by_providing_a_file_name_cs.csproj", "{66438CBE-181F-4751-B180-EAAC9B19812E}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "create_by_providing_a_file_name_vb", "presentation\create_by_providing_a_file_name\vb\create_by_providing_a_file_name_vb.vbproj", "{26618FBA-A3BB-4057-A80B-240E4C90306F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "create_and_add_a_character_style_cs", "word\create_and_add_a_character_style\cs\create_and_add_a_character_style_cs.csproj", "{A05BCE67-2847-4BA8-8D0F-A5C6476EAEBA}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "create_and_add_a_character_style_vb", "word\create_and_add_a_character_style\vb\create_and_add_a_character_style_vb.vbproj", "{7E3D140B-57EE-4BE3-AB73-D06CC875BAC5}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "create_and_add_a_paragraph_style_cs", "word\create_and_add_a_paragraph_style\cs\create_and_add_a_paragraph_style_cs.csproj", "{EB7A3C49-8516-43AB-8589-41408B238636}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "create_and_add_a_paragraph_style_vb", "word\create_and_add_a_paragraph_style\vb\create_and_add_a_paragraph_style_vb.vbproj", "{67ABA332-E9E8-4FEE-88D5-436AF6E17ACC}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "delete_comments_by_all_or_a_specific_author_cs", "word\delete_comments_by_all_or_a_specific_author\cs\delete_comments_by_all_or_a_specific_author_cs.csproj", "{2D6C4ED6-A22A-4B05-8ED8-26572ABB322B}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "delete_comments_by_all_or_a_specific_author_vb", "word\delete_comments_by_all_or_a_specific_author\vb\delete_comments_by_all_or_a_specific_author_vb.vbproj", "{FDF5EDBB-C4A1-42AA-A0AF-288B13E9ABD1}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "extract_styles_cs", "word\extract_styles\cs\extract_styles_cs.csproj", "{6A3B60EF-CD76-4FAE-96C3-DDF7EEB5886D}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "extract_styles_vb", "word\extract_styles\vb\extract_styles_vb.vbproj", "{D4A479DD-35BF-40CA-A377-0172581852AD}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "insert_a_comment_cs", "word\insert_a_comment\cs\insert_a_comment_cs.csproj", "{0615B916-647D-4176-86AC-60E5B967738C}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "insert_a_comment_vb", "word\insert_a_comment\vb\insert_a_comment_vb.vbproj", "{45F7B93D-20F6-43BF-8AA6-FD0EAA3F58FF}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "insert_a_new_worksheet_cs", "spreadsheet\insert_a_new_worksheet\cs\insert_a_new_worksheet_cs.csproj", "{7825182C-8B6C-493F-9C1F-DD80F8A0EAFD}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "insert_a_new_worksheet_vb", "spreadsheet\insert_a_new_worksheet\vb\insert_a_new_worksheet_vb.vbproj", "{B258784B-1568-479F-9B21-9E5045EC75E3}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "insert_a_picture_cs", "word\insert_a_picture\cs\insert_a_picture_cs.csproj", "{F364E5F4-B908-4624-9E1D-86113B032387}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "insert_a_table_cs", "word\insert_a_table\cs\insert_a_table_cs.csproj", "{0913F657-6C2C-49E4-AE25-223B11EB8724}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "insert_a_table_vb", "word\insert_a_table\vb\insert_a_table_vb.vbproj", "{800AB4A5-B593-4B33-A2D4-0CED80253344}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "merge_two_adjacent_cells_cs", "spreadsheet\merge_two_adjacent_cells\cs\merge_two_adjacent_cells_cs.csproj", "{40FB71B1-87F8-4DBE-96B7-043A386C72D9}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "merge_two_adjacent_cells_vb", "spreadsheet\merge_two_adjacent_cells\vb\merge_two_adjacent_cells_vb.vbproj", "{AC58704E-D2BE-43BB-9F80-322349F26802}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "open_for_read_only_access_cs", "spreadsheet\open_for_read_only_access\cs\open_for_read_only_access_cs.csproj", "{BAE86ACC-E06B-4767-9A68-6607C6DA6DF7}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "open_for_read_only_access_vb", "spreadsheet\open_for_read_only_access\vb\open_for_read_only_access_vb.vbproj", "{82E1A22E-18FF-4E5D-8724-27634D0D23DA}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "open_from_a_stream_cs", "spreadsheet\open_from_a_stream\cs\open_from_a_stream_cs.csproj", "{1262A76C-FED4-431B-A1B6-329C3DAD2D03}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "open_from_a_stream_vb", "spreadsheet\open_from_a_stream\vb\open_from_a_stream_vb.vbproj", "{E2100A00-DE49-4E4C-A2A6-304DB0A20423}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "parse_and_read_a_large_spreadsheet_cs", "spreadsheet\parse_and_read_a_large_spreadsheet\cs\parse_and_read_a_large_spreadsheet_cs.csproj", "{6F4298ED-EEFB-4899-8F5B-1F6B1F4C7F4C}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "parse_and_read_a_large_spreadsheet_vb", "spreadsheet\parse_and_read_a_large_spreadsheet\vb\parse_and_read_a_large_spreadsheet_vb.vbproj", "{41FE579B-E3E2-4E43-A246-81C702DB09C3}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "remove_hidden_text_cs", "word\remove_hidden_text\cs\remove_hidden_text_cs.csproj", "{16D1B230-A352-4341-B143-1EE39F32F45E}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "remove_hidden_text_vb", "word\remove_hidden_text\vb\remove_hidden_text_vb.vbproj", "{D156A91E-C79A-4735-AFF1-E2C836E261F7}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "remove_the_headers_and_footers_cs", "word\remove_the_headers_and_footers\cs\remove_the_headers_and_footers_cs.csproj", "{D6F0121C-A9B2-401C-B458-481286E98818}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "remove_the_headers_and_footers_vb", "word\remove_the_headers_and_footers\vb\remove_the_headers_and_footers_vb.vbproj", "{9EE65ED2-C97B-4015-8293-ED79B29C1608}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "replace_the_header_cs", "word\replace_the_header\cs\replace_the_header_cs.csproj", "{E7D4CECE-39DB-4EE7-B4C9-83FBC89B8903}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "replace_the_header_vb", "word\replace_the_header\vb\replace_the_header_vb.vbproj", "{72BB1EBA-2168-4C1B-9F8A-E6CE4CB14920}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "replace_the_styles_parts_cs", "word\replace_the_styles_parts\cs\replace_the_styles_parts_cs.csproj", "{DA1D02A7-801C-49EE-B300-79CFDC8BFF66}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "replace_the_styles_parts_vb", "word\replace_the_styles_parts\vb\replace_the_styles_parts_vb.vbproj", "{F8004D45-99F4-45B0-B2CF-539A4C65D7EC}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "replace_the_theme_part_cs", "word\replace_the_theme_part\cs\replace_the_theme_part_cs.csproj", "{C0564907-D3BE-478E-B936-C55E4E745EBC}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "replace_the_theme_part_vb", "word\replace_the_theme_part\vb\replace_the_theme_part_vb.vbproj", "{906B7316-6E97-4E92-9E0E-1BDF8FCD49D0}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_a_dictionary_of_all_named_ranges_cs", "spreadsheet\retrieve_a_dictionary_of_all_named_ranges\cs\retrieve_a_dictionary_of_all_named_ranges_cs.csproj", "{EEEB9B22-F363-477C-935C-139E01F79AF1}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_a_dictionary_of_all_named_ranges_vb", "spreadsheet\retrieve_a_dictionary_of_all_named_ranges\vb\retrieve_a_dictionary_of_all_named_ranges_vb.vbproj", "{5757C767-600D-4911-9167-5C1B7D17018B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_a_list_of_the_hidden_rows_or_columns_cs", "spreadsheet\retrieve_a_list_of_the_hidden_rows_or_columns\cs\retrieve_a_list_of_the_hidden_rows_or_columns_cs.csproj", "{7DE8E6F7-3493-4BCA-9519-69CE3ED12459}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_a_list_of_the_hidden_rows_or_columns_vb", "spreadsheet\retrieve_a_list_of_the_hidden_rows_or_columns\vb\retrieve_a_list_of_the_hidden_rows_or_columns_vb.vbproj", "{E31B5339-9529-4716-9E7A-D8DA91F023C0}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_a_list_of_the_hidden_worksheets_cs", "spreadsheet\retrieve_a_list_of_the_hidden_worksheets\cs\retrieve_a_list_of_the_hidden_worksheets_cs.csproj", "{E2A68C76-68F5-4FD2-9ED2-80454B69550F}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_a_list_of_the_worksheets_cs", "spreadsheet\retrieve_a_list_of_the_worksheets\cs\retrieve_a_list_of_the_worksheets_cs.csproj", "{3C113EBD-A91B-45D2-BB1F-4C148326C492}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_a_list_of_the_worksheets_vb", "spreadsheet\retrieve_a_list_of_the_worksheets\vb\retrieve_a_list_of_the_worksheets_vb.vbproj", "{69A6E865-50F4-47DE-9B40-27B8D41BA3CE}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_application_property_values_cs", "word\retrieve_application_property_values\cs\retrieve_application_property_values_cs.csproj", "{80EC9377-CD17-4BCD-97E6-EF971ED7CEDF}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_application_property_values_vb", "word\retrieve_application_property_values\vb\retrieve_application_property_values_vb.vbproj", "{5D5EE944-CEFC-49D3-9213-B7AF3AB13220}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_comments_cs", "word\retrieve_comments\cs\retrieve_comments_cs.csproj", "{DF930C62-644D-4F7C-AB12-6909C9CD8FF2}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_comments_vb", "word\retrieve_comments\vb\retrieve_comments_vb.vbproj", "{F4C3D0CB-7BEA-4CDE-99CA-51995AA590CE}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_the_number_of_slides_cs", "presentation\retrieve_the_number_of_slides\cs\retrieve_the_number_of_slides_cs.csproj", "{9AA1CD10-0BF7-412A-AA54-DF59FF5510C8}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_the_number_of_slides_vb", "presentation\retrieve_the_number_of_slides\vb\retrieve_the_number_of_slides_vb.vbproj", "{588BA6E9-92FD-4074-BE0A-3192ABD0D7B6}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "retrieve_the_values_of_cells_cs", "spreadsheet\retrieve_the_values_of_cells\cs\retrieve_the_values_of_cells_cs.csproj", "{FC42866A-6868-4173-9E45-12095CC91A03}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "retrieve_the_values_of_cells_vb", "spreadsheet\retrieve_the_values_of_cells\vb\retrieve_the_values_of_cells_vb.vbproj", "{08FADF41-2082-4A04-8613-659B5624086D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "search_and_replace_text_a_part_cs", "word\search_and_replace_text_a_part\cs\search_and_replace_text_a_part_cs.csproj", "{B4AD7B34-760A-4FD5-878B-1F01AF917D92}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "search_and_replace_text_a_part_vb", "word\search_and_replace_text_a_part\vb\search_and_replace_text_a_part_vb.vbproj", "{D0C6147C-EE5A-45F6-8CEA-A5E2AA560098}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "set_a_custom_property_cs", "word\set_a_custom_property\cs\set_a_custom_property_cs.csproj", "{45133FD5-04AE-43C1-A556-D09CADD354D4}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "set_a_custom_property_vb", "word\set_a_custom_property\vb\set_a_custom_property_vb.vbproj", "{787D75FD-9C9F-43C9-A09B-29ED587EFECA}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "set_the_font_for_a_text_run_cs", "word\set_the_font_for_a_text_run\cs\set_the_font_for_a_text_run_cs.csproj", "{D3D354F1-9DAE-4F5C-A0A8-68CF92A53900}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "set_the_font_for_a_text_run_vb", "word\set_the_font_for_a_text_run\vb\set_the_font_for_a_text_run_vb.vbproj", "{A8945DA0-1FA0-4191-BF25-83A91DD8BD6E}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "validate_cs", "word\validate\cs\validate_cs.csproj", "{DD7FD3A1-F42C-4DD7-8993-D4E86473D304}"
+EndProject
+Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "validate_vb", "word\validate\vb\validate_vb.vbproj", "{7B84F55C-56BE-4FDA-9639-62367246F22D}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AD0206D0-5EBF-41E8-A138-12A485DC7932}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -43,6 +190,286 @@ Global
{0470C4B3-18CE-4621-A41C-A1C70DDF8EAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0470C4B3-18CE-4621-A41C-A1C70DDF8EAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0470C4B3-18CE-4621-A41C-A1C70DDF8EAD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {29E66A2F-4AA6-4AE3-B0FC-AE3376004D34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {29E66A2F-4AA6-4AE3-B0FC-AE3376004D34}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {29E66A2F-4AA6-4AE3-B0FC-AE3376004D34}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {29E66A2F-4AA6-4AE3-B0FC-AE3376004D34}.Release|Any CPU.Build.0 = Release|Any CPU
+ {ACDDC408-5095-4300-91A8-A026936E370A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ACDDC408-5095-4300-91A8-A026936E370A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ACDDC408-5095-4300-91A8-A026936E370A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ACDDC408-5095-4300-91A8-A026936E370A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {88B852C2-60AE-49AB-BD54-711B6FDEB4A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {88B852C2-60AE-49AB-BD54-711B6FDEB4A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {88B852C2-60AE-49AB-BD54-711B6FDEB4A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {88B852C2-60AE-49AB-BD54-711B6FDEB4A4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6F5CF9FC-02AD-476B-B580-4D6A61B8728D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6F5CF9FC-02AD-476B-B580-4D6A61B8728D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6F5CF9FC-02AD-476B-B580-4D6A61B8728D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6F5CF9FC-02AD-476B-B580-4D6A61B8728D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D0165B95-1EF5-4510-A23E-CE1A5DD94C73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D0165B95-1EF5-4510-A23E-CE1A5DD94C73}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D0165B95-1EF5-4510-A23E-CE1A5DD94C73}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D0165B95-1EF5-4510-A23E-CE1A5DD94C73}.Release|Any CPU.Build.0 = Release|Any CPU
+ {97F968C3-CD44-4703-B103-AF5BAE50A576}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {97F968C3-CD44-4703-B103-AF5BAE50A576}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {97F968C3-CD44-4703-B103-AF5BAE50A576}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {97F968C3-CD44-4703-B103-AF5BAE50A576}.Release|Any CPU.Build.0 = Release|Any CPU
+ {51FC11CF-9386-4C10-BB79-3171662DA20D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {51FC11CF-9386-4C10-BB79-3171662DA20D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {51FC11CF-9386-4C10-BB79-3171662DA20D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {51FC11CF-9386-4C10-BB79-3171662DA20D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {37A2DA75-58D9-49CA-8EE6-43BA43DC82B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {37A2DA75-58D9-49CA-8EE6-43BA43DC82B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {37A2DA75-58D9-49CA-8EE6-43BA43DC82B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {37A2DA75-58D9-49CA-8EE6-43BA43DC82B6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {43E06191-76C0-4712-B3CF-8E12CC8F42B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {43E06191-76C0-4712-B3CF-8E12CC8F42B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {43E06191-76C0-4712-B3CF-8E12CC8F42B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {43E06191-76C0-4712-B3CF-8E12CC8F42B2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B75C407E-0421-42FA-A6EE-FE862CBC3D08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B75C407E-0421-42FA-A6EE-FE862CBC3D08}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B75C407E-0421-42FA-A6EE-FE862CBC3D08}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B75C407E-0421-42FA-A6EE-FE862CBC3D08}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E9BF7E13-BB77-4490-8419-9D61B15A18A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E9BF7E13-BB77-4490-8419-9D61B15A18A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E9BF7E13-BB77-4490-8419-9D61B15A18A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E9BF7E13-BB77-4490-8419-9D61B15A18A5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7BE20721-C670-448F-AEFB-54BA4366C5A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7BE20721-C670-448F-AEFB-54BA4366C5A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7BE20721-C670-448F-AEFB-54BA4366C5A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7BE20721-C670-448F-AEFB-54BA4366C5A7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {66438CBE-181F-4751-B180-EAAC9B19812E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {66438CBE-181F-4751-B180-EAAC9B19812E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {66438CBE-181F-4751-B180-EAAC9B19812E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {66438CBE-181F-4751-B180-EAAC9B19812E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {26618FBA-A3BB-4057-A80B-240E4C90306F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {26618FBA-A3BB-4057-A80B-240E4C90306F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {26618FBA-A3BB-4057-A80B-240E4C90306F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {26618FBA-A3BB-4057-A80B-240E4C90306F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A05BCE67-2847-4BA8-8D0F-A5C6476EAEBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A05BCE67-2847-4BA8-8D0F-A5C6476EAEBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A05BCE67-2847-4BA8-8D0F-A5C6476EAEBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A05BCE67-2847-4BA8-8D0F-A5C6476EAEBA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7E3D140B-57EE-4BE3-AB73-D06CC875BAC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7E3D140B-57EE-4BE3-AB73-D06CC875BAC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7E3D140B-57EE-4BE3-AB73-D06CC875BAC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7E3D140B-57EE-4BE3-AB73-D06CC875BAC5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EB7A3C49-8516-43AB-8589-41408B238636}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EB7A3C49-8516-43AB-8589-41408B238636}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EB7A3C49-8516-43AB-8589-41408B238636}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EB7A3C49-8516-43AB-8589-41408B238636}.Release|Any CPU.Build.0 = Release|Any CPU
+ {67ABA332-E9E8-4FEE-88D5-436AF6E17ACC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {67ABA332-E9E8-4FEE-88D5-436AF6E17ACC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {67ABA332-E9E8-4FEE-88D5-436AF6E17ACC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {67ABA332-E9E8-4FEE-88D5-436AF6E17ACC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2D6C4ED6-A22A-4B05-8ED8-26572ABB322B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2D6C4ED6-A22A-4B05-8ED8-26572ABB322B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2D6C4ED6-A22A-4B05-8ED8-26572ABB322B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2D6C4ED6-A22A-4B05-8ED8-26572ABB322B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FDF5EDBB-C4A1-42AA-A0AF-288B13E9ABD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FDF5EDBB-C4A1-42AA-A0AF-288B13E9ABD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FDF5EDBB-C4A1-42AA-A0AF-288B13E9ABD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FDF5EDBB-C4A1-42AA-A0AF-288B13E9ABD1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6A3B60EF-CD76-4FAE-96C3-DDF7EEB5886D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6A3B60EF-CD76-4FAE-96C3-DDF7EEB5886D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6A3B60EF-CD76-4FAE-96C3-DDF7EEB5886D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6A3B60EF-CD76-4FAE-96C3-DDF7EEB5886D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D4A479DD-35BF-40CA-A377-0172581852AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D4A479DD-35BF-40CA-A377-0172581852AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D4A479DD-35BF-40CA-A377-0172581852AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D4A479DD-35BF-40CA-A377-0172581852AD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0615B916-647D-4176-86AC-60E5B967738C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0615B916-647D-4176-86AC-60E5B967738C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0615B916-647D-4176-86AC-60E5B967738C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0615B916-647D-4176-86AC-60E5B967738C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {45F7B93D-20F6-43BF-8AA6-FD0EAA3F58FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {45F7B93D-20F6-43BF-8AA6-FD0EAA3F58FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {45F7B93D-20F6-43BF-8AA6-FD0EAA3F58FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {45F7B93D-20F6-43BF-8AA6-FD0EAA3F58FF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7825182C-8B6C-493F-9C1F-DD80F8A0EAFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7825182C-8B6C-493F-9C1F-DD80F8A0EAFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7825182C-8B6C-493F-9C1F-DD80F8A0EAFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7825182C-8B6C-493F-9C1F-DD80F8A0EAFD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B258784B-1568-479F-9B21-9E5045EC75E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B258784B-1568-479F-9B21-9E5045EC75E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B258784B-1568-479F-9B21-9E5045EC75E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B258784B-1568-479F-9B21-9E5045EC75E3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F364E5F4-B908-4624-9E1D-86113B032387}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F364E5F4-B908-4624-9E1D-86113B032387}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F364E5F4-B908-4624-9E1D-86113B032387}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F364E5F4-B908-4624-9E1D-86113B032387}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0913F657-6C2C-49E4-AE25-223B11EB8724}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0913F657-6C2C-49E4-AE25-223B11EB8724}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0913F657-6C2C-49E4-AE25-223B11EB8724}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0913F657-6C2C-49E4-AE25-223B11EB8724}.Release|Any CPU.Build.0 = Release|Any CPU
+ {800AB4A5-B593-4B33-A2D4-0CED80253344}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {800AB4A5-B593-4B33-A2D4-0CED80253344}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {800AB4A5-B593-4B33-A2D4-0CED80253344}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {800AB4A5-B593-4B33-A2D4-0CED80253344}.Release|Any CPU.Build.0 = Release|Any CPU
+ {40FB71B1-87F8-4DBE-96B7-043A386C72D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {40FB71B1-87F8-4DBE-96B7-043A386C72D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {40FB71B1-87F8-4DBE-96B7-043A386C72D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {40FB71B1-87F8-4DBE-96B7-043A386C72D9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AC58704E-D2BE-43BB-9F80-322349F26802}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AC58704E-D2BE-43BB-9F80-322349F26802}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AC58704E-D2BE-43BB-9F80-322349F26802}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AC58704E-D2BE-43BB-9F80-322349F26802}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BAE86ACC-E06B-4767-9A68-6607C6DA6DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BAE86ACC-E06B-4767-9A68-6607C6DA6DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BAE86ACC-E06B-4767-9A68-6607C6DA6DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BAE86ACC-E06B-4767-9A68-6607C6DA6DF7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {82E1A22E-18FF-4E5D-8724-27634D0D23DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {82E1A22E-18FF-4E5D-8724-27634D0D23DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {82E1A22E-18FF-4E5D-8724-27634D0D23DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {82E1A22E-18FF-4E5D-8724-27634D0D23DA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1262A76C-FED4-431B-A1B6-329C3DAD2D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1262A76C-FED4-431B-A1B6-329C3DAD2D03}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1262A76C-FED4-431B-A1B6-329C3DAD2D03}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1262A76C-FED4-431B-A1B6-329C3DAD2D03}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E2100A00-DE49-4E4C-A2A6-304DB0A20423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E2100A00-DE49-4E4C-A2A6-304DB0A20423}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E2100A00-DE49-4E4C-A2A6-304DB0A20423}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E2100A00-DE49-4E4C-A2A6-304DB0A20423}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6F4298ED-EEFB-4899-8F5B-1F6B1F4C7F4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6F4298ED-EEFB-4899-8F5B-1F6B1F4C7F4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6F4298ED-EEFB-4899-8F5B-1F6B1F4C7F4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6F4298ED-EEFB-4899-8F5B-1F6B1F4C7F4C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {41FE579B-E3E2-4E43-A246-81C702DB09C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {41FE579B-E3E2-4E43-A246-81C702DB09C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {41FE579B-E3E2-4E43-A246-81C702DB09C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {41FE579B-E3E2-4E43-A246-81C702DB09C3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {16D1B230-A352-4341-B143-1EE39F32F45E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {16D1B230-A352-4341-B143-1EE39F32F45E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {16D1B230-A352-4341-B143-1EE39F32F45E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {16D1B230-A352-4341-B143-1EE39F32F45E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D156A91E-C79A-4735-AFF1-E2C836E261F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D156A91E-C79A-4735-AFF1-E2C836E261F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D156A91E-C79A-4735-AFF1-E2C836E261F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D156A91E-C79A-4735-AFF1-E2C836E261F7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D6F0121C-A9B2-401C-B458-481286E98818}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D6F0121C-A9B2-401C-B458-481286E98818}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D6F0121C-A9B2-401C-B458-481286E98818}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D6F0121C-A9B2-401C-B458-481286E98818}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9EE65ED2-C97B-4015-8293-ED79B29C1608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9EE65ED2-C97B-4015-8293-ED79B29C1608}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9EE65ED2-C97B-4015-8293-ED79B29C1608}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9EE65ED2-C97B-4015-8293-ED79B29C1608}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E7D4CECE-39DB-4EE7-B4C9-83FBC89B8903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E7D4CECE-39DB-4EE7-B4C9-83FBC89B8903}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E7D4CECE-39DB-4EE7-B4C9-83FBC89B8903}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E7D4CECE-39DB-4EE7-B4C9-83FBC89B8903}.Release|Any CPU.Build.0 = Release|Any CPU
+ {72BB1EBA-2168-4C1B-9F8A-E6CE4CB14920}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {72BB1EBA-2168-4C1B-9F8A-E6CE4CB14920}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {72BB1EBA-2168-4C1B-9F8A-E6CE4CB14920}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {72BB1EBA-2168-4C1B-9F8A-E6CE4CB14920}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DA1D02A7-801C-49EE-B300-79CFDC8BFF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DA1D02A7-801C-49EE-B300-79CFDC8BFF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DA1D02A7-801C-49EE-B300-79CFDC8BFF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DA1D02A7-801C-49EE-B300-79CFDC8BFF66}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F8004D45-99F4-45B0-B2CF-539A4C65D7EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F8004D45-99F4-45B0-B2CF-539A4C65D7EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F8004D45-99F4-45B0-B2CF-539A4C65D7EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F8004D45-99F4-45B0-B2CF-539A4C65D7EC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C0564907-D3BE-478E-B936-C55E4E745EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C0564907-D3BE-478E-B936-C55E4E745EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C0564907-D3BE-478E-B936-C55E4E745EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C0564907-D3BE-478E-B936-C55E4E745EBC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {906B7316-6E97-4E92-9E0E-1BDF8FCD49D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {906B7316-6E97-4E92-9E0E-1BDF8FCD49D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {906B7316-6E97-4E92-9E0E-1BDF8FCD49D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {906B7316-6E97-4E92-9E0E-1BDF8FCD49D0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EEEB9B22-F363-477C-935C-139E01F79AF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EEEB9B22-F363-477C-935C-139E01F79AF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EEEB9B22-F363-477C-935C-139E01F79AF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EEEB9B22-F363-477C-935C-139E01F79AF1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5757C767-600D-4911-9167-5C1B7D17018B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5757C767-600D-4911-9167-5C1B7D17018B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5757C767-600D-4911-9167-5C1B7D17018B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5757C767-600D-4911-9167-5C1B7D17018B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7DE8E6F7-3493-4BCA-9519-69CE3ED12459}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7DE8E6F7-3493-4BCA-9519-69CE3ED12459}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7DE8E6F7-3493-4BCA-9519-69CE3ED12459}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7DE8E6F7-3493-4BCA-9519-69CE3ED12459}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E31B5339-9529-4716-9E7A-D8DA91F023C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E31B5339-9529-4716-9E7A-D8DA91F023C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E31B5339-9529-4716-9E7A-D8DA91F023C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E31B5339-9529-4716-9E7A-D8DA91F023C0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E2A68C76-68F5-4FD2-9ED2-80454B69550F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E2A68C76-68F5-4FD2-9ED2-80454B69550F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E2A68C76-68F5-4FD2-9ED2-80454B69550F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E2A68C76-68F5-4FD2-9ED2-80454B69550F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3C113EBD-A91B-45D2-BB1F-4C148326C492}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3C113EBD-A91B-45D2-BB1F-4C148326C492}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3C113EBD-A91B-45D2-BB1F-4C148326C492}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3C113EBD-A91B-45D2-BB1F-4C148326C492}.Release|Any CPU.Build.0 = Release|Any CPU
+ {69A6E865-50F4-47DE-9B40-27B8D41BA3CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {69A6E865-50F4-47DE-9B40-27B8D41BA3CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {69A6E865-50F4-47DE-9B40-27B8D41BA3CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {69A6E865-50F4-47DE-9B40-27B8D41BA3CE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {80EC9377-CD17-4BCD-97E6-EF971ED7CEDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {80EC9377-CD17-4BCD-97E6-EF971ED7CEDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {80EC9377-CD17-4BCD-97E6-EF971ED7CEDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {80EC9377-CD17-4BCD-97E6-EF971ED7CEDF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5D5EE944-CEFC-49D3-9213-B7AF3AB13220}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5D5EE944-CEFC-49D3-9213-B7AF3AB13220}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5D5EE944-CEFC-49D3-9213-B7AF3AB13220}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5D5EE944-CEFC-49D3-9213-B7AF3AB13220}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DF930C62-644D-4F7C-AB12-6909C9CD8FF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DF930C62-644D-4F7C-AB12-6909C9CD8FF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DF930C62-644D-4F7C-AB12-6909C9CD8FF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DF930C62-644D-4F7C-AB12-6909C9CD8FF2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F4C3D0CB-7BEA-4CDE-99CA-51995AA590CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F4C3D0CB-7BEA-4CDE-99CA-51995AA590CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F4C3D0CB-7BEA-4CDE-99CA-51995AA590CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F4C3D0CB-7BEA-4CDE-99CA-51995AA590CE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9AA1CD10-0BF7-412A-AA54-DF59FF5510C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9AA1CD10-0BF7-412A-AA54-DF59FF5510C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9AA1CD10-0BF7-412A-AA54-DF59FF5510C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9AA1CD10-0BF7-412A-AA54-DF59FF5510C8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {588BA6E9-92FD-4074-BE0A-3192ABD0D7B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {588BA6E9-92FD-4074-BE0A-3192ABD0D7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {588BA6E9-92FD-4074-BE0A-3192ABD0D7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {588BA6E9-92FD-4074-BE0A-3192ABD0D7B6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FC42866A-6868-4173-9E45-12095CC91A03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FC42866A-6868-4173-9E45-12095CC91A03}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FC42866A-6868-4173-9E45-12095CC91A03}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FC42866A-6868-4173-9E45-12095CC91A03}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08FADF41-2082-4A04-8613-659B5624086D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08FADF41-2082-4A04-8613-659B5624086D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08FADF41-2082-4A04-8613-659B5624086D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08FADF41-2082-4A04-8613-659B5624086D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B4AD7B34-760A-4FD5-878B-1F01AF917D92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B4AD7B34-760A-4FD5-878B-1F01AF917D92}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B4AD7B34-760A-4FD5-878B-1F01AF917D92}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B4AD7B34-760A-4FD5-878B-1F01AF917D92}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D0C6147C-EE5A-45F6-8CEA-A5E2AA560098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D0C6147C-EE5A-45F6-8CEA-A5E2AA560098}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D0C6147C-EE5A-45F6-8CEA-A5E2AA560098}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D0C6147C-EE5A-45F6-8CEA-A5E2AA560098}.Release|Any CPU.Build.0 = Release|Any CPU
+ {45133FD5-04AE-43C1-A556-D09CADD354D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {45133FD5-04AE-43C1-A556-D09CADD354D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {45133FD5-04AE-43C1-A556-D09CADD354D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {45133FD5-04AE-43C1-A556-D09CADD354D4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {787D75FD-9C9F-43C9-A09B-29ED587EFECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {787D75FD-9C9F-43C9-A09B-29ED587EFECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {787D75FD-9C9F-43C9-A09B-29ED587EFECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {787D75FD-9C9F-43C9-A09B-29ED587EFECA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D3D354F1-9DAE-4F5C-A0A8-68CF92A53900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D3D354F1-9DAE-4F5C-A0A8-68CF92A53900}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D3D354F1-9DAE-4F5C-A0A8-68CF92A53900}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D3D354F1-9DAE-4F5C-A0A8-68CF92A53900}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A8945DA0-1FA0-4191-BF25-83A91DD8BD6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A8945DA0-1FA0-4191-BF25-83A91DD8BD6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A8945DA0-1FA0-4191-BF25-83A91DD8BD6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A8945DA0-1FA0-4191-BF25-83A91DD8BD6E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DD7FD3A1-F42C-4DD7-8993-D4E86473D304}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DD7FD3A1-F42C-4DD7-8993-D4E86473D304}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DD7FD3A1-F42C-4DD7-8993-D4E86473D304}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DD7FD3A1-F42C-4DD7-8993-D4E86473D304}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7B84F55C-56BE-4FDA-9639-62367246F22D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7B84F55C-56BE-4FDA-9639-62367246F22D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7B84F55C-56BE-4FDA-9639-62367246F22D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7B84F55C-56BE-4FDA-9639-62367246F22D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -52,6 +479,76 @@ Global
{E079BD07-B6BB-441C-8FB6-3FFC8B30E6B0} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
{B87B46CC-6642-4754-AA32-2AD057D877DC} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
{F5204024-B0D0-4106-AE8B-8CB1552C1F87} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {29E66A2F-4AA6-4AE3-B0FC-AE3376004D34} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {ACDDC408-5095-4300-91A8-A026936E370A} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {88B852C2-60AE-49AB-BD54-711B6FDEB4A4} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {6F5CF9FC-02AD-476B-B580-4D6A61B8728D} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {D0165B95-1EF5-4510-A23E-CE1A5DD94C73} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {97F968C3-CD44-4703-B103-AF5BAE50A576} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {51FC11CF-9386-4C10-BB79-3171662DA20D} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {37A2DA75-58D9-49CA-8EE6-43BA43DC82B6} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {43E06191-76C0-4712-B3CF-8E12CC8F42B2} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {B75C407E-0421-42FA-A6EE-FE862CBC3D08} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {E9BF7E13-BB77-4490-8419-9D61B15A18A5} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {7BE20721-C670-448F-AEFB-54BA4366C5A7} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {66438CBE-181F-4751-B180-EAAC9B19812E} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {26618FBA-A3BB-4057-A80B-240E4C90306F} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {A05BCE67-2847-4BA8-8D0F-A5C6476EAEBA} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {7E3D140B-57EE-4BE3-AB73-D06CC875BAC5} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {EB7A3C49-8516-43AB-8589-41408B238636} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {67ABA332-E9E8-4FEE-88D5-436AF6E17ACC} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {2D6C4ED6-A22A-4B05-8ED8-26572ABB322B} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {FDF5EDBB-C4A1-42AA-A0AF-288B13E9ABD1} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {6A3B60EF-CD76-4FAE-96C3-DDF7EEB5886D} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {D4A479DD-35BF-40CA-A377-0172581852AD} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {0615B916-647D-4176-86AC-60E5B967738C} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {45F7B93D-20F6-43BF-8AA6-FD0EAA3F58FF} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {7825182C-8B6C-493F-9C1F-DD80F8A0EAFD} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {B258784B-1568-479F-9B21-9E5045EC75E3} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {F364E5F4-B908-4624-9E1D-86113B032387} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {0913F657-6C2C-49E4-AE25-223B11EB8724} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {800AB4A5-B593-4B33-A2D4-0CED80253344} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {40FB71B1-87F8-4DBE-96B7-043A386C72D9} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {AC58704E-D2BE-43BB-9F80-322349F26802} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {BAE86ACC-E06B-4767-9A68-6607C6DA6DF7} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {82E1A22E-18FF-4E5D-8724-27634D0D23DA} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {1262A76C-FED4-431B-A1B6-329C3DAD2D03} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {E2100A00-DE49-4E4C-A2A6-304DB0A20423} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {6F4298ED-EEFB-4899-8F5B-1F6B1F4C7F4C} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {41FE579B-E3E2-4E43-A246-81C702DB09C3} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {16D1B230-A352-4341-B143-1EE39F32F45E} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {D156A91E-C79A-4735-AFF1-E2C836E261F7} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {D6F0121C-A9B2-401C-B458-481286E98818} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {9EE65ED2-C97B-4015-8293-ED79B29C1608} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {E7D4CECE-39DB-4EE7-B4C9-83FBC89B8903} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {72BB1EBA-2168-4C1B-9F8A-E6CE4CB14920} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {DA1D02A7-801C-49EE-B300-79CFDC8BFF66} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {F8004D45-99F4-45B0-B2CF-539A4C65D7EC} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {C0564907-D3BE-478E-B936-C55E4E745EBC} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {906B7316-6E97-4E92-9E0E-1BDF8FCD49D0} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {EEEB9B22-F363-477C-935C-139E01F79AF1} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {5757C767-600D-4911-9167-5C1B7D17018B} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {7DE8E6F7-3493-4BCA-9519-69CE3ED12459} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {E31B5339-9529-4716-9E7A-D8DA91F023C0} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {E2A68C76-68F5-4FD2-9ED2-80454B69550F} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {3C113EBD-A91B-45D2-BB1F-4C148326C492} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {69A6E865-50F4-47DE-9B40-27B8D41BA3CE} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {80EC9377-CD17-4BCD-97E6-EF971ED7CEDF} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {5D5EE944-CEFC-49D3-9213-B7AF3AB13220} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {DF930C62-644D-4F7C-AB12-6909C9CD8FF2} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {F4C3D0CB-7BEA-4CDE-99CA-51995AA590CE} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {9AA1CD10-0BF7-412A-AA54-DF59FF5510C8} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {588BA6E9-92FD-4074-BE0A-3192ABD0D7B6} = {CDB9D4A6-7A7A-4CDF-A7A3-4F17F5F1602D}
+ {FC42866A-6868-4173-9E45-12095CC91A03} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {08FADF41-2082-4A04-8613-659B5624086D} = {7ACDC26B-C774-4004-8553-87E862D1E71F}
+ {B4AD7B34-760A-4FD5-878B-1F01AF917D92} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {D0C6147C-EE5A-45F6-8CEA-A5E2AA560098} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {45133FD5-04AE-43C1-A556-D09CADD354D4} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {787D75FD-9C9F-43C9-A09B-29ED587EFECA} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {D3D354F1-9DAE-4F5C-A0A8-68CF92A53900} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {A8945DA0-1FA0-4191-BF25-83A91DD8BD6E} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {DD7FD3A1-F42C-4DD7-8993-D4E86473D304} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
+ {7B84F55C-56BE-4FDA-9639-62367246F22D} = {D207D3D7-FD4D-4FD4-A7D0-79A82086FB6F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {721B3030-08D7-4412-9087-D1CFBB3F5046}
diff --git a/samples/spreadsheet/add_custom_ui/cs/Program.cs b/samples/spreadsheet/add_custom_ui/cs/Program.cs
new file mode 100644
index 00000000..7d448c82
--- /dev/null
+++ b/samples/spreadsheet/add_custom_ui/cs/Program.cs
@@ -0,0 +1,42 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Office.CustomUI;
+using DocumentFormat.OpenXml.Packaging;
+
+static void AddCustomUI(string fileName, string customUIContent)
+{
+ // Add a custom UI part to the document.
+ // Use this sample XML to test:
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+
+ // In the sample XLSM file, create a module and create a procedure
+ // named SampleMacro, using this
+ // signature: Public Sub SampleMacro(control As IRibbonControl)
+ // Add some code, and then save and close the XLSM file. Run this
+ // example to add a button to the Add-Ins tab that calls the macro,
+ // given the XML content above in the AddCustomUI.xml file.
+
+ using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, true))
+ {
+ // You can have only a single ribbon extensibility part.
+ // If the part doesn't exist, create it.
+ var part = document.RibbonExtensibilityPart;
+ if (part == null)
+ {
+ part = document.AddRibbonExtensibilityPart();
+ }
+ part.CustomUI = new CustomUI(customUIContent);
+ part.CustomUI.Save();
+ }
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/add_custom_ui/cs/add_custom_ui_cs.csproj b/samples/spreadsheet/add_custom_ui/cs/add_custom_ui_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/add_custom_ui/cs/add_custom_ui_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/add_custom_ui/vb/Program.vb b/samples/spreadsheet/add_custom_ui/vb/Program.vb
new file mode 100644
index 00000000..70b53113
--- /dev/null
+++ b/samples/spreadsheet/add_custom_ui/vb/Program.vb
@@ -0,0 +1,47 @@
+Imports DocumentFormat.OpenXml.Office.CustomUI
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub XLAddCustomUI(ByVal fileName As String,
+ ByVal customUIContent As String)
+ ' Add a custom UI part to the document.
+ ' Use this sample XML to test:
+
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+ '
+
+ ' In the sample XLSM file, create a module and create a procedure
+ ' named SampleMacro, using this signature:
+ ' Public Sub SampleMacro(control As IRibbonControl)
+ ' Add some code, and then save and close the XLSM file. Run this
+ ' example to add a button to the Add-Ins tab that calls the macro,
+ ' given the XML content above in the AddCustomUI.xml file.
+
+ Using document As SpreadsheetDocument =
+ SpreadsheetDocument.Open(fileName, True)
+ ' You can have only a single ribbon extensibility part.
+ ' If the part doesn't exist, add it.
+ Dim part = document.RibbonExtensibilityPart
+ If part Is Nothing Then
+ part = document.AddRibbonExtensibilityPart
+ End If
+ part.CustomUI = New CustomUI(customUIContent)
+ part.CustomUI.Save()
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/add_custom_ui/vb/add_custom_ui_vb.vbproj b/samples/spreadsheet/add_custom_ui/vb/add_custom_ui_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/add_custom_ui/vb/add_custom_ui_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs b/samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs
new file mode 100644
index 00000000..a96728e8
--- /dev/null
+++ b/samples/spreadsheet/insert_a_new_worksheet/cs/Program.cs
@@ -0,0 +1,34 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System.Linq;
+
+// Given a document name, inserts a new worksheet.
+static void InsertWorksheet(string docName)
+{
+ // Open the document for editing.
+ using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(docName, true))
+ {
+ // Add a blank WorksheetPart.
+ WorksheetPart newWorksheetPart = spreadSheet.WorkbookPart.AddNewPart();
+ newWorksheetPart.Worksheet = new Worksheet(new SheetData());
+
+ Sheets sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild();
+ string relationshipId = spreadSheet.WorkbookPart.GetIdOfPart(newWorksheetPart);
+
+ // Get a unique ID for the new worksheet.
+ uint sheetId = 1;
+ if (sheets.Elements().Count() > 0)
+ {
+ sheetId = sheets.Elements().Select(s => s.SheetId.Value).Max() + 1;
+ }
+
+ // Give the new worksheet a name.
+ string sheetName = "Sheet" + sheetId;
+
+ // Append the new worksheet and associate it with the workbook.
+ Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
+ sheets.Append(sheet);
+ }
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/insert_a_new_worksheet/cs/insert_a_new_worksheet_cs.csproj b/samples/spreadsheet/insert_a_new_worksheet/cs/insert_a_new_worksheet_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/insert_a_new_worksheet/cs/insert_a_new_worksheet_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb b/samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb
new file mode 100644
index 00000000..45ca8b41
--- /dev/null
+++ b/samples/spreadsheet/insert_a_new_worksheet/vb/Program.vb
@@ -0,0 +1,41 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Given a document name, inserts a new worksheet.
+ Public Sub InsertWorksheet(ByVal docName As String)
+ ' Open the document for editing.
+ Dim spreadSheet As SpreadsheetDocument = SpreadsheetDocument.Open(docName, True)
+
+ Using (spreadSheet)
+ ' Add a blank WorksheetPart.
+ Dim newWorksheetPart As WorksheetPart = spreadSheet.WorkbookPart.AddNewPart(Of WorksheetPart)()
+ newWorksheetPart.Worksheet = New Worksheet(New SheetData())
+ ' newWorksheetPart.Worksheet.Save()
+
+ Dim sheets As Sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild(Of Sheets)()
+ Dim relationshipId As String = spreadSheet.WorkbookPart.GetIdOfPart(newWorksheetPart)
+
+ ' Get a unique ID for the new worksheet.
+ Dim sheetId As UInteger = 1
+ If (sheets.Elements(Of Sheet).Count > 0) Then
+ sheetId = sheets.Elements(Of Sheet).Select(Function(s) s.SheetId.Value).Max + 1
+ End If
+
+ ' Give the new worksheet a name.
+ Dim sheetName As String = ("Sheet" + sheetId.ToString())
+
+ ' Append the new worksheet and associate it with the workbook.
+ Dim sheet As Sheet = New Sheet
+ sheet.Id = relationshipId
+ sheet.SheetId = sheetId
+ sheet.Name = sheetName
+ sheets.Append(sheet)
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/insert_a_new_worksheet/vb/insert_a_new_worksheet_vb.vbproj b/samples/spreadsheet/insert_a_new_worksheet/vb/insert_a_new_worksheet_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/insert_a_new_worksheet/vb/insert_a_new_worksheet_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs b/samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs
new file mode 100644
index 00000000..008e6878
--- /dev/null
+++ b/samples/spreadsheet/merge_two_adjacent_cells/cs/Program.cs
@@ -0,0 +1,147 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+// Given a document name, a worksheet name, and the names of two adjacent cells, merges the two cells.
+// When two cells are merged, only the content from one cell is preserved:
+// the upper-left cell for left-to-right languages or the upper-right cell for right-to-left languages.
+static void MergeTwoCells(string docName, string sheetName, string cell1Name, string cell2Name)
+{
+ // Open the document for editing.
+ using (SpreadsheetDocument document = SpreadsheetDocument.Open(docName, true))
+ {
+ Worksheet worksheet = GetWorksheet(document, sheetName);
+ if (worksheet == null || string.IsNullOrEmpty(cell1Name) || string.IsNullOrEmpty(cell2Name))
+ {
+ return;
+ }
+
+ // Verify if the specified cells exist, and if they do not exist, create them.
+ CreateSpreadsheetCellIfNotExist(worksheet, cell1Name);
+ CreateSpreadsheetCellIfNotExist(worksheet, cell2Name);
+
+ MergeCells mergeCells;
+ if (worksheet.Elements().Count() > 0)
+ {
+ mergeCells = worksheet.Elements().First();
+ }
+ else
+ {
+ mergeCells = new MergeCells();
+
+ // Insert a MergeCells object into the specified position.
+ if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else if (worksheet.Elements().Count() > 0)
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ else
+ {
+ worksheet.InsertAfter(mergeCells, worksheet.Elements().First());
+ }
+ }
+
+ // Create the merged cell and append it to the MergeCells collection.
+ MergeCell mergeCell = new MergeCell() { Reference = new StringValue(cell1Name + ":" + cell2Name) };
+ mergeCells.Append(mergeCell);
+
+ worksheet.Save();
+ }
+}
+// Given a Worksheet and a cell name, verifies that the specified cell exists.
+// If it does not exist, creates a new cell.
+static void CreateSpreadsheetCellIfNotExist(Worksheet worksheet, string cellName)
+{
+ string columnName = GetColumnName(cellName);
+ uint rowIndex = GetRowIndex(cellName);
+
+ IEnumerable rows = worksheet.Descendants().Where(r => r.RowIndex.Value == rowIndex);
+
+ // If the Worksheet does not contain the specified row, create the specified row.
+ // Create the specified cell in that row, and insert the row into the Worksheet.
+ if (rows.Count() == 0)
+ {
+ Row row = new Row() { RowIndex = new UInt32Value(rowIndex) };
+ Cell cell = new Cell() { CellReference = new StringValue(cellName) };
+ row.Append(cell);
+ worksheet.Descendants().First().Append(row);
+ worksheet.Save();
+ }
+ else
+ {
+ Row row = rows.First();
+
+ IEnumerable cells = row.Elements().Where(c => c.CellReference.Value == cellName);
+
+ // If the row does not contain the specified cell, create the specified cell.
+ if (cells.Count() == 0)
+ {
+ Cell cell = new Cell() { CellReference = new StringValue(cellName) };
+ row.Append(cell);
+ worksheet.Save();
+ }
+ }
+}
+
+// Given a SpreadsheetDocument and a worksheet name, get the specified worksheet.
+static Worksheet GetWorksheet(SpreadsheetDocument document, string worksheetName)
+{
+ IEnumerable sheets = document.WorkbookPart.Workbook.Descendants().Where(s => s.Name == worksheetName);
+ WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.First().Id);
+ if (sheets.Count() == 0)
+ return null;
+ else
+ return worksheetPart.Worksheet;
+}
+
+// Given a cell name, parses the specified cell to get the column name.
+static string GetColumnName(string cellName)
+{
+ // Create a regular expression to match the column name portion of the cell name.
+ Regex regex = new Regex("[A-Za-z]+");
+ Match match = regex.Match(cellName);
+
+ return match.Value;
+}
+// Given a cell name, parses the specified cell to get the row index.
+static uint GetRowIndex(string cellName)
+{
+ // Create a regular expression to match the row index portion the cell name.
+ Regex regex = new Regex(@"\d+");
+ Match match = regex.Match(cellName);
+
+ return uint.Parse(match.Value);
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/merge_two_adjacent_cells/cs/merge_two_adjacent_cells_cs.csproj b/samples/spreadsheet/merge_two_adjacent_cells/cs/merge_two_adjacent_cells_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/merge_two_adjacent_cells/cs/merge_two_adjacent_cells_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/merge_two_adjacent_cells/vb/Program.vb b/samples/spreadsheet/merge_two_adjacent_cells/vb/Program.vb
new file mode 100644
index 00000000..ad293de9
--- /dev/null
+++ b/samples/spreadsheet/merge_two_adjacent_cells/vb/Program.vb
@@ -0,0 +1,128 @@
+Imports System.Text.RegularExpressions
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Given a document name, a worksheet name, and the names of two adjacent cells, merges the two cells.
+ ' When two cells are merged, only the content from one cell is preserved:
+ ' the upper-left cell for left-to-right languages or the upper-right cell for right-to-left languages.
+ Private Sub MergeTwoCells(ByVal docName As String, ByVal sheetName As String, ByVal cell1Name As String, ByVal cell2Name As String)
+ ' Open the document for editing.
+ Dim document As SpreadsheetDocument = SpreadsheetDocument.Open(docName, True)
+
+ Using (document)
+ Dim worksheet As Worksheet = GetWorksheet(document, sheetName)
+ If ((worksheet Is Nothing) OrElse (String.IsNullOrEmpty(cell1Name) OrElse String.IsNullOrEmpty(cell2Name))) Then
+ Return
+ End If
+
+ ' Verify if the specified cells exist, and if they do not exist, create them.
+ CreateSpreadsheetCellIfNotExist(worksheet, cell1Name)
+ CreateSpreadsheetCellIfNotExist(worksheet, cell2Name)
+
+ Dim mergeCells As MergeCells
+ If (worksheet.Elements(Of MergeCells)().Count() > 0) Then
+ mergeCells = worksheet.Elements(Of MergeCells).First()
+ Else
+ mergeCells = New MergeCells()
+
+ ' Insert a MergeCells object into the specified position.
+ If (worksheet.Elements(Of CustomSheetView)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of CustomSheetView)().First())
+ ElseIf (worksheet.Elements(Of DataConsolidate)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of DataConsolidate)().First())
+ ElseIf (worksheet.Elements(Of SortState)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SortState)().First())
+ ElseIf (worksheet.Elements(Of AutoFilter)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of AutoFilter)().First())
+ ElseIf (worksheet.Elements(Of Scenarios)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of Scenarios)().First())
+ ElseIf (worksheet.Elements(Of ProtectedRanges)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of ProtectedRanges)().First())
+ ElseIf (worksheet.Elements(Of SheetProtection)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SheetProtection)().First())
+ ElseIf (worksheet.Elements(Of SheetCalculationProperties)().Count() > 0) Then
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SheetCalculationProperties)().First())
+ Else
+ worksheet.InsertAfter(mergeCells, worksheet.Elements(Of SheetData)().First())
+ End If
+ End If
+
+ ' Create the merged cell and append it to the MergeCells collection.
+ Dim mergeCell As MergeCell = New MergeCell()
+ mergeCell.Reference = New StringValue((cell1Name + (":" + cell2Name)))
+ mergeCells.Append(mergeCell)
+
+ worksheet.Save()
+ End Using
+ End Sub
+
+ ' Given a SpreadsheetDocument and a worksheet name, get the specified worksheet.
+ Private Function GetWorksheet(ByVal document As SpreadsheetDocument, ByVal worksheetName As String) As Worksheet
+ Dim sheets As IEnumerable(Of Sheet) = document.WorkbookPart.Workbook.Descendants(Of Sheet)().Where(Function(s) s.Name = worksheetName)
+ If (sheets.Count = 0) Then
+ ' The specified worksheet does not exist.
+ Return Nothing
+ End If
+ Dim worksheetPart As WorksheetPart = CType(document.WorkbookPart.GetPartById(sheets.First.Id), WorksheetPart)
+
+ Return worksheetPart.Worksheet
+ End Function
+
+ ' Given a Worksheet and a cell name, verifies that the specified cell exists.
+ ' If it does not exist, creates a new cell.
+ Private Sub CreateSpreadsheetCellIfNotExist(ByVal worksheet As Worksheet, ByVal cellName As String)
+ Dim columnName As String = GetColumnName(cellName)
+ Dim rowIndex As UInteger = GetRowIndex(cellName)
+
+ Dim rows As IEnumerable(Of Row) = worksheet.Descendants(Of Row)().Where(Function(r) r.RowIndex.Value = rowIndex.ToString())
+
+ ' If the worksheet does not contain the specified row, create the specified row.
+ ' Create the specified cell in that row, and insert the row into the worksheet.
+ If (rows.Count = 0) Then
+ Dim row As Row = New Row()
+ row.RowIndex = New UInt32Value(rowIndex)
+
+ Dim cell As Cell = New Cell()
+ cell.CellReference = New StringValue(cellName)
+
+ row.Append(cell)
+ worksheet.Descendants(Of SheetData)().First().Append(row)
+ worksheet.Save()
+ Else
+ Dim row As Row = rows.First()
+ Dim cells As IEnumerable(Of Cell) = row.Elements(Of Cell)().Where(Function(c) c.CellReference.Value = cellName)
+
+ ' If the row does not contain the specified cell, create the specified cell.
+ If (cells.Count = 0) Then
+ Dim cell As Cell = New Cell
+ cell.CellReference = New StringValue(cellName)
+
+ row.Append(cell)
+ worksheet.Save()
+ End If
+ End If
+ End Sub
+
+ ' Given a cell name, parses the specified cell to get the column name.
+ Private Function GetColumnName(ByVal cellName As String) As String
+ ' Create a regular expression to match the column name portion of the cell name.
+ Dim regex As Regex = New Regex("[A-Za-z]+")
+ Dim match As Match = regex.Match(cellName)
+ Return match.Value
+ End Function
+
+ ' Given a cell name, parses the specified cell to get the row index.
+ Private Function GetRowIndex(ByVal cellName As String) As UInteger
+ ' Create a regular expression to match the row index portion the cell name.
+ Dim regex As Regex = New Regex("\d+")
+ Dim match As Match = regex.Match(cellName)
+ Return UInteger.Parse(match.Value)
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/merge_two_adjacent_cells/vb/merge_two_adjacent_cells_vb.vbproj b/samples/spreadsheet/merge_two_adjacent_cells/vb/merge_two_adjacent_cells_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/merge_two_adjacent_cells/vb/merge_two_adjacent_cells_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/open_for_read_only_access/cs/Program.cs b/samples/spreadsheet/open_for_read_only_access/cs/Program.cs
new file mode 100644
index 00000000..9095974f
--- /dev/null
+++ b/samples/spreadsheet/open_for_read_only_access/cs/Program.cs
@@ -0,0 +1,15 @@
+#nullable disable
+using DocumentFormat.OpenXml.Packaging;
+
+static void OpenSpreadsheetDocumentReadonly(string filepath)
+{
+ // Open a SpreadsheetDocument based on a filepath.
+ using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filepath, false))
+ {
+ // Attempt to add a new WorksheetPart.
+ // The call to AddNewPart generates an exception because the file is read-only.
+ WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
+
+ // The rest of the code will not be called.
+ }
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/open_for_read_only_access/cs/open_for_read_only_access_cs.csproj b/samples/spreadsheet/open_for_read_only_access/cs/open_for_read_only_access_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/open_for_read_only_access/cs/open_for_read_only_access_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/open_for_read_only_access/vb/Program.vb b/samples/spreadsheet/open_for_read_only_access/vb/Program.vb
new file mode 100644
index 00000000..55e48516
--- /dev/null
+++ b/samples/spreadsheet/open_for_read_only_access/vb/Program.vb
@@ -0,0 +1,19 @@
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub OpenSpreadsheetDocumentReadonly(ByVal filepath As String)
+ ' Open a SpreadsheetDocument based on a filepath.
+ Using spreadsheetDocument As SpreadsheetDocument = spreadsheetDocument.Open(filepath, False)
+ ' Attempt to add a new WorksheetPart.
+ ' The call to AddNewPart generates an exception because the file is read-only.
+ Dim newWorksheetPart As WorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
+
+ ' The rest of the code will not be called.
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/open_for_read_only_access/vb/open_for_read_only_access_vb.vbproj b/samples/spreadsheet/open_for_read_only_access/vb/open_for_read_only_access_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/open_for_read_only_access/vb/open_for_read_only_access_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/open_from_a_stream/cs/Program.cs b/samples/spreadsheet/open_from_a_stream/cs/Program.cs
new file mode 100644
index 00000000..d9a5dbe4
--- /dev/null
+++ b/samples/spreadsheet/open_from_a_stream/cs/Program.cs
@@ -0,0 +1,39 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System.IO;
+using System.Linq;
+
+static void OpenAndAddToSpreadsheetStream(Stream stream)
+{
+ // Open a SpreadsheetDocument based on a stream.
+ SpreadsheetDocument spreadsheetDocument =
+ SpreadsheetDocument.Open(stream, true);
+
+ // Add a new worksheet.
+ WorksheetPart newWorksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart();
+ newWorksheetPart.Worksheet = new Worksheet(new SheetData());
+ newWorksheetPart.Worksheet.Save();
+
+ Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.GetFirstChild();
+ string relationshipId = spreadsheetDocument.WorkbookPart.GetIdOfPart(newWorksheetPart);
+
+ // Get a unique ID for the new worksheet.
+ uint sheetId = 1;
+ if (sheets.Elements().Count() > 0)
+ {
+ sheetId = sheets.Elements().Select(s => s.SheetId.Value).Max() + 1;
+ }
+
+ // Give the new worksheet a name.
+ string sheetName = "Sheet" + sheetId;
+
+ // Append the new worksheet and associate it with the workbook.
+ Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
+ sheets.Append(sheet);
+ spreadsheetDocument.WorkbookPart.Workbook.Save();
+
+ // Dispose the document handle.
+ spreadsheetDocument.Dispose();
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/open_from_a_stream/cs/open_from_a_stream_cs.csproj b/samples/spreadsheet/open_from_a_stream/cs/open_from_a_stream_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/open_from_a_stream/cs/open_from_a_stream_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/open_from_a_stream/vb/Program.vb b/samples/spreadsheet/open_from_a_stream/vb/Program.vb
new file mode 100644
index 00000000..a280f5e6
--- /dev/null
+++ b/samples/spreadsheet/open_from_a_stream/vb/Program.vb
@@ -0,0 +1,45 @@
+Imports System.IO
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub OpenAndAddToSpreadsheetStream(ByVal stream As Stream)
+ ' Open a SpreadsheetDocument based on a stream.
+ Dim mySpreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(stream, True)
+
+ ' Add a new worksheet.
+ Dim newWorksheetPart As WorksheetPart = mySpreadsheetDocument.WorkbookPart.AddNewPart(Of WorksheetPart)()
+ newWorksheetPart.Worksheet = New Worksheet(New SheetData())
+ newWorksheetPart.Worksheet.Save()
+
+ Dim sheets As Sheets = mySpreadsheetDocument.WorkbookPart.Workbook.GetFirstChild(Of Sheets)()
+ Dim relationshipId As String = mySpreadsheetDocument.WorkbookPart.GetIdOfPart(newWorksheetPart)
+
+ ' Get a unique ID for the new worksheet.
+ Dim sheetId As UInteger = 1
+ If (sheets.Elements(Of Sheet).Count > 0) Then
+ sheetId = sheets.Elements(Of Sheet).Select(Function(s) s.SheetId.Value).Max + 1
+ End If
+
+ ' Give the new worksheet a name.
+ Dim sheetName As String = ("Sheet" + sheetId.ToString())
+
+ ' Append the new worksheet and associate it with the workbook.
+ Dim sheet As Sheet = New Sheet
+ sheet.Id = relationshipId
+ sheet.SheetId = sheetId
+ sheet.Name = sheetName
+ sheets.Append(sheet)
+ mySpreadsheetDocument.WorkbookPart.Workbook.Save()
+
+ 'Dispose the document handle.
+ mySpreadsheetDocument.Dispose()
+
+ 'Caller must close the stream.
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/open_from_a_stream/vb/open_from_a_stream_vb.vbproj b/samples/spreadsheet/open_from_a_stream/vb/open_from_a_stream_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/open_from_a_stream/vb/open_from_a_stream_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs
new file mode 100644
index 00000000..5d2e1789
--- /dev/null
+++ b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/Program.cs
@@ -0,0 +1,54 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System;
+using System.Linq;
+
+// The DOM approach.
+// Note that the code below works only for cells that contain numeric values.
+//
+static void ReadExcelFileDOM(string fileName)
+{
+ using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
+ {
+ WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
+ WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
+ SheetData sheetData = worksheetPart.Worksheet.Elements().First();
+ string text;
+ foreach (Row r in sheetData.Elements())
+ {
+ foreach (Cell c in r.Elements())
+ {
+ text = c.CellValue.Text;
+ Console.Write(text + " ");
+ }
+ }
+ Console.WriteLine();
+ Console.ReadKey();
+ }
+}
+
+// The SAX approach.
+static void ReadExcelFileSAX(string fileName)
+{
+ using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
+ {
+ WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
+ WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
+
+ OpenXmlReader reader = OpenXmlReader.Create(worksheetPart);
+ string text;
+ while (reader.Read())
+ {
+ if (reader.ElementType == typeof(CellValue))
+ {
+ text = reader.GetText();
+ Console.Write(text + " ");
+ }
+ }
+ Console.WriteLine();
+ Console.ReadKey();
+ }
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/parse_and_read_a_large_spreadsheet_cs.csproj b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/parse_and_read_a_large_spreadsheet_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/cs/parse_and_read_a_large_spreadsheet_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/Program.vb b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/Program.vb
new file mode 100644
index 00000000..c6f8a951
--- /dev/null
+++ b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/Program.vb
@@ -0,0 +1,50 @@
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' The DOM approach.
+ ' Note that the this code works only for cells that contain numeric values.
+
+
+ Private Sub ReadExcelFileDOM(ByVal fileName As String)
+ Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
+ Dim workbookPart As WorkbookPart = spreadsheetDocument.WorkbookPart
+ Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
+ Dim sheetData As SheetData = worksheetPart.Worksheet.Elements(Of SheetData)().First()
+ Dim text As String
+ For Each r As Row In sheetData.Elements(Of Row)()
+ For Each c As Cell In r.Elements(Of Cell)()
+ text = c.CellValue.Text
+ Console.Write(text & " ")
+ Next
+ Next
+ Console.WriteLine()
+ Console.ReadKey()
+ End Using
+ End Sub
+
+ ' The SAX approach.
+ Private Sub ReadExcelFileSAX(ByVal fileName As String)
+ Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, False)
+ Dim workbookPart As WorkbookPart = spreadsheetDocument.WorkbookPart
+ Dim worksheetPart As WorksheetPart = workbookPart.WorksheetParts.First()
+
+ Dim reader As OpenXmlReader = OpenXmlReader.Create(worksheetPart)
+ Dim text As String
+ While reader.Read()
+ If reader.ElementType = GetType(CellValue) Then
+ text = reader.GetText()
+ Console.Write(text & " ")
+ End If
+ End While
+ Console.WriteLine()
+ Console.ReadKey()
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/parse_and_read_a_large_spreadsheet_vb.vbproj b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/parse_and_read_a_large_spreadsheet_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/parse_and_read_a_large_spreadsheet/vb/parse_and_read_a_large_spreadsheet_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs
new file mode 100644
index 00000000..4da81755
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/Program.cs
@@ -0,0 +1,33 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System;
+using System.Collections.Generic;
+
+static Dictionary
+ GetDefinedNames(String fileName)
+{
+ // Given a workbook name, return a dictionary of defined names.
+ // The pairs include the range name and a string representing the range.
+ var returnValue = new Dictionary();
+
+ // Open the spreadsheet document for read-only access.
+ using (SpreadsheetDocument document =
+ SpreadsheetDocument.Open(fileName, false))
+ {
+ // Retrieve a reference to the workbook part.
+ var wbPart = document.WorkbookPart;
+
+ // Retrieve a reference to the defined names collection.
+ DefinedNames definedNames = wbPart.Workbook.DefinedNames;
+
+ // If there are defined names, add them to the dictionary.
+ if (definedNames != null)
+ {
+ foreach (DefinedName dn in definedNames)
+ returnValue.Add(dn.Name.Value, dn.Text);
+ }
+ }
+ return returnValue;
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/retrieve_a_dictionary_of_all_named_ranges_cs.csproj b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/retrieve_a_dictionary_of_all_named_ranges_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/cs/retrieve_a_dictionary_of_all_named_ranges_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/Program.vb b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/Program.vb
new file mode 100644
index 00000000..49c57887
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/Program.vb
@@ -0,0 +1,36 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Function GetDefinedNames(
+ ByVal fileName As String) As Dictionary(Of String, String)
+
+ ' Given a workbook name, return a dictionary of defined names.
+ ' The pairs include the range name and a string representing the range.
+ Dim returnValue As New Dictionary(Of String, String)
+
+ ' Open the spreadsheet document for read-only access.
+ Using document As SpreadsheetDocument =
+ SpreadsheetDocument.Open(fileName, False)
+
+ ' Retrieve a reference to the workbook part.
+ Dim wbPart As WorkbookPart = document.WorkbookPart
+
+ ' Retrieve a reference to the defined names collection.
+ Dim definedNames As DefinedNames = wbPart.Workbook.DefinedNames
+
+ ' If there are defined names, add them to the dictionary.
+ If definedNames IsNot Nothing Then
+ For Each dn As DefinedName In definedNames
+ returnValue.Add(dn.Name.Value, dn.Text)
+ Next
+ End If
+ End Using
+ Return returnValue
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/retrieve_a_dictionary_of_all_named_ranges_vb.vbproj b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/retrieve_a_dictionary_of_all_named_ranges_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_dictionary_of_all_named_ranges/vb/retrieve_a_dictionary_of_all_named_ranges_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs
new file mode 100644
index 00000000..da22b9c8
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/Program.cs
@@ -0,0 +1,61 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+static List GetHiddenRowsOrCols(
+ string fileName, string sheetName, bool detectRows)
+{
+ // Given a workbook and a worksheet name, return
+ // either a list of hidden row numbers, or a list
+ // of hidden column numbers. If detectRows is true, return
+ // hidden rows. If detectRows is false, return hidden columns.
+ // Rows and columns are numbered starting with 1.
+
+ List itemList = new List();
+
+ using (SpreadsheetDocument document =
+ SpreadsheetDocument.Open(fileName, false))
+ {
+ WorkbookPart wbPart = document.WorkbookPart;
+
+ Sheet theSheet = wbPart.Workbook.Descendants().
+ Where((s) => s.Name == sheetName).FirstOrDefault();
+ if (theSheet == null)
+ {
+ throw new ArgumentException("sheetName");
+ }
+ else
+ {
+ // The sheet does exist.
+ WorksheetPart wsPart =
+ (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
+ Worksheet ws = wsPart.Worksheet;
+
+ if (detectRows)
+ {
+ // Retrieve hidden rows.
+ itemList = ws.Descendants().
+ Where((r) => r.Hidden != null && r.Hidden.Value).
+ Select(r => r.RowIndex.Value).ToList();
+ }
+ else
+ {
+ // Retrieve hidden columns.
+ var cols = ws.Descendants().
+ Where((c) => c.Hidden != null && c.Hidden.Value);
+ foreach (Column item in cols)
+ {
+ for (uint i = item.Min.Value; i <= item.Max.Value; i++)
+ {
+ itemList.Add(i);
+ }
+ }
+ }
+ }
+ }
+ return itemList;
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/retrieve_a_list_of_the_hidden_rows_or_columns_cs.csproj b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/retrieve_a_list_of_the_hidden_rows_or_columns_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/cs/retrieve_a_list_of_the_hidden_rows_or_columns_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/Program.vb b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/Program.vb
new file mode 100644
index 00000000..47207836
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/Program.vb
@@ -0,0 +1,58 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Function GetHiddenRowsOrCols(
+ ByVal fileName As String, ByVal sheetName As String,
+ ByVal detectRows As Boolean) As List(Of UInteger)
+
+ ' Given a workbook and a worksheet name, return either
+ ' a list of hidden row numbers, or a list of hidden
+ ' column numbers. If detectRows is True, return
+ ' hidden rows. If detectRows is False, return hidden columns.
+ ' Rows and columns are numbered starting with 1.
+
+ Dim itemList As New List(Of UInteger)
+
+ Using document As SpreadsheetDocument =
+ SpreadsheetDocument.Open(fileName, False)
+
+ Dim wbPart As WorkbookPart = document.WorkbookPart
+
+ Dim theSheet As Sheet = wbPart.Workbook.Descendants(Of Sheet)().
+ Where(Function(s) s.Name = sheetName).FirstOrDefault()
+ If theSheet Is Nothing Then
+ Throw New ArgumentException("sheetName")
+ Else
+ ' The sheet does exist.
+ Dim wsPart As WorksheetPart =
+ CType(wbPart.GetPartById(theSheet.Id), WorksheetPart)
+ Dim ws As Worksheet = wsPart.Worksheet
+
+ If detectRows Then
+ ' Retrieve hidden rows.
+ itemList = ws.Descendants(Of Row).
+ Where(Function(r) r.Hidden IsNot Nothing AndAlso
+ r.Hidden.Value).
+ Select(Function(r) r.RowIndex.Value).ToList()
+ Else
+ ' Retrieve hidden columns.
+ Dim cols = ws.Descendants(Of Column).
+ Where(Function(c) c.Hidden IsNot Nothing AndAlso
+ c.Hidden.Value)
+ For Each item As Column In cols
+ For i As UInteger = item.Min.Value To item.Max.Value
+ itemList.Add(i)
+ Next
+ Next
+ End If
+ End If
+ End Using
+ Return itemList
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/retrieve_a_list_of_the_hidden_rows_or_columns_vb.vbproj b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/retrieve_a_list_of_the_hidden_rows_or_columns_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_rows_or_columns/vb/retrieve_a_list_of_the_hidden_rows_or_columns_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs
new file mode 100644
index 00000000..d364d7d1
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/Program.cs
@@ -0,0 +1,28 @@
+#nullable disable
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System.Collections.Generic;
+using System.Linq;
+
+static List GetHiddenSheets(string fileName)
+{
+ List returnVal = new List();
+
+ using (SpreadsheetDocument document =
+ SpreadsheetDocument.Open(fileName, false))
+ {
+ WorkbookPart wbPart = document.WorkbookPart;
+ var sheets = wbPart.Workbook.Descendants();
+
+ // Look for sheets where there is a State attribute defined,
+ // where the State has a value,
+ // and where the value is either Hidden or VeryHidden.
+ var hiddenSheets = sheets.Where((item) => item.State != null &&
+ item.State.HasValue &&
+ (item.State.Value == SheetStateValues.Hidden ||
+ item.State.Value == SheetStateValues.VeryHidden));
+
+ returnVal = hiddenSheets.ToList();
+ }
+ return returnVal;
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/retrieve_a_list_of_the_hidden_worksheets_cs.csproj b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/retrieve_a_list_of_the_hidden_worksheets_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/cs/retrieve_a_list_of_the_hidden_worksheets_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/Program.vb b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/Program.vb
new file mode 100644
index 00000000..c510cf05
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/Program.vb
@@ -0,0 +1,31 @@
+Imports DocumentFormat.OpenXml.Spreadsheet
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program `
+ Sub Main(args As String())`
+ End Sub`
+
+
+
+ Public Function GetHiddenSheets(ByVal fileName As String) As List(Of Sheet)
+ Dim returnVal As New List(Of Sheet)
+
+ Using document As SpreadsheetDocument =
+ SpreadsheetDocument.Open(fileName, False)
+
+ Dim wbPart As WorkbookPart = document.WorkbookPart
+ Dim sheets = wbPart.Workbook.Descendants(Of Sheet)()
+
+ ' Look for sheets where there is a State attribute defined,
+ ' where the State has a value,
+ ' and where the value is either Hidden or VeryHidden:
+ Dim hiddenSheets = sheets.Where(Function(item) item.State IsNot
+ Nothing AndAlso item.State.HasValue _
+ AndAlso (item.State.Value = SheetStateValues.Hidden Or _
+ item.State.Value = SheetStateValues.VeryHidden))
+
+ returnVal = hiddenSheets.ToList()
+ End Using
+ Return returnVal
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/retrieve_a_list_of_the_hidden_worksheets_vb.vbproj b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/retrieve_a_list_of_the_hidden_worksheets_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_hidden_worksheets/vb/retrieve_a_list_of_the_hidden_worksheets_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs
new file mode 100644
index 00000000..eca31fae
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/Program.cs
@@ -0,0 +1,40 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System;
+
+namespace GetAllWorkheets
+{
+ class Program
+ {
+ const string DEMOFILE =
+ @"C:\Users\Public\Documents\SampleWorkbook.xlsx";
+
+ static void Main(string[] args)
+ {
+ var results = GetAllWorksheets(DEMOFILE);
+ foreach (Sheet item in results)
+ {
+ Console.WriteLine(item.Name);
+ }
+ }
+
+ // Retrieve a List of all the sheets in a workbook.
+ // The Sheets class contains a collection of
+ // OpenXmlElement objects, each representing one of
+ // the sheets.
+ public static Sheets GetAllWorksheets(string fileName)
+ {
+ Sheets theSheets = null;
+
+ using (SpreadsheetDocument document =
+ SpreadsheetDocument.Open(fileName, false))
+ {
+ WorkbookPart wbPart = document.WorkbookPart;
+ theSheets = wbPart.Workbook.Sheets;
+ }
+ return theSheets;
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/retrieve_a_list_of_the_worksheets_cs.csproj b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/retrieve_a_list_of_the_worksheets_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/cs/retrieve_a_list_of_the_worksheets_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/Program.vb b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/Program.vb
new file mode 100644
index 00000000..e438b481
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/Program.vb
@@ -0,0 +1,31 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Module1
+
+ Const DEMOFILE As String =
+ "C:\Users\Public\Documents\SampleWorkbook.xlsx"
+
+ Sub Main()
+ Dim results = GetAllWorksheets(DEMOFILE)
+ ' Because Sheet inherits from OpenXmlElement, you can cast
+ ' each item in the collection to be a Sheet instance.
+ For Each item As Sheet In results
+ Console.WriteLine(item.Name)
+ Next
+ End Sub
+
+ ' Retrieve a list of all the sheets in a Workbook.
+ ' The Sheets class contains a collection of
+ ' OpenXmlElement objects, each representing
+ ' one of the sheets.
+ Public Function GetAllWorksheets(ByVal fileName As String) As Sheets
+ Dim theSheets As Sheets
+ Using document As SpreadsheetDocument =
+ SpreadsheetDocument.Open(fileName, False)
+ Dim wbPart As WorkbookPart = document.WorkbookPart
+ theSheets = wbPart.Workbook.Sheets()
+ End Using
+ Return theSheets
+ End Function
+End Module
diff --git a/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/retrieve_a_list_of_the_worksheets_vb.vbproj b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/retrieve_a_list_of_the_worksheets_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_a_list_of_the_worksheets/vb/retrieve_a_list_of_the_worksheets_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs b/samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs
new file mode 100644
index 00000000..57d582aa
--- /dev/null
+++ b/samples/spreadsheet/retrieve_the_values_of_cells/cs/Program.cs
@@ -0,0 +1,95 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Spreadsheet;
+using System;
+using System.Linq;
+
+// Retrieve the value of a cell, given a file name, sheet name,
+// and address name.
+static string GetCellValue(string fileName,
+ string sheetName,
+ string addressName)
+{
+ string value = null;
+
+ // Open the spreadsheet document for read-only access.
+ using (SpreadsheetDocument document =
+ SpreadsheetDocument.Open(fileName, false))
+ {
+ // Retrieve a reference to the workbook part.
+ WorkbookPart wbPart = document.WorkbookPart;
+
+ // Find the sheet with the supplied name, and then use that
+ // Sheet object to retrieve a reference to the first worksheet.
+ Sheet theSheet = wbPart.Workbook.Descendants().
+ Where(s => s.Name == sheetName).FirstOrDefault();
+
+ // Throw an exception if there is no sheet.
+ if (theSheet == null)
+ {
+ throw new ArgumentException("sheetName");
+ }
+
+ // Retrieve a reference to the worksheet part.
+ WorksheetPart wsPart =
+ (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
+
+ // Use its Worksheet property to get a reference to the cell
+ // whose address matches the address you supplied.
+ Cell theCell = wsPart.Worksheet.Descendants().
+ Where(c => c.CellReference == addressName).FirstOrDefault();
+
+ // If the cell does not exist, return an empty string.
+ if (theCell.InnerText.Length > 0)
+ {
+ value = theCell.InnerText;
+
+ // If the cell represents an integer number, you are done.
+ // For dates, this code returns the serialized value that
+ // represents the date. The code handles strings and
+ // Booleans individually. For shared strings, the code
+ // looks up the corresponding value in the shared string
+ // table. For Booleans, the code converts the value into
+ // the words TRUE or FALSE.
+ if (theCell.DataType != null)
+ {
+ switch (theCell.DataType.Value)
+ {
+ case CellValues.SharedString:
+
+ // For shared strings, look up the value in the
+ // shared strings table.
+ var stringTable =
+ wbPart.GetPartsOfType()
+ .FirstOrDefault();
+
+ // If the shared string table is missing, something
+ // is wrong. Return the index that is in
+ // the cell. Otherwise, look up the correct text in
+ // the table.
+ if (stringTable != null)
+ {
+ value =
+ stringTable.SharedStringTable
+ .ElementAt(int.Parse(value)).InnerText;
+ }
+ break;
+
+ case CellValues.Boolean:
+ switch (value)
+ {
+ case "0":
+ value = "FALSE";
+ break;
+ default:
+ value = "TRUE";
+ break;
+ }
+ break;
+ }
+ }
+ }
+ }
+ return value;
+}
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_the_values_of_cells/cs/retrieve_the_values_of_cells_cs.csproj b/samples/spreadsheet/retrieve_the_values_of_cells/cs/retrieve_the_values_of_cells_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_the_values_of_cells/cs/retrieve_the_values_of_cells_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_the_values_of_cells/vb/Program.vb b/samples/spreadsheet/retrieve_the_values_of_cells/vb/Program.vb
new file mode 100644
index 00000000..533dfb86
--- /dev/null
+++ b/samples/spreadsheet/retrieve_the_values_of_cells/vb/Program.vb
@@ -0,0 +1,84 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Function GetCellValue(ByVal fileName As String,
+ ByVal sheetName As String,
+ ByVal addressName As String) As String
+
+ Dim value As String = Nothing
+
+ ' Open the spreadsheet document for read-only access.
+ Using document As SpreadsheetDocument =
+ SpreadsheetDocument.Open(fileName, False)
+
+ ' Retrieve a reference to the workbook part.
+ Dim wbPart As WorkbookPart = document.WorkbookPart
+
+ ' Find the sheet with the supplied name, and then use that Sheet object
+ ' to retrieve a reference to the appropriate worksheet.
+ Dim theSheet As Sheet = wbPart.Workbook.Descendants(Of Sheet)().
+ Where(Function(s) s.Name = sheetName).FirstOrDefault()
+
+ ' Throw an exception if there is no sheet.
+ If theSheet Is Nothing Then
+ Throw New ArgumentException("sheetName")
+ End If
+
+ ' Retrieve a reference to the worksheet part.
+ Dim wsPart As WorksheetPart =
+ CType(wbPart.GetPartById(theSheet.Id), WorksheetPart)
+
+ ' Use its Worksheet property to get a reference to the cell
+ ' whose address matches the address you supplied.
+ Dim theCell As Cell = wsPart.Worksheet.Descendants(Of Cell).
+ Where(Function(c) c.CellReference = addressName).FirstOrDefault
+
+ ' If the cell does not exist, return an empty string.
+ If theCell IsNot Nothing Then
+ value = theCell.InnerText
+
+ ' If the cell represents an numeric value, you are done.
+ ' For dates, this code returns the serialized value that
+ ' represents the date. The code handles strings and
+ ' Booleans individually. For shared strings, the code
+ ' looks up the corresponding value in the shared string
+ ' table. For Booleans, the code converts the value into
+ ' the words TRUE or FALSE.
+ If theCell.DataType IsNot Nothing Then
+ Select Case theCell.DataType.Value
+ Case CellValues.SharedString
+
+ ' For shared strings, look up the value in the
+ ' shared strings table.
+ Dim stringTable = wbPart.
+ GetPartsOfType(Of SharedStringTablePart).FirstOrDefault()
+
+ ' If the shared string table is missing, something
+ ' is wrong. Return the index that is in
+ ' the cell. Otherwise, look up the correct text in
+ ' the table.
+ If stringTable IsNot Nothing Then
+ value = stringTable.SharedStringTable.
+ ElementAt(Integer.Parse(value)).InnerText
+ End If
+
+ Case CellValues.Boolean
+ Select Case value
+ Case "0"
+ value = "FALSE"
+ Case Else
+ value = "TRUE"
+ End Select
+ End Select
+ End If
+ End If
+ End Using
+ Return value
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/spreadsheet/retrieve_the_values_of_cells/vb/retrieve_the_values_of_cells_vb.vbproj b/samples/spreadsheet/retrieve_the_values_of_cells/vb/retrieve_the_values_of_cells_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/spreadsheet/retrieve_the_values_of_cells/vb/retrieve_the_values_of_cells_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/tools/migrator/Program.cs b/samples/tools/migrator/Program.cs
index bd10fa5b..5b4478c2 100644
--- a/samples/tools/migrator/Program.cs
+++ b/samples/tools/migrator/Program.cs
@@ -1,59 +1,97 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
-if (args is not [string path])
+if (args is not [string folder])
{
- Console.WriteLine("Must supply a path");
+ Console.WriteLine("Must supply a folder");
return;
}
-var samplesDir = Path.GetFullPath(Path.Combine(path, "..", "..", "samples"))!;
+var files = Directory.GetFiles(folder, "*.md");
-if (!Directory.Exists(samplesDir))
+foreach (var path in files)
{
- Console.WriteLine("Not a valid document");
- return;
-}
-
-var text = File.ReadAllText(path);
-
-text = Matchers.GetAssemblyDirective().Replace(text, string.Empty);
-text = Matchers.HowWorks().Replace(text, "##");
-
-var csMatch = Matchers.Csharp().Match(text);
-var cs = csMatch.Groups[2].Value;
-var vbMatch = Matchers.Vb().Match(text);
-var vb = vbMatch.Groups[2].Value;
-
-var area = Matchers.Area().Match(text).Groups[1].Value;
-Console.WriteLine($"Enter name for {Path.GetFileName(path)}");
-string name = Console.ReadLine() ?? throw new InvalidOperationException();
-
-name = name.Replace("-", "_");
-
-text = text.Replace(csMatch.Groups[1].Value, $"""
- ### [CSharp](#tab/cs)
+ var samplesDir = Path.GetFullPath(Path.Combine(path, "..", "..", "samples"))!;
+
+ if (!Directory.Exists(samplesDir))
+ {
+ Console.WriteLine("Not a valid document");
+ return;
+ }
+
+ var text = File.ReadAllText(path);
+
+ var csMatch = Matchers.Csharp().Match(text);
+ var csCodeMatches = Matchers.GetCsharpCode(text);
+
+ var vbMatch = Matchers.Vb().Match(text);
+ var vbCodeMatches = Matchers.GetVbCode(text);
+
+ if (csCodeMatches is null || vbCodeMatches is null || csCodeMatches.Count < 1 || vbCodeMatches.Count < 1)
+ {
+ Console.WriteLine("No code found");
+ continue;
+ }
+
+ if (!csCodeMatches[0].Value.TrimStart().StartsWith("using"))
+ {
+ Console.WriteLine("Not a complete program");
+ continue;
+ }
+
+ var cs = string.Concat(csCodeMatches[0].Value, csCodeMatches[csCodeMatches.Count - 1].Value.TrimEnd());
+ var vb = string.Concat(vbCodeMatches[0].Value, vbCodeMatches[vbCodeMatches.Count - 1].Value.TrimEnd());
+ var area = Matchers.Area().Match(text).Groups[1].Value;
+
+ if (area is null || area == string.Empty)
+ {
+
+ if (cs.Contains("SpreadsheetDocument") || text.Contains("SpreadsheetML"))
+ {
+ area = "spreadsheet";
+ }
+ else if (cs.Contains("WordprocessingDocument") || text.Contains("WordprocessingML"))
+ {
+ area = "word";
+ }
+ else if (cs.Contains("PresentationDocument") || text.Contains("PresentationML"))
+ {
+ area = "presentation";
+ }
+
+ text = Matchers.GetAssemblyDirective().Replace(text, string.Empty);
+ text = Matchers.HowWorks().Replace(text, "##");
+
+ var name = Path.GetFileName(path).Replace("-", "_").Replace(".md", string.Empty);
+
+ if (csMatch is not null && csMatch.Groups is not null && csMatch.Groups[1] is not null && csMatch.Groups[1].Value.Length > 0)
+ {
+ text = text.Replace(csMatch.Groups[1].Value, $"""
+ ### [C#](#tab/cs)
[!code-csharp[](../samples/{area}/{name}/cs/Program.cs)]
""");
-
-text = text.Replace(vbMatch.Groups[1].Value, $"""
- ### [CSharp](#tab/cs)
+ }
+ if (vbMatch is not null && vbMatch.Groups is not null && vbMatch.Groups[1] is not null && vbMatch.Groups[1].Value.Length > 0)
+ {
+ text = text.Replace(vbMatch.Groups[1].Value, $"""
+ ### [Visual Basic](#tab/vb)
[!code-vb[](../samples/{area}/{name}/vb/Program.vb)]
""");
+ }
-var thisSampleDir = Path.Combine(samplesDir, area, name);
+ var thisSampleDir = Path.Combine(samplesDir, area ?? string.Empty, name);
-var csDir = Path.Combine(thisSampleDir, "cs");
-Directory.CreateDirectory(csDir);
-var csProj = Path.Combine(csDir, $"{name}_cs.csproj");
-File.WriteAllText(csProj, """""");
-File.WriteAllText(Path.Combine(csDir, "Program.cs"), cs);
+ var csDir = Path.Combine(thisSampleDir, "cs");
+ Directory.CreateDirectory(csDir);
+ var csProj = Path.Combine(csDir, $"{name}_cs.csproj");
+ File.WriteAllText(csProj, """""");
+ File.WriteAllText(Path.Combine(csDir, "Program.cs"), cs);
-var vbDir = Path.Combine(thisSampleDir, "vb");
-Directory.CreateDirectory(vbDir);
-var vbProj = Path.Combine(vbDir, $"{name}_vb.vbproj");
-File.WriteAllText(vbProj, """""");
-File.WriteAllText(Path.Combine(vbDir, "Program.vb"), $"""
+ var vbDir = Path.Combine(thisSampleDir, "vb");
+ Directory.CreateDirectory(vbDir);
+ var vbProj = Path.Combine(vbDir, $"{name}_vb.vbproj");
+ File.WriteAllText(vbProj, """""");
+ File.WriteAllText(Path.Combine(vbDir, "Program.vb"), $"""
Module Program `
Sub Main(args As String())`
End Sub`
@@ -62,11 +100,13 @@ End Sub`
End Module
""");
-File.WriteAllText(path, text);
+ File.WriteAllText(path, text);
-Process.Start(new ProcessStartInfo("dotnet", $"sln add {csProj} --solution-folder {area}") { WorkingDirectory = samplesDir })!.WaitForExit();
-Process.Start(new ProcessStartInfo("dotnet", $"sln add {vbProj} --solution-folder {area}") { WorkingDirectory = samplesDir })!.WaitForExit();
+ Process.Start(new ProcessStartInfo("dotnet", $"sln add {csProj} --solution-folder {area}") { WorkingDirectory = samplesDir })!.WaitForExit();
+ Process.Start(new ProcessStartInfo("dotnet", $"sln add {vbProj} --solution-folder {area}") { WorkingDirectory = samplesDir })!.WaitForExit();
+ }
+}
partial class Matchers
{
[GeneratedRegex("""The following assembly directives.*?```vb.*?```""", RegexOptions.Singleline)]
@@ -78,9 +118,35 @@ partial class Matchers
[GeneratedRegex(".*(```csharp(.*?)```)", RegexOptions.Singleline)]
public static partial Regex Csharp();
+ [GeneratedRegex("```csharp(.*?)```", RegexOptions.Singleline)]
+ public static partial Regex CsharpUsings();
+
[GeneratedRegex(".*(```vb(.*?)```)", RegexOptions.Singleline)]
public static partial Regex Vb();
+ [GeneratedRegex("```vb(.*?)```", RegexOptions.Singleline)]
+ public static partial Regex VbUsings();
+
[GeneratedRegex("./includes/(.*?)/structure\\.md")]
public static partial Regex Area();
+
+ public static MatchCollection? GetCsharpCode(string str)
+ {
+ var pattern = @"(?<=```csharp).*?(?=```)";
+
+ var regex = new Regex(pattern, RegexOptions.Singleline);
+ var matchCollection = regex.Matches(str);
+
+ return matchCollection;
+ }
+
+ public static MatchCollection? GetVbCode(string str)
+ {
+ var pattern = @"(?<=```vb).*?(?=```)";
+
+ var regex = new Regex(pattern, RegexOptions.Singleline);
+ var matchCollection = regex.Matches(str);
+
+ return matchCollection;
+ }
}
\ No newline at end of file
diff --git a/samples/tools/migrator/migrator.csproj b/samples/tools/migrator/migrator.csproj
index 2150e379..c982e8e0 100644
--- a/samples/tools/migrator/migrator.csproj
+++ b/samples/tools/migrator/migrator.csproj
@@ -5,6 +5,11 @@
net8.0enableenable
+ Nullable
+
+
+
+
diff --git a/samples/word/accept_all_revisions/cs/Program.cs b/samples/word/accept_all_revisions/cs/Program.cs
index 79f58e33..bef0e76b 100644
--- a/samples/word/accept_all_revisions/cs/Program.cs
+++ b/samples/word/accept_all_revisions/cs/Program.cs
@@ -1,3 +1,4 @@
+#nullable disable
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
diff --git a/samples/word/add_tables/cs/Program.cs b/samples/word/add_tables/cs/Program.cs
new file mode 100644
index 00000000..0ebbb446
--- /dev/null
+++ b/samples/word/add_tables/cs/Program.cs
@@ -0,0 +1,72 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+
+// Take the data from a two-dimensional array and build a table at the
+// end of the supplied document.
+static void AddTable(string fileName, string[,] data)
+{
+ using (var document = WordprocessingDocument.Open(fileName, true))
+ {
+
+ var doc = document.MainDocumentPart.Document;
+
+ Table table = new Table();
+
+ TableProperties props = new TableProperties(
+ new TableBorders(
+ new TopBorder
+ {
+ Val = new EnumValue(BorderValues.Single),
+ Size = 12
+ },
+ new BottomBorder
+ {
+ Val = new EnumValue(BorderValues.Single),
+ Size = 12
+ },
+ new LeftBorder
+ {
+ Val = new EnumValue(BorderValues.Single),
+ Size = 12
+ },
+ new RightBorder
+ {
+ Val = new EnumValue(BorderValues.Single),
+ Size = 12
+ },
+ new InsideHorizontalBorder
+ {
+ Val = new EnumValue(BorderValues.Single),
+ Size = 12
+ },
+ new InsideVerticalBorder
+ {
+ Val = new EnumValue(BorderValues.Single),
+ Size = 12
+ }));
+
+ table.AppendChild(props);
+
+ for (var i = 0; i <= data.GetUpperBound(0); i++)
+ {
+ var tr = new TableRow();
+ for (var j = 0; j <= data.GetUpperBound(1); j++)
+ {
+ var tc = new TableCell();
+ tc.Append(new Paragraph(new Run(new Text(data[i, j]))));
+
+ // Assume you want columns that are automatically sized.
+ tc.Append(new TableCellProperties(
+ new TableCellWidth { Type = TableWidthUnitValues.Auto }));
+
+ tr.Append(tc);
+ }
+ table.Append(tr);
+ }
+ doc.Body.Append(table);
+ doc.Save();
+ }
+}
\ No newline at end of file
diff --git a/samples/word/add_tables/cs/add_tables_cs.csproj b/samples/word/add_tables/cs/add_tables_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/add_tables/cs/add_tables_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/add_tables/vb/Program.vb b/samples/word/add_tables/vb/Program.vb
new file mode 100644
index 00000000..b3f29cad
--- /dev/null
+++ b/samples/word/add_tables/vb/Program.vb
@@ -0,0 +1,67 @@
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+Imports BottomBorder = DocumentFormat.OpenXml.Wordprocessing.BottomBorder
+Imports LeftBorder = DocumentFormat.OpenXml.Wordprocessing.LeftBorder
+Imports RightBorder = DocumentFormat.OpenXml.Wordprocessing.RightBorder
+Imports Run = DocumentFormat.OpenXml.Wordprocessing.Run
+Imports Table = DocumentFormat.OpenXml.Wordprocessing.Table
+Imports Text = DocumentFormat.OpenXml.Wordprocessing.Text
+Imports TopBorder = DocumentFormat.OpenXml.Wordprocessing.TopBorder
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+ ' Take the data from a two-dimensional array and build a table at the
+ ' end of the supplied document.
+ Public Sub AddTable(ByVal fileName As String,
+ ByVal data(,) As String)
+ Using document = WordprocessingDocument.Open(fileName, True)
+
+ Dim doc = document.MainDocumentPart.Document
+
+ Dim table As New Table()
+
+ Dim props As TableProperties = _
+ New TableProperties(New TableBorders( _
+ New TopBorder With {
+ .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
+ .Size = 12},
+ New BottomBorder With {
+ .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
+ .Size = 12},
+ New LeftBorder With {
+ .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
+ .Size = 12},
+ New RightBorder With {
+ .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
+ .Size = 12}, _
+ New InsideHorizontalBorder With {
+ .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
+ .Size = 12}, _
+ New InsideVerticalBorder With {
+ .Val = New EnumValue(Of BorderValues)(BorderValues.Single),
+ .Size = 12}))
+ table.AppendChild(Of TableProperties)(props)
+
+ For i = 0 To UBound(data, 1)
+ Dim tr As New TableRow
+ For j = 0 To UBound(data, 2)
+ Dim tc As New TableCell
+ tc.Append(New Paragraph(New Run(New Text(data(i, j)))))
+
+ ' Assume you want columns that are automatically sized.
+ tc.Append(New TableCellProperties(
+ New TableCellWidth With {.Type = TableWidthUnitValues.Auto}))
+
+ tr.Append(tc)
+ Next
+ table.Append(tr)
+ Next
+ doc.Body.Append(table)
+ doc.Save()
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/add_tables/vb/add_tables_vb.vbproj b/samples/word/add_tables/vb/add_tables_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/add_tables/vb/add_tables_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/change_text_a_table/cs/Program.cs b/samples/word/change_text_a_table/cs/Program.cs
new file mode 100644
index 00000000..e494c04f
--- /dev/null
+++ b/samples/word/change_text_a_table/cs/Program.cs
@@ -0,0 +1,35 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.Linq;
+
+// Change the text in a table in a word processing document.
+static void ChangeTextInCell(string filepath, string txt)
+{
+ // Use the file name and path passed in as an argument to
+ // open an existing document.
+ using (WordprocessingDocument doc =
+ WordprocessingDocument.Open(filepath, true))
+ {
+ // Find the first table in the document.
+ Table table =
+ doc.MainDocumentPart.Document.Body.Elements
().First();
+
+ // Find the second row in the table.
+ TableRow row = table.Elements().ElementAt(1);
+
+ // Find the third cell in the row.
+ TableCell cell = row.Elements().ElementAt(2);
+
+ // Find the first paragraph in the table cell.
+ Paragraph p = cell.Elements().First();
+
+ // Find the first run in the paragraph.
+ Run r = p.Elements().First();
+
+ // Set the text for the run.
+ Text t = r.Elements().First();
+ t.Text = txt;
+ }
+}
\ No newline at end of file
diff --git a/samples/word/change_text_a_table/cs/change_text_a_table_cs.csproj b/samples/word/change_text_a_table/cs/change_text_a_table_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/change_text_a_table/cs/change_text_a_table_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/change_text_a_table/vb/Program.vb b/samples/word/change_text_a_table/vb/Program.vb
new file mode 100644
index 00000000..f7508208
--- /dev/null
+++ b/samples/word/change_text_a_table/vb/Program.vb
@@ -0,0 +1,35 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Change the text in a table in a word processing document.
+ Public Sub ChangeTextInCell(ByVal filepath As String, ByVal txt As String)
+ ' Use the file name and path passed in as an argument to
+ ' Open an existing document.
+ Using doc As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
+ ' Find the first table in the document.
+ Dim table As Table = doc.MainDocumentPart.Document.Body.Elements(Of Table)().First()
+
+ ' Find the second row in the table.
+ Dim row As TableRow = table.Elements(Of TableRow)().ElementAt(1)
+
+ ' Find the third cell in the row.
+ Dim cell As TableCell = row.Elements(Of TableCell)().ElementAt(2)
+
+ ' Find the first paragraph in the table cell.
+ Dim p As Paragraph = cell.Elements(Of Paragraph)().First()
+
+ ' Find the first run in the paragraph.
+ Dim r As Run = p.Elements(Of Run)().First()
+
+ ' Set the text for the run.
+ Dim t As Text = r.Elements(Of Text)().First()
+ t.Text = txt
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/change_text_a_table/vb/change_text_a_table_vb.vbproj b/samples/word/change_text_a_table/vb/change_text_a_table_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/change_text_a_table/vb/change_text_a_table_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/change_the_print_orientation/cs/Program.cs b/samples/word/change_the_print_orientation/cs/Program.cs
new file mode 100644
index 00000000..25ba5bdd
--- /dev/null
+++ b/samples/word/change_the_print_orientation/cs/Program.cs
@@ -0,0 +1,107 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.Linq;
+
+namespace ChangePrintOrientation
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ SetPrintOrientation(@"C:\Users\Public\Documents\ChangePrintOrientation.docx",
+ PageOrientationValues.Landscape);
+ }
+
+ // Given a document name, set the print orientation for
+ // all the sections of the document.
+ public static void SetPrintOrientation(
+ string fileName, PageOrientationValues newOrientation)
+ {
+ using (var document =
+ WordprocessingDocument.Open(fileName, true))
+ {
+ bool documentChanged = false;
+
+ var docPart = document.MainDocumentPart;
+ var sections = docPart.Document.Descendants();
+
+ foreach (SectionProperties sectPr in sections)
+ {
+ bool pageOrientationChanged = false;
+
+ PageSize pgSz = sectPr.Descendants().FirstOrDefault();
+ if (pgSz != null)
+ {
+ // No Orient property? Create it now. Otherwise, just
+ // set its value. Assume that the default orientation
+ // is Portrait.
+ if (pgSz.Orient == null)
+ {
+ // Need to create the attribute. You do not need to
+ // create the Orient property if the property does not
+ // already exist, and you are setting it to Portrait.
+ // That is the default value.
+ if (newOrientation != PageOrientationValues.Portrait)
+ {
+ pageOrientationChanged = true;
+ documentChanged = true;
+ pgSz.Orient =
+ new EnumValue(newOrientation);
+ }
+ }
+ else
+ {
+ // The Orient property exists, but its value
+ // is different than the new value.
+ if (pgSz.Orient.Value != newOrientation)
+ {
+ pgSz.Orient.Value = newOrientation;
+ pageOrientationChanged = true;
+ documentChanged = true;
+ }
+ }
+
+ if (pageOrientationChanged)
+ {
+ // Changing the orientation is not enough. You must also
+ // change the page size.
+ var width = pgSz.Width;
+ var height = pgSz.Height;
+ pgSz.Width = height;
+ pgSz.Height = width;
+
+ PageMargin pgMar =
+ sectPr.Descendants().FirstOrDefault();
+ if (pgMar != null)
+ {
+ // Rotate margins. Printer settings control how far you
+ // rotate when switching to landscape mode. Not having those
+ // settings, this code rotates 90 degrees. You could easily
+ // modify this behavior, or make it a parameter for the
+ // procedure.
+ var top = pgMar.Top.Value;
+ var bottom = pgMar.Bottom.Value;
+ var left = pgMar.Left.Value;
+ var right = pgMar.Right.Value;
+
+ pgMar.Top = new Int32Value((int)left);
+ pgMar.Bottom = new Int32Value((int)right);
+ pgMar.Left =
+ new UInt32Value((uint)System.Math.Max(0, bottom));
+ pgMar.Right =
+ new UInt32Value((uint)System.Math.Max(0, top));
+ }
+ }
+ }
+ }
+ if (documentChanged)
+ {
+ docPart.Document.Save();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/change_the_print_orientation/cs/change_the_print_orientation_cs.csproj b/samples/word/change_the_print_orientation/cs/change_the_print_orientation_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/change_the_print_orientation/cs/change_the_print_orientation_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/change_the_print_orientation/vb/Program.vb b/samples/word/change_the_print_orientation/vb/Program.vb
new file mode 100644
index 00000000..587b64ae
--- /dev/null
+++ b/samples/word/change_the_print_orientation/vb/Program.vb
@@ -0,0 +1,90 @@
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Given a document name, set the print orientation for
+ ' all the sections of the document.
+ Public Sub SetPrintOrientation(
+ ByVal fileName As String, ByVal newOrientation As PageOrientationValues)
+ Using document =
+ WordprocessingDocument.Open(fileName, True)
+ Dim documentChanged As Boolean = False
+
+ Dim docPart = document.MainDocumentPart
+ Dim sections = docPart.Document.Descendants(Of SectionProperties)()
+
+ For Each sectPr As SectionProperties In sections
+
+ Dim pageOrientationChanged As Boolean = False
+
+ Dim pgSz As PageSize =
+ sectPr.Descendants(Of PageSize).FirstOrDefault
+ If pgSz IsNot Nothing Then
+ ' No Orient property? Create it now. Otherwise, just
+ ' set its value. Assume that the default orientation
+ ' is Portrait.
+ If pgSz.Orient Is Nothing Then
+ ' Need to create the attribute. You do not need to
+ ' create the Orient property if the property does not
+ ' already exist and you are setting it to Portrait.
+ ' That is the default value.
+ If newOrientation <> PageOrientationValues.Portrait Then
+ pageOrientationChanged = True
+ documentChanged = True
+ pgSz.Orient =
+ New EnumValue(Of PageOrientationValues)(newOrientation)
+ End If
+ Else
+ ' The Orient property exists, but its value
+ ' is different than the new value.
+ If pgSz.Orient.Value <> newOrientation Then
+ pgSz.Orient.Value = newOrientation
+ pageOrientationChanged = True
+ documentChanged = True
+ End If
+ End If
+
+ If pageOrientationChanged Then
+ ' Changing the orientation is not enough. You must also
+ ' change the page size.
+ Dim width = pgSz.Width
+ Dim height = pgSz.Height
+ pgSz.Width = height
+ pgSz.Height = width
+
+ Dim pgMar As PageMargin =
+ sectPr.Descendants(Of PageMargin).FirstOrDefault()
+ If pgMar IsNot Nothing Then
+ ' Rotate margins. Printer settings control how far you
+ ' rotate when switching to landscape mode. Not having those
+ ' settings, this code rotates 90 degrees. You could easily
+ ' modify this behavior, or make it a parameter for the
+ ' procedure.
+ Dim top = pgMar.Top.Value
+ Dim bottom = pgMar.Bottom.Value
+ Dim left = pgMar.Left.Value
+ Dim right = pgMar.Right.Value
+
+ pgMar.Top = CType(left, Int32Value)
+ pgMar.Bottom = CType(right, Int32Value)
+ pgMar.Left = CType(System.Math.Max(0,
+ CType(bottom, Int32Value)), UInt32Value)
+ pgMar.Right = CType(System.Math.Max(0,
+ CType(top, Int32Value)), UInt32Value)
+ End If
+ End If
+ End If
+ Next
+
+ If documentChanged Then
+ docPart.Document.Save()
+ End If
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/change_the_print_orientation/vb/change_the_print_orientation_vb.vbproj b/samples/word/change_the_print_orientation/vb/change_the_print_orientation_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/change_the_print_orientation/vb/change_the_print_orientation_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs b/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs
new file mode 100644
index 00000000..dc7a226a
--- /dev/null
+++ b/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/Program.cs
@@ -0,0 +1,53 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using System.IO;
+
+// Given a .docm file (with macro storage), remove the VBA
+// project, reset the document type, and save the document with a new name.
+static void ConvertDOCMtoDOCX(string fileName)
+{
+ bool fileChanged = false;
+
+ using (WordprocessingDocument document =
+ WordprocessingDocument.Open(fileName, true))
+ {
+ // Access the main document part.
+ var docPart = document.MainDocumentPart;
+
+ // Look for the vbaProject part. If it is there, delete it.
+ var vbaPart = docPart.VbaProjectPart;
+ if (vbaPart != null)
+ {
+ // Delete the vbaProject part and then save the document.
+ docPart.DeletePart(vbaPart);
+ docPart.Document.Save();
+
+ // Change the document type to
+ // not macro-enabled.
+ document.ChangeDocumentType(
+ WordprocessingDocumentType.Document);
+
+ // Track that the document has been changed.
+ fileChanged = true;
+ }
+ }
+
+ // If anything goes wrong in this file handling,
+ // the code will raise an exception back to the caller.
+ if (fileChanged)
+ {
+ // Create the new .docx filename.
+ var newFileName = Path.ChangeExtension(fileName, ".docx");
+
+ // If it already exists, it will be deleted!
+ if (File.Exists(newFileName))
+ {
+ File.Delete(newFileName);
+ }
+
+ // Rename the file.
+ File.Move(fileName, newFileName);
+ }
+}
\ No newline at end of file
diff --git a/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/convert_from_the_docm_to_the_docx_file_format_cs.csproj b/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/convert_from_the_docm_to_the_docx_file_format_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/convert_from_the_docm_to_the_docx_file_format/cs/convert_from_the_docm_to_the_docx_file_format_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/Program.vb b/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/Program.vb
new file mode 100644
index 00000000..f47f5c16
--- /dev/null
+++ b/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/Program.vb
@@ -0,0 +1,56 @@
+Imports System.IO
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Given a .docm file (with macro storage), remove the VBA
+ ' project, reset the document type, and save the document with a new name.
+ Public Sub ConvertDOCMtoDOCX(ByVal fileName As String)
+ Dim fileChanged As Boolean = False
+
+ Using document As WordprocessingDocument =
+ WordprocessingDocument.Open(fileName, True)
+
+ ' Access the main document part.
+ Dim docPart = document.MainDocumentPart
+
+ ' Look for the vbaProject part. If it is there, delete it.
+ Dim vbaPart = docPart.VbaProjectPart
+ If vbaPart IsNot Nothing Then
+
+ ' Delete the vbaProject part and then save the document.
+ docPart.DeletePart(vbaPart)
+ docPart.Document.Save()
+
+ ' Change the document type to
+ ' not macro-enabled.
+ document.ChangeDocumentType(
+ WordprocessingDocumentType.Document)
+
+ ' Track that the document has been changed.
+ fileChanged = True
+ End If
+ End Using
+
+ ' If anything goes wrong in this file handling,
+ ' the code will raise an exception back to the caller.
+ If fileChanged Then
+
+ ' Create the new .docx filename.
+ Dim newFileName = Path.ChangeExtension(fileName, ".docx")
+
+ ' If it already exists, it will be deleted!
+ If File.Exists(newFileName) Then
+ File.Delete(newFileName)
+ End If
+
+ ' Rename the file.
+ File.Move(fileName, newFileName)
+ End If
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/convert_from_the_docm_to_the_docx_file_format_vb.vbproj b/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/convert_from_the_docm_to_the_docx_file_format_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/convert_from_the_docm_to_the_docx_file_format/vb/convert_from_the_docm_to_the_docx_file_format_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_character_style/cs/Program.cs b/samples/word/create_and_add_a_character_style/cs/Program.cs
new file mode 100644
index 00000000..7b57a2a3
--- /dev/null
+++ b/samples/word/create_and_add_a_character_style/cs/Program.cs
@@ -0,0 +1,59 @@
+#nullable disable
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+
+// Create a new character style with the specified style id, style name and aliases and
+// add it to the specified style definitions part.
+static void CreateAndAddCharacterStyle(StyleDefinitionsPart styleDefinitionsPart,
+ string styleid, string stylename, string aliases = "")
+{
+ // Get access to the root element of the styles part.
+ Styles styles = styleDefinitionsPart.Styles;
+
+ // Create a new character style and specify some of the attributes.
+ Style style = new Style()
+ {
+ Type = StyleValues.Character,
+ StyleId = styleid,
+ CustomStyle = true
+ };
+
+ // Create and add the child elements (properties of the style).
+ Aliases aliases1 = new Aliases() { Val = aliases };
+ StyleName styleName1 = new StyleName() { Val = stylename };
+ LinkedStyle linkedStyle1 = new LinkedStyle() { Val = "OverdueAmountPara" };
+ if (aliases != "")
+ style.Append(aliases1);
+ style.Append(styleName1);
+ style.Append(linkedStyle1);
+
+ // Create the StyleRunProperties object and specify some of the run properties.
+ StyleRunProperties styleRunProperties1 = new StyleRunProperties();
+ Bold bold1 = new Bold();
+ Color color1 = new Color() { ThemeColor = ThemeColorValues.Accent2 };
+ RunFonts font1 = new RunFonts() { Ascii = "Tahoma" };
+ Italic italic1 = new Italic();
+ // Specify a 24 point size.
+ FontSize fontSize1 = new FontSize() { Val = "48" };
+ styleRunProperties1.Append(font1);
+ styleRunProperties1.Append(fontSize1);
+ styleRunProperties1.Append(color1);
+ styleRunProperties1.Append(bold1);
+ styleRunProperties1.Append(italic1);
+
+ // Add the run properties to the style.
+ style.Append(styleRunProperties1);
+
+ // Add the style to the styles part.
+ styles.Append(style);
+}
+
+// Add a StylesDefinitionsPart to the document. Returns a reference to it.
+static StyleDefinitionsPart AddStylesPartToPackage(WordprocessingDocument doc)
+{
+ StyleDefinitionsPart part;
+ part = doc.MainDocumentPart.AddNewPart();
+ Styles root = new Styles();
+ root.Save(part);
+ return part;
+}
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_character_style/cs/create_and_add_a_character_style_cs.csproj b/samples/word/create_and_add_a_character_style/cs/create_and_add_a_character_style_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/create_and_add_a_character_style/cs/create_and_add_a_character_style_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_character_style/vb/Program.vb b/samples/word/create_and_add_a_character_style/vb/Program.vb
new file mode 100644
index 00000000..0048c84a
--- /dev/null
+++ b/samples/word/create_and_add_a_character_style/vb/Program.vb
@@ -0,0 +1,71 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+Imports Bold = DocumentFormat.OpenXml.Wordprocessing.Bold
+Imports Color = DocumentFormat.OpenXml.Wordprocessing.Color
+Imports FontSize = DocumentFormat.OpenXml.Wordprocessing.FontSize
+Imports Italic = DocumentFormat.OpenXml.Wordprocessing.Italic
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+ ' Create a new character style with the specified style id, style name and aliases and add
+ ' it to the specified style definitions part.
+ Public Sub CreateAndAddCharacterStyle(ByVal styleDefinitionsPart As StyleDefinitionsPart,
+ ByVal styleid As String, ByVal stylename As String, Optional ByVal aliases As String = "")
+ ' Get access to the root element of the styles part.
+ Dim styles As Styles = styleDefinitionsPart.Styles
+ If styles Is Nothing Then
+ styleDefinitionsPart.Styles = New Styles()
+ styleDefinitionsPart.Styles.Save()
+ End If
+
+ ' Create a new character style and specify some of the attributes.
+ Dim style As New Style() With { _
+ .Type = StyleValues.Character, _
+ .StyleId = styleid, _
+ .CustomStyle = True}
+
+ ' Create and add the child elements (properties of the style).
+ Dim aliases1 As New Aliases() With {.Val = aliases}
+ Dim styleName1 As New StyleName() With {.Val = stylename}
+ Dim linkedStyle1 As New LinkedStyle() With {.Val = "OverdueAmountPara"}
+ If aliases <> "" Then
+ style.Append(aliases1)
+ End If
+ style.Append(styleName1)
+ style.Append(linkedStyle1)
+
+ ' Create the StyleRunProperties object and specify some of the run properties.
+ Dim styleRunProperties1 As New StyleRunProperties()
+ Dim bold1 As New Bold()
+ Dim color1 As New Color() With { _
+ .ThemeColor = ThemeColorValues.Accent2}
+ Dim font1 As New RunFonts() With {.Ascii = "Tahoma"}
+ Dim italic1 As New Italic()
+ ' Specify a 24 point size.
+ Dim fontSize1 As New FontSize() With {.Val = "48"}
+ styleRunProperties1.Append(font1)
+ styleRunProperties1.Append(fontSize1)
+ styleRunProperties1.Append(color1)
+ styleRunProperties1.Append(bold1)
+ styleRunProperties1.Append(italic1)
+
+ ' Add the run properties to the style.
+ style.Append(styleRunProperties1)
+
+ ' Add the style to the styles part.
+ styles.Append(style)
+ End Sub
+
+ ' Add a StylesDefinitionsPart to the document. Returns a reference to it.
+ Public Function AddStylesPartToPackage(ByVal doc As WordprocessingDocument) _
+ As StyleDefinitionsPart
+ Dim part As StyleDefinitionsPart
+ part = doc.MainDocumentPart.AddNewPart(Of StyleDefinitionsPart)()
+ Dim root As New Styles()
+ root.Save(part)
+ Return part
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_character_style/vb/create_and_add_a_character_style_vb.vbproj b/samples/word/create_and_add_a_character_style/vb/create_and_add_a_character_style_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/create_and_add_a_character_style/vb/create_and_add_a_character_style_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_paragraph_style/cs/Program.cs b/samples/word/create_and_add_a_paragraph_style/cs/Program.cs
new file mode 100644
index 00000000..408aa16d
--- /dev/null
+++ b/samples/word/create_and_add_a_paragraph_style/cs/Program.cs
@@ -0,0 +1,83 @@
+#nullable disable
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+
+// Create a new paragraph style with the specified style ID, primary style name, and aliases and
+// add it to the specified style definitions part.
+static void CreateAndAddParagraphStyle(StyleDefinitionsPart styleDefinitionsPart,
+ string styleid, string stylename, string aliases = "")
+{
+ // Access the root element of the styles part.
+ Styles styles = styleDefinitionsPart.Styles;
+ if (styles == null)
+ {
+ styleDefinitionsPart.Styles = new Styles();
+ styleDefinitionsPart.Styles.Save();
+ }
+
+ // Create a new paragraph style element and specify some of the attributes.
+ Style style = new Style()
+ {
+ Type = StyleValues.Paragraph,
+ StyleId = styleid,
+ CustomStyle = true,
+ Default = false
+ };
+
+ // Create and add the child elements (properties of the style).
+ Aliases aliases1 = new Aliases() { Val = aliases };
+ AutoRedefine autoredefine1 = new AutoRedefine() { Val = OnOffOnlyValues.Off };
+ BasedOn basedon1 = new BasedOn() { Val = "Normal" };
+ LinkedStyle linkedStyle1 = new LinkedStyle() { Val = "OverdueAmountChar" };
+ Locked locked1 = new Locked() { Val = OnOffOnlyValues.Off };
+ PrimaryStyle primarystyle1 = new PrimaryStyle() { Val = OnOffOnlyValues.On };
+ StyleHidden stylehidden1 = new StyleHidden() { Val = OnOffOnlyValues.Off };
+ SemiHidden semihidden1 = new SemiHidden() { Val = OnOffOnlyValues.Off };
+ StyleName styleName1 = new StyleName() { Val = stylename };
+ NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = "Normal" };
+ UIPriority uipriority1 = new UIPriority() { Val = 1 };
+ UnhideWhenUsed unhidewhenused1 = new UnhideWhenUsed() { Val = OnOffOnlyValues.On };
+ if (aliases != "")
+ style.Append(aliases1);
+ style.Append(autoredefine1);
+ style.Append(basedon1);
+ style.Append(linkedStyle1);
+ style.Append(locked1);
+ style.Append(primarystyle1);
+ style.Append(stylehidden1);
+ style.Append(semihidden1);
+ style.Append(styleName1);
+ style.Append(nextParagraphStyle1);
+ style.Append(uipriority1);
+ style.Append(unhidewhenused1);
+
+ // Create the StyleRunProperties object and specify some of the run properties.
+ StyleRunProperties styleRunProperties1 = new StyleRunProperties();
+ Bold bold1 = new Bold();
+ Color color1 = new Color() { ThemeColor = ThemeColorValues.Accent2 };
+ RunFonts font1 = new RunFonts() { Ascii = "Lucida Console" };
+ Italic italic1 = new Italic();
+ // Specify a 12 point size.
+ FontSize fontSize1 = new FontSize() { Val = "24" };
+ styleRunProperties1.Append(bold1);
+ styleRunProperties1.Append(color1);
+ styleRunProperties1.Append(font1);
+ styleRunProperties1.Append(fontSize1);
+ styleRunProperties1.Append(italic1);
+
+ // Add the run properties to the style.
+ style.Append(styleRunProperties1);
+
+ // Add the style to the styles part.
+ styles.Append(style);
+}
+
+// Add a StylesDefinitionsPart to the document. Returns a reference to it.
+static StyleDefinitionsPart AddStylesPartToPackage(WordprocessingDocument doc)
+{
+ StyleDefinitionsPart part;
+ part = doc.MainDocumentPart.AddNewPart();
+ Styles root = new Styles();
+ root.Save(part);
+ return part;
+}
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_paragraph_style/cs/create_and_add_a_paragraph_style_cs.csproj b/samples/word/create_and_add_a_paragraph_style/cs/create_and_add_a_paragraph_style_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/create_and_add_a_paragraph_style/cs/create_and_add_a_paragraph_style_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_paragraph_style/vb/Program.vb b/samples/word/create_and_add_a_paragraph_style/vb/Program.vb
new file mode 100644
index 00000000..5a6bcba8
--- /dev/null
+++ b/samples/word/create_and_add_a_paragraph_style/vb/Program.vb
@@ -0,0 +1,91 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+ ' Create a new paragraph style with the specified style ID, primary style name, and aliases and
+ ' add it to the specified style definitions part.
+ Public Sub CreateAndAddParagraphStyle(ByVal styleDefinitionsPart As StyleDefinitionsPart,
+ ByVal styleid As String, ByVal stylename As String, Optional ByVal aliases As String = "")
+
+ ' Access the root element of the styles part.
+ Dim styles As Styles = styleDefinitionsPart.Styles
+ If styles Is Nothing Then
+ styleDefinitionsPart.Styles = New Styles()
+ styleDefinitionsPart.Styles.Save()
+ End If
+
+ ' Create a new paragraph style element and specify some of the attributes.
+ Dim style As New Style() With { _
+ .Type = StyleValues.Paragraph, _
+ .StyleId = styleid, _
+ .CustomStyle = True, _
+ .[Default] = False}
+
+ ' Create and add the child elements (properties of the style)
+ Dim aliases1 As New Aliases() With {.Val = aliases}
+ Dim autoredefine1 As New AutoRedefine() With {.Val = OnOffOnlyValues.Off}
+ Dim basedon1 As New BasedOn() With {.Val = "Normal"}
+ Dim linkedStyle1 As New LinkedStyle() With {.Val = "OverdueAmountChar"}
+ Dim locked1 As New Locked() With {.Val = OnOffOnlyValues.Off}
+ Dim primarystyle1 As New PrimaryStyle() With {.Val = OnOffOnlyValues.[On]}
+ Dim stylehidden1 As New StyleHidden() With {.Val = OnOffOnlyValues.Off}
+ Dim semihidden1 As New SemiHidden() With {.Val = OnOffOnlyValues.Off}
+ Dim styleName1 As New StyleName() With {.Val = stylename}
+ Dim nextParagraphStyle1 As New NextParagraphStyle() With { _
+ .Val = "Normal"}
+ Dim uipriority1 As New UIPriority() With {.Val = 1}
+ Dim unhidewhenused1 As New UnhideWhenUsed() With { _
+ .Val = OnOffOnlyValues.[On]}
+ If aliases <> "" Then
+ style.Append(aliases1)
+ End If
+ style.Append(autoredefine1)
+ style.Append(basedon1)
+ style.Append(linkedStyle1)
+ style.Append(locked1)
+ style.Append(primarystyle1)
+ style.Append(stylehidden1)
+ style.Append(semihidden1)
+ style.Append(styleName1)
+ style.Append(nextParagraphStyle1)
+ style.Append(uipriority1)
+ style.Append(unhidewhenused1)
+
+ ' Create the StyleRunProperties object and specify some of the run properties.
+ Dim styleRunProperties1 As New StyleRunProperties()
+ Dim bold1 As New Bold()
+ Dim color1 As New Color() With { _
+ .ThemeColor = ThemeColorValues.Accent2}
+ Dim font1 As New RunFonts() With { _
+ .Ascii = "Lucida Console"}
+ Dim italic1 As New Italic()
+ ' Specify a 12 point size.
+ Dim fontSize1 As New FontSize() With { _
+ .Val = "24"}
+ styleRunProperties1.Append(bold1)
+ styleRunProperties1.Append(color1)
+ styleRunProperties1.Append(font1)
+ styleRunProperties1.Append(fontSize1)
+ styleRunProperties1.Append(italic1)
+
+ ' Add the run properties to the style.
+ style.Append(styleRunProperties1)
+
+ ' Add the style to the styles part.
+ styles.Append(style)
+ End Sub
+
+ ' Add a StylesDefinitionsPart to the document. Returns a reference to it.
+ Public Function AddStylesPartToPackage(ByVal doc As WordprocessingDocument) _
+ As StyleDefinitionsPart
+ Dim part As StyleDefinitionsPart
+ part = doc.MainDocumentPart.AddNewPart(Of StyleDefinitionsPart)()
+ Dim root As New Styles()
+ root.Save(part)
+ Return part
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/word/create_and_add_a_paragraph_style/vb/create_and_add_a_paragraph_style_vb.vbproj b/samples/word/create_and_add_a_paragraph_style/vb/create_and_add_a_paragraph_style_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/create_and_add_a_paragraph_style/vb/create_and_add_a_paragraph_style_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs b/samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs
new file mode 100644
index 00000000..3f5afcda
--- /dev/null
+++ b/samples/word/delete_comments_by_all_or_a_specific_author/cs/Program.cs
@@ -0,0 +1,84 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+// Delete comments by a specific author. Pass an empty string for the
+// author to delete all comments, by all authors.
+static void DeleteComments(string fileName,
+ string author = "")
+{
+ // Get an existing Wordprocessing document.
+ using (WordprocessingDocument document = WordprocessingDocument.Open(fileName, true))
+ {
+ // Set commentPart to the document WordprocessingCommentsPart,
+ // if it exists.
+ WordprocessingCommentsPart commentPart =
+ document.MainDocumentPart.WordprocessingCommentsPart;
+
+ // If no WordprocessingCommentsPart exists, there can be no
+ // comments. Stop execution and return from the method.
+ if (commentPart == null)
+ {
+ return;
+ }
+
+ // Create a list of comments by the specified author, or
+ // if the author name is empty, all authors.
+ List commentsToDelete =
+ commentPart.Comments.Elements().ToList();
+ if (!String.IsNullOrEmpty(author))
+ {
+ commentsToDelete = commentsToDelete.
+ Where(c => c.Author == author).ToList();
+ }
+ IEnumerable commentIds =
+ commentsToDelete.Select(r => r.Id.Value);
+
+ // Delete each comment in commentToDelete from the
+ // Comments collection.
+ foreach (Comment c in commentsToDelete)
+ {
+ c.Remove();
+ }
+
+ // Save the comment part change.
+ commentPart.Comments.Save();
+
+ Document doc = document.MainDocumentPart.Document;
+
+ // Delete CommentRangeStart for each
+ // deleted comment in the main document.
+ List commentRangeStartToDelete =
+ doc.Descendants().
+ Where(c => commentIds.Contains(c.Id.Value)).ToList();
+ foreach (CommentRangeStart c in commentRangeStartToDelete)
+ {
+ c.Remove();
+ }
+
+ // Delete CommentRangeEnd for each deleted comment in the main document.
+ List commentRangeEndToDelete =
+ doc.Descendants().
+ Where(c => commentIds.Contains(c.Id.Value)).ToList();
+ foreach (CommentRangeEnd c in commentRangeEndToDelete)
+ {
+ c.Remove();
+ }
+
+ // Delete CommentReference for each deleted comment in the main document.
+ List commentRangeReferenceToDelete =
+ doc.Descendants().
+ Where(c => commentIds.Contains(c.Id.Value)).ToList();
+ foreach (CommentReference c in commentRangeReferenceToDelete)
+ {
+ c.Remove();
+ }
+
+ // Save changes back to the MainDocumentPart part.
+ doc.Save();
+ }
+}
\ No newline at end of file
diff --git a/samples/word/delete_comments_by_all_or_a_specific_author/cs/delete_comments_by_all_or_a_specific_author_cs.csproj b/samples/word/delete_comments_by_all_or_a_specific_author/cs/delete_comments_by_all_or_a_specific_author_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/delete_comments_by_all_or_a_specific_author/cs/delete_comments_by_all_or_a_specific_author_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/delete_comments_by_all_or_a_specific_author/vb/Program.vb b/samples/word/delete_comments_by_all_or_a_specific_author/vb/Program.vb
new file mode 100644
index 00000000..e7097e51
--- /dev/null
+++ b/samples/word/delete_comments_by_all_or_a_specific_author/vb/Program.vb
@@ -0,0 +1,79 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+ ' Delete comments by a specific author. Pass an empty string for the author
+ ' to delete all comments, by all authors.
+ Public Sub DeleteComments(ByVal fileName As String,
+ Optional ByVal author As String = "")
+
+ ' Get an existing Wordprocessing document.
+ Using document As WordprocessingDocument =
+ WordprocessingDocument.Open(fileName, True)
+ ' Set commentPart to the document
+ ' WordprocessingCommentsPart, if it exists.
+ Dim commentPart As WordprocessingCommentsPart =
+ document.MainDocumentPart.WordprocessingCommentsPart
+
+ ' If no WordprocessingCommentsPart exists, there can be no
+ ' comments. Stop execution and return from the method.
+ If (commentPart Is Nothing) Then
+ Return
+ End If
+
+ ' Create a list of comments by the specified author, or
+ ' if the author name is empty, all authors.
+ Dim commentsToDelete As List(Of Comment) = _
+ commentPart.Comments.Elements(Of Comment)().ToList()
+ If Not String.IsNullOrEmpty(author) Then
+ commentsToDelete = commentsToDelete.
+ Where(Function(c) c.Author = author).ToList()
+ End If
+ Dim commentIds As IEnumerable(Of String) =
+ commentsToDelete.Select(Function(r) r.Id.Value)
+
+ ' Delete each comment in commentToDelete from the Comments
+ ' collection.
+ For Each c As Comment In commentsToDelete
+ c.Remove()
+ Next
+
+ ' Save the comment part change.
+ commentPart.Comments.Save()
+
+ Dim doc As Document = document.MainDocumentPart.Document
+
+ ' Delete CommentRangeStart for each
+ ' deleted comment in the main document.
+ Dim commentRangeStartToDelete As List(Of CommentRangeStart) = _
+ doc.Descendants(Of CommentRangeStart). _
+ Where(Function(c) commentIds.Contains(c.Id.Value)).ToList()
+ For Each c As CommentRangeStart In commentRangeStartToDelete
+ c.Remove()
+ Next
+
+ ' Delete CommentRangeEnd for each deleted comment in main document.
+ Dim commentRangeEndToDelete As List(Of CommentRangeEnd) = _
+ doc.Descendants(Of CommentRangeEnd). _
+ Where(Function(c) commentIds.Contains(c.Id.Value)).ToList()
+ For Each c As CommentRangeEnd In commentRangeEndToDelete
+ c.Remove()
+ Next
+
+ ' Delete CommentReference for each deleted comment in the main document.
+ Dim commentRangeReferenceToDelete As List(Of CommentReference) = _
+ doc.Descendants(Of CommentReference). _
+ Where(Function(c) commentIds.Contains(c.Id.Value)).ToList
+ For Each c As CommentReference In commentRangeReferenceToDelete
+ c.Remove()
+ Next
+
+ ' Save changes back to the MainDocumentPart part.
+ doc.Save()
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/delete_comments_by_all_or_a_specific_author/vb/delete_comments_by_all_or_a_specific_author_vb.vbproj b/samples/word/delete_comments_by_all_or_a_specific_author/vb/delete_comments_by_all_or_a_specific_author_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/delete_comments_by_all_or_a_specific_author/vb/delete_comments_by_all_or_a_specific_author_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/extract_styles/cs/Program.cs b/samples/word/extract_styles/cs/Program.cs
new file mode 100644
index 00000000..7d6aa6cf
--- /dev/null
+++ b/samples/word/extract_styles/cs/Program.cs
@@ -0,0 +1,44 @@
+#nullable disable
+using DocumentFormat.OpenXml.Packaging;
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+
+// Extract the styles or stylesWithEffects part from a
+// word processing document as an XDocument instance.
+static XDocument ExtractStylesPart(
+ string fileName,
+ bool getStylesWithEffectsPart = true)
+{
+ // Declare a variable to hold the XDocument.
+ XDocument styles = null;
+
+ // Open the document for read access and get a reference.
+ using (var document =
+ WordprocessingDocument.Open(fileName, false))
+ {
+ // Get a reference to the main document part.
+ var docPart = document.MainDocumentPart;
+
+ // Assign a reference to the appropriate part to the
+ // stylesPart variable.
+ StylesPart stylesPart = null;
+ if (getStylesWithEffectsPart)
+ stylesPart = docPart.StylesWithEffectsPart;
+ else
+ stylesPart = docPart.StyleDefinitionsPart;
+
+ // If the part exists, read it into the XDocument.
+ if (stylesPart != null)
+ {
+ using (var reader = XmlNodeReader.Create(
+ stylesPart.GetStream(FileMode.Open, FileAccess.Read)))
+ {
+ // Create the XDocument.
+ styles = XDocument.Load(reader);
+ }
+ }
+ }
+ // Return the XDocument instance.
+ return styles;
+}
\ No newline at end of file
diff --git a/samples/word/extract_styles/cs/extract_styles_cs.csproj b/samples/word/extract_styles/cs/extract_styles_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/extract_styles/cs/extract_styles_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/extract_styles/vb/Program.vb b/samples/word/extract_styles/vb/Program.vb
new file mode 100644
index 00000000..6a182926
--- /dev/null
+++ b/samples/word/extract_styles/vb/Program.vb
@@ -0,0 +1,47 @@
+Imports System.IO
+Imports System.Xml
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Extract the styles or stylesWithEffects part from a
+ ' word processing document as an XDocument instance.
+ Public Function ExtractStylesPart(
+ ByVal fileName As String,
+ Optional ByVal getStylesWithEffectsPart As Boolean = True) As XDocument
+
+ ' Declare a variable to hold the XDocument.
+ Dim styles As XDocument = Nothing
+
+ ' Open the document for read access and get a reference.
+ Using document = WordprocessingDocument.Open(fileName, False)
+
+ ' Get a reference to the main document part.
+ Dim docPart = document.MainDocumentPart
+
+ ' Assign a reference to the appropriate part to the
+ ' stylesPart variable.
+ Dim stylesPart As StylesPart = Nothing
+ If getStylesWithEffectsPart Then
+ stylesPart = docPart.StylesWithEffectsPart
+ Else
+ stylesPart = docPart.StyleDefinitionsPart
+ End If
+
+ ' If the part exists, read it into the XDocument.
+ If stylesPart IsNot Nothing Then
+ Using reader = XmlNodeReader.Create(
+ stylesPart.GetStream(FileMode.Open, FileAccess.Read))
+ ' Create the XDocument:
+ styles = XDocument.Load(reader)
+ End Using
+ End If
+ End Using
+ ' Return the XDocument instance.
+ Return styles
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/word/extract_styles/vb/extract_styles_vb.vbproj b/samples/word/extract_styles/vb/extract_styles_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/extract_styles/vb/extract_styles_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/insert_a_comment/cs/Program.cs b/samples/word/insert_a_comment/cs/Program.cs
new file mode 100644
index 00000000..428f0440
--- /dev/null
+++ b/samples/word/insert_a_comment/cs/Program.cs
@@ -0,0 +1,68 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System;
+using System.Linq;
+
+// Insert a comment on the first paragraph.
+static void AddCommentOnFirstParagraph(string fileName,
+ string author, string initials, string comment)
+{
+ // Use the file name and path passed in as an
+ // argument to open an existing Wordprocessing document.
+ using (WordprocessingDocument document =
+ WordprocessingDocument.Open(fileName, true))
+ {
+ // Locate the first paragraph in the document.
+ Paragraph firstParagraph =
+ document.MainDocumentPart.Document.Descendants().First();
+ Comments comments = null;
+ string id = "0";
+
+ // Verify that the document contains a
+ // WordProcessingCommentsPart part; if not, add a new one.
+ if (document.MainDocumentPart.GetPartsOfType().Count() > 0)
+ {
+ comments = document.MainDocumentPart.WordprocessingCommentsPart.Comments;
+ if (comments.HasChildren)
+ {
+ // Obtain an unused ID.
+ id = (comments.Descendants().Select(e => int.Parse(e.Id.Value)).Max() + 1).ToString();
+ }
+ }
+ else
+ {
+ // No WordprocessingCommentsPart part exists, so add one to the package.
+ WordprocessingCommentsPart commentPart = document.MainDocumentPart.AddNewPart();
+ commentPart.Comments = new Comments();
+ comments = commentPart.Comments;
+ }
+
+ // Compose a new Comment and add it to the Comments part.
+ Paragraph p = new Paragraph(new Run(new Text(comment)));
+ Comment cmt =
+ new Comment()
+ {
+ Id = id,
+ Author = author,
+ Initials = initials,
+ Date = DateTime.Now
+ };
+ cmt.AppendChild(p);
+ comments.AppendChild(cmt);
+ comments.Save();
+
+ // Specify the text range for the Comment.
+ // Insert the new CommentRangeStart before the first run of paragraph.
+ firstParagraph.InsertBefore(new CommentRangeStart()
+ { Id = id }, firstParagraph.GetFirstChild());
+
+ // Insert the new CommentRangeEnd after last run of paragraph.
+ var cmtEnd = firstParagraph.InsertAfter(new CommentRangeEnd()
+ { Id = id }, firstParagraph.Elements().Last());
+
+ // Compose a run with CommentReference and insert it.
+ firstParagraph.InsertAfter(new Run(new CommentReference() { Id = id }), cmtEnd);
+ }
+}
\ No newline at end of file
diff --git a/samples/word/insert_a_comment/cs/insert_a_comment_cs.csproj b/samples/word/insert_a_comment/cs/insert_a_comment_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/insert_a_comment/cs/insert_a_comment_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/insert_a_comment/vb/Program.vb b/samples/word/insert_a_comment/vb/Program.vb
new file mode 100644
index 00000000..c556b09c
--- /dev/null
+++ b/samples/word/insert_a_comment/vb/Program.vb
@@ -0,0 +1,53 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Insert a comment on the first paragraph.
+ Public Sub AddCommentOnFirstParagraph(ByVal fileName As String, ByVal author As String, ByVal initials As String, ByVal comment As String)
+ ' Use the file name and path passed in as an
+ ' argument to open an existing Wordprocessing document.
+ Using document As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
+ ' Locate the first paragraph in the document.
+ Dim firstParagraph As Paragraph = document.MainDocumentPart.Document.Descendants(Of Paragraph)().First()
+ Dim comments As Comments = Nothing
+ Dim id As String = "0"
+
+ ' Verify that the document contains a
+ ' WordProcessingCommentsPart part; if not, add a new one.
+ If document.MainDocumentPart.GetPartsOfType(Of WordprocessingCommentsPart).Count() > 0 Then
+ comments = document.MainDocumentPart.WordprocessingCommentsPart.Comments
+ If comments.HasChildren Then
+ ' Obtain an unused ID.
+ id = comments.Descendants(Of Comment)().[Select](Function(e) e.Id.Value).Max()
+ End If
+ Else
+ ' No WordprocessingCommentsPart part exists, so add one to the package.
+ Dim commentPart As WordprocessingCommentsPart = document.MainDocumentPart.AddNewPart(Of WordprocessingCommentsPart)()
+ commentPart.Comments = New Comments()
+ comments = commentPart.Comments
+ End If
+
+ ' Compose a new Comment and add it to the Comments part.
+ Dim p As New Paragraph(New Run(New Text(comment)))
+ Dim cmt As New Comment() With {.Id = id, .Author = author, .Initials = initials, .Date = DateTime.Now}
+ cmt.AppendChild(p)
+ comments.AppendChild(cmt)
+ comments.Save()
+
+ ' Specify the text range for the Comment.
+ ' Insert the new CommentRangeStart before the first run of paragraph.
+ firstParagraph.InsertBefore(New CommentRangeStart() With {.Id = id}, firstParagraph.GetFirstChild(Of Run)())
+
+ ' Insert the new CommentRangeEnd after last run of paragraph.
+ Dim cmtEnd = firstParagraph.InsertAfter(New CommentRangeEnd() With {.Id = id}, firstParagraph.Elements(Of Run)().Last())
+
+ ' Compose a run with CommentReference and insert it.
+ firstParagraph.InsertAfter(New Run(New CommentReference() With {.Id = id}), cmtEnd)
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/insert_a_comment/vb/insert_a_comment_vb.vbproj b/samples/word/insert_a_comment/vb/insert_a_comment_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/insert_a_comment/vb/insert_a_comment_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/insert_a_picture/cs/Program.cs b/samples/word/insert_a_picture/cs/Program.cs
new file mode 100644
index 00000000..e053faf6
--- /dev/null
+++ b/samples/word/insert_a_picture/cs/Program.cs
@@ -0,0 +1,97 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.IO;
+using A = DocumentFormat.OpenXml.Drawing;
+using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing;
+using PIC = DocumentFormat.OpenXml.Drawing.Pictures;
+
+static void InsertAPicture(string document, string fileName)
+{
+ using (WordprocessingDocument wordprocessingDocument =
+ WordprocessingDocument.Open(document, true))
+ {
+ MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
+
+ ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
+
+ using (FileStream stream = new FileStream(fileName, FileMode.Open))
+ {
+ imagePart.FeedData(stream);
+ }
+
+ AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));
+ }
+}
+
+static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)
+{
+ // Define the reference of the image.
+ var element =
+ new Drawing(
+ new DW.Inline(
+ new DW.Extent() { Cx = 990000L, Cy = 792000L },
+ new DW.EffectExtent()
+ {
+ LeftEdge = 0L,
+ TopEdge = 0L,
+ RightEdge = 0L,
+ BottomEdge = 0L
+ },
+ new DW.DocProperties()
+ {
+ Id = (UInt32Value)1U,
+ Name = "Picture 1"
+ },
+ new DW.NonVisualGraphicFrameDrawingProperties(
+ new A.GraphicFrameLocks() { NoChangeAspect = true }),
+ new A.Graphic(
+ new A.GraphicData(
+ new PIC.Picture(
+ new PIC.NonVisualPictureProperties(
+ new PIC.NonVisualDrawingProperties()
+ {
+ Id = (UInt32Value)0U,
+ Name = "New Bitmap Image.jpg"
+ },
+ new PIC.NonVisualPictureDrawingProperties()),
+ new PIC.BlipFill(
+ new A.Blip(
+ new A.BlipExtensionList(
+ new A.BlipExtension()
+ {
+ Uri =
+ "{28A0092B-C50C-407E-A947-70E740481C1C}"
+ })
+ )
+ {
+ Embed = relationshipId,
+ CompressionState =
+ A.BlipCompressionValues.Print
+ },
+ new A.Stretch(
+ new A.FillRectangle())),
+ new PIC.ShapeProperties(
+ new A.Transform2D(
+ new A.Offset() { X = 0L, Y = 0L },
+ new A.Extents() { Cx = 990000L, Cy = 792000L }),
+ new A.PresetGeometry(
+ new A.AdjustValueList()
+ )
+ { Preset = A.ShapeTypeValues.Rectangle }))
+ )
+ { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
+ )
+ {
+ DistanceFromTop = (UInt32Value)0U,
+ DistanceFromBottom = (UInt32Value)0U,
+ DistanceFromLeft = (UInt32Value)0U,
+ DistanceFromRight = (UInt32Value)0U,
+ EditId = "50D07946"
+ });
+
+ // Append the reference to body, the element should be in a Run.
+ wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));
+}
\ No newline at end of file
diff --git a/samples/word/insert_a_picture/cs/insert_a_picture_cs.csproj b/samples/word/insert_a_picture/cs/insert_a_picture_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/insert_a_picture/cs/insert_a_picture_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/insert_a_picture/vb/Program.vb b/samples/word/insert_a_picture/vb/Program.vb
new file mode 100644
index 00000000..5359cddc
--- /dev/null
+++ b/samples/word/insert_a_picture/vb/Program.vb
@@ -0,0 +1,74 @@
+Imports System.IO
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+Imports A = DocumentFormat.OpenXml.Drawing
+Imports DW = DocumentFormat.OpenXml.Drawing.Wordprocessing
+Imports PIC = DocumentFormat.OpenXml.Drawing.Pictures
+
+Module Program `
+ Sub Main(args As String())`
+ End Sub`
+
+
+
+ Public Sub InsertAPicture(ByVal document As String, ByVal fileName As String)
+ Using wordprocessingDocument As WordprocessingDocument = WordprocessingDocument.Open(document, True)
+ Dim mainPart As MainDocumentPart = wordprocessingDocument.MainDocumentPart
+
+ Dim imagePart As ImagePart = mainPart.AddImagePart(ImagePartType.Jpeg)
+
+ Using stream As New FileStream(fileName, FileMode.Open)
+ imagePart.FeedData(stream)
+ End Using
+
+ AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart))
+ End Using
+ End Sub
+
+ Private Sub AddImageToBody(ByVal wordDoc As WordprocessingDocument, ByVal relationshipId As String)
+ ' Define the reference of the image.
+ Dim element = New Drawing( _
+ New DW.Inline( _
+ New DW.Extent() With {.Cx = 990000L, .Cy = 792000L}, _
+ New DW.EffectExtent() With {.LeftEdge = 0L, .TopEdge = 0L, .RightEdge = 0L, .BottomEdge = 0L}, _
+ New DW.DocProperties() With {.Id = CType(1UI, UInt32Value), .Name = "Picture1"}, _
+ New DW.NonVisualGraphicFrameDrawingProperties( _
+ New A.GraphicFrameLocks() With {.NoChangeAspect = True} _
+ ), _
+ New A.Graphic(New A.GraphicData( _
+ New PIC.Picture( _
+ New PIC.NonVisualPictureProperties( _
+ New PIC.NonVisualDrawingProperties() With {.Id = 0UI, .Name = "Koala.jpg"}, _
+ New PIC.NonVisualPictureDrawingProperties() _
+ ), _
+ New PIC.BlipFill( _
+ New A.Blip( _
+ New A.BlipExtensionList( _
+ New A.BlipExtension() With {.Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"}) _
+ ) With {.Embed = relationshipId, .CompressionState = A.BlipCompressionValues.Print}, _
+ New A.Stretch( _
+ New A.FillRectangle() _
+ ) _
+ ), _
+ New PIC.ShapeProperties( _
+ New A.Transform2D( _
+ New A.Offset() With {.X = 0L, .Y = 0L}, _
+ New A.Extents() With {.Cx = 990000L, .Cy = 792000L}), _
+ New A.PresetGeometry( _
+ New A.AdjustValueList() _
+ ) With {.Preset = A.ShapeTypeValues.Rectangle} _
+ ) _
+ ) _
+ ) With {.Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"} _
+ ) _
+ ) With {.DistanceFromTop = 0UI, _
+ .DistanceFromBottom = 0UI, _
+ .DistanceFromLeft = 0UI, _
+ .DistanceFromRight = 0UI} _
+ )
+
+ ' Append the reference to body, the element should be in a Run.
+ wordDoc.MainDocumentPart.Document.Body.AppendChild(New Paragraph(New Run(element)))
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/insert_a_picture/vb/insert_a_picture_vb.vbproj b/samples/word/insert_a_picture/vb/insert_a_picture_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/insert_a_picture/vb/insert_a_picture_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/insert_a_table/cs/Program.cs b/samples/word/insert_a_table/cs/Program.cs
new file mode 100644
index 00000000..2d51522b
--- /dev/null
+++ b/samples/word/insert_a_table/cs/Program.cs
@@ -0,0 +1,92 @@
+#nullable disable
+
+using DocumentFormat.OpenXml;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+
+// Insert a table into a word processing document.
+static void CreateTable(string fileName)
+{
+ // Use the file name and path passed in as an argument
+ // to open an existing Word 2007 document.
+
+ using (WordprocessingDocument doc
+ = WordprocessingDocument.Open(fileName, true))
+ {
+ // Create an empty table.
+ Table table = new Table();
+
+ // Create a TableProperties object and specify its border information.
+ TableProperties tblProp = new TableProperties(
+ new TableBorders(
+ new TopBorder()
+ {
+ Val =
+ new EnumValue(BorderValues.Dashed),
+ Size = 24
+ },
+ new BottomBorder()
+ {
+ Val =
+ new EnumValue(BorderValues.Dashed),
+ Size = 24
+ },
+ new LeftBorder()
+ {
+ Val =
+ new EnumValue(BorderValues.Dashed),
+ Size = 24
+ },
+ new RightBorder()
+ {
+ Val =
+ new EnumValue(BorderValues.Dashed),
+ Size = 24
+ },
+ new InsideHorizontalBorder()
+ {
+ Val =
+ new EnumValue(BorderValues.Dashed),
+ Size = 24
+ },
+ new InsideVerticalBorder()
+ {
+ Val =
+ new EnumValue(BorderValues.Dashed),
+ Size = 24
+ }
+ )
+ );
+
+ // Append the TableProperties object to the empty table.
+ table.AppendChild(tblProp);
+
+ // Create a row.
+ TableRow tr = new TableRow();
+
+ // Create a cell.
+ TableCell tc1 = new TableCell();
+
+ // Specify the width property of the table cell.
+ tc1.Append(new TableCellProperties(
+ new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));
+
+ // Specify the table cell content.
+ tc1.Append(new Paragraph(new Run(new Text("some text"))));
+
+ // Append the table cell to the table row.
+ tr.Append(tc1);
+
+ // Create a second table cell by copying the OuterXml value of the first table cell.
+ TableCell tc2 = new TableCell(tc1.OuterXml);
+
+ // Append the table cell to the table row.
+ tr.Append(tc2);
+
+ // Append the table row to the table.
+ table.Append(tr);
+
+ // Append the table to the document.
+ doc.MainDocumentPart.Document.Body.Append(table);
+ }
+}
\ No newline at end of file
diff --git a/samples/word/insert_a_table/cs/insert_a_table_cs.csproj b/samples/word/insert_a_table/cs/insert_a_table_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/insert_a_table/cs/insert_a_table_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/insert_a_table/vb/Program.vb b/samples/word/insert_a_table/vb/Program.vb
new file mode 100644
index 00000000..49f0ba81
--- /dev/null
+++ b/samples/word/insert_a_table/vb/Program.vb
@@ -0,0 +1,65 @@
+Imports DocumentFormat.OpenXml
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+Imports BottomBorder = DocumentFormat.OpenXml.Wordprocessing.BottomBorder
+Imports LeftBorder = DocumentFormat.OpenXml.Wordprocessing.LeftBorder
+Imports RightBorder = DocumentFormat.OpenXml.Wordprocessing.RightBorder
+Imports Run = DocumentFormat.OpenXml.Wordprocessing.Run
+Imports Table = DocumentFormat.OpenXml.Wordprocessing.Table
+Imports Text = DocumentFormat.OpenXml.Wordprocessing.Text
+Imports TopBorder = DocumentFormat.OpenXml.Wordprocessing.TopBorder
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+ ' Insert a table into a word processing document.
+ Public Sub CreateTable(ByVal fileName As String)
+ ' Use the file name and path passed in as an argument
+ ' to open an existing Word 2007 document.
+
+ Using doc As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
+ ' Create an empty table.
+ Dim table As New Table()
+
+ ' Create a TableProperties object and specify its border information.
+ Dim tblProp As New TableProperties(New TableBorders(
+ New TopBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24},
+ New BottomBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24},
+ New LeftBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24},
+ New RightBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24},
+ New InsideHorizontalBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24},
+ New InsideVerticalBorder() With {.Val = New EnumValue(Of BorderValues)(BorderValues.Dashed), .Size = 24}))
+ ' Append the TableProperties object to the empty table.
+ table.AppendChild(Of TableProperties)(tblProp)
+
+ ' Create a row.
+ Dim tr As New TableRow()
+
+ ' Create a cell.
+ Dim tc1 As New TableCell()
+
+ ' Specify the width property of the table cell.
+ tc1.Append(New TableCellProperties(New TableCellWidth()))
+
+ ' Specify the table cell content.
+ tc1.Append(New Paragraph(New Run(New Text("some text"))))
+
+ ' Append the table cell to the table row.
+ tr.Append(tc1)
+
+ ' Create a second table cell by copying the OuterXml value of the first table cell.
+ Dim tc2 As New TableCell(tc1.OuterXml)
+
+ ' Append the table cell to the table row.
+ tr.Append(tc2)
+
+ ' Append the table row to the table.
+ table.Append(tr)
+
+ ' Append the table to the document.
+ doc.MainDocumentPart.Document.Body.Append(table)
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/insert_a_table/vb/insert_a_table_vb.vbproj b/samples/word/insert_a_table/vb/insert_a_table_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/insert_a_table/vb/insert_a_table_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/remove_hidden_text/cs/Program.cs b/samples/word/remove_hidden_text/cs/Program.cs
new file mode 100644
index 00000000..e770c63d
--- /dev/null
+++ b/samples/word/remove_hidden_text/cs/Program.cs
@@ -0,0 +1,38 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using System.IO;
+using System.Xml;
+
+static void WDDeleteHiddenText(string docName)
+{
+ // Given a document name, delete all the hidden text.
+ const string wordmlNamespace = "https://schemas.openxmlformats.org/wordprocessingml/2006/main";
+
+ using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(docName, true))
+ {
+ // Manage namespaces to perform XPath queries.
+ NameTable nt = new NameTable();
+ XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
+ nsManager.AddNamespace("w", wordmlNamespace);
+
+ // Get the document part from the package.
+ // Load the XML in the document part into an XmlDocument instance.
+ XmlDocument xdoc = new XmlDocument(nt);
+ xdoc.Load(wdDoc.MainDocumentPart.GetStream());
+ XmlNodeList hiddenNodes = xdoc.SelectNodes("//w:vanish", nsManager);
+ foreach (System.Xml.XmlNode hiddenNode in hiddenNodes)
+ {
+ XmlNode topNode = hiddenNode.ParentNode.ParentNode;
+ XmlNode topParentNode = topNode.ParentNode;
+ topParentNode.RemoveChild(topNode);
+ if (!(topParentNode.HasChildNodes))
+ {
+ topParentNode.ParentNode.RemoveChild(topParentNode);
+ }
+ }
+
+ // Save the document XML back to its document part.
+ xdoc.Save(wdDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write));
+ }
+}
\ No newline at end of file
diff --git a/samples/word/remove_hidden_text/cs/remove_hidden_text_cs.csproj b/samples/word/remove_hidden_text/cs/remove_hidden_text_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/remove_hidden_text/cs/remove_hidden_text_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/remove_hidden_text/vb/Program.vb b/samples/word/remove_hidden_text/vb/Program.vb
new file mode 100644
index 00000000..d62a94d2
--- /dev/null
+++ b/samples/word/remove_hidden_text/vb/Program.vb
@@ -0,0 +1,39 @@
+Imports System.IO
+Imports System.Xml
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub WDDeleteHiddenText(ByVal docName As String)
+ ' Given a document name, delete all the hidden text.
+ Const wordmlNamespace As String = "https://schemas.openxmlformats.org/wordprocessingml/2006/main"
+
+ Using wdDoc As WordprocessingDocument = WordprocessingDocument.Open(docName, True)
+ ' Manage namespaces to perform XPath queries.
+ Dim nt As New NameTable()
+ Dim nsManager As New XmlNamespaceManager(nt)
+ nsManager.AddNamespace("w", wordmlNamespace)
+
+ ' Get the document part from the package.
+ ' Load the XML in the document part into an XmlDocument instance.
+ Dim xdoc As New XmlDocument(nt)
+ xdoc.Load(wdDoc.MainDocumentPart.GetStream())
+ Dim hiddenNodes As XmlNodeList = xdoc.SelectNodes("//w:vanish", nsManager)
+ For Each hiddenNode As System.Xml.XmlNode In hiddenNodes
+ Dim topNode As XmlNode = hiddenNode.ParentNode.ParentNode
+ Dim topParentNode As XmlNode = topNode.ParentNode
+ topParentNode.RemoveChild(topNode)
+ If Not (topParentNode.HasChildNodes) Then
+ topParentNode.ParentNode.RemoveChild(topParentNode)
+ End If
+ Next
+
+ ' Save the document XML back to its document part.
+ xdoc.Save(wdDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write))
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/remove_hidden_text/vb/remove_hidden_text_vb.vbproj b/samples/word/remove_hidden_text/vb/remove_hidden_text_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/remove_hidden_text/vb/remove_hidden_text_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/remove_the_headers_and_footers/cs/Program.cs b/samples/word/remove_the_headers_and_footers/cs/Program.cs
new file mode 100644
index 00000000..4041455d
--- /dev/null
+++ b/samples/word/remove_the_headers_and_footers/cs/Program.cs
@@ -0,0 +1,56 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.Linq;
+
+// Remove all of the headers and footers from a document.
+static void RemoveHeadersAndFooters(string filename)
+{
+ // Given a document name, remove all of the headers and footers
+ // from the document.
+ using (WordprocessingDocument doc = WordprocessingDocument.Open(filename, true))
+ {
+ // Get a reference to the main document part.
+ var docPart = doc.MainDocumentPart;
+
+ // Count the header and footer parts and continue if there
+ // are any.
+ if (docPart.HeaderParts.Count() > 0 ||
+ docPart.FooterParts.Count() > 0)
+ {
+ // Remove the header and footer parts.
+ docPart.DeleteParts(docPart.HeaderParts);
+ docPart.DeleteParts(docPart.FooterParts);
+
+ // Get a reference to the root element of the main
+ // document part.
+ Document document = docPart.Document;
+
+ // Remove all references to the headers and footers.
+
+ // First, create a list of all descendants of type
+ // HeaderReference. Then, navigate the list and call
+ // Remove on each item to delete the reference.
+ var headers =
+ document.Descendants().ToList();
+ foreach (var header in headers)
+ {
+ header.Remove();
+ }
+
+ // First, create a list of all descendants of type
+ // FooterReference. Then, navigate the list and call
+ // Remove on each item to delete the reference.
+ var footers =
+ document.Descendants().ToList();
+ foreach (var footer in footers)
+ {
+ footer.Remove();
+ }
+
+ // Save the changes.
+ document.Save();
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/remove_the_headers_and_footers/cs/remove_the_headers_and_footers_cs.csproj b/samples/word/remove_the_headers_and_footers/cs/remove_the_headers_and_footers_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/remove_the_headers_and_footers/cs/remove_the_headers_and_footers_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/remove_the_headers_and_footers/vb/Program.vb b/samples/word/remove_the_headers_and_footers/vb/Program.vb
new file mode 100644
index 00000000..e8ea0b53
--- /dev/null
+++ b/samples/word/remove_the_headers_and_footers/vb/Program.vb
@@ -0,0 +1,58 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Spreadsheet
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+ ' To remove all of the headers and footers in a document.
+ Public Sub RemoveHeadersAndFooters(ByVal filename As String)
+
+ ' Given a document name, remove all of the headers and footers
+ ' from the document.
+ Using doc = WordprocessingDocument.Open(filename, True)
+
+ ' Get a reference to the main document part.
+ Dim docPart = doc.MainDocumentPart
+
+ ' Count the header and footer parts and continue if there
+ ' are any.
+ If (docPart.HeaderParts.Count > 0) Or
+ (docPart.FooterParts.Count > 0) Then
+
+ ' Remove the header and footer parts.
+ docPart.DeleteParts(docPart.HeaderParts)
+ docPart.DeleteParts(docPart.FooterParts)
+
+ ' Get a reference to the root element of the main
+ ' document part.
+ Dim document As Document = docPart.Document
+
+ ' Remove all references to the headers and footers.
+
+ ' First, create a list of all descendants of type
+ ' HeaderReference. Then, navigate the list and call
+ ' Remove on each item to delete the reference.
+ Dim headers =
+ document.Descendants(Of HeaderReference).ToList()
+ For Each header In headers
+ header.Remove()
+ Next
+
+ ' First, create a list of all descendants of type
+ ' FooterReference. Then, navigate the list and call
+ ' Remove on each item to delete the reference.
+ Dim footers =
+ document.Descendants(Of FooterReference).ToList()
+ For Each footer In footers
+ footer.Remove()
+ Next
+
+ ' Save the changes.
+ document.Save()
+ End If
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/remove_the_headers_and_footers/vb/remove_the_headers_and_footers_vb.vbproj b/samples/word/remove_the_headers_and_footers/vb/remove_the_headers_and_footers_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/remove_the_headers_and_footers/vb/remove_the_headers_and_footers_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/replace_the_header/cs/Program.cs b/samples/word/replace_the_header/cs/Program.cs
new file mode 100644
index 00000000..21699f92
--- /dev/null
+++ b/samples/word/replace_the_header/cs/Program.cs
@@ -0,0 +1,53 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.Collections.Generic;
+using System.Linq;
+
+static void AddHeaderFromTo(string filepathFrom, string filepathTo)
+{
+ // Replace header in target document with header of source document.
+ using (WordprocessingDocument
+ wdDoc = WordprocessingDocument.Open(filepathTo, true))
+ {
+ MainDocumentPart mainPart = wdDoc.MainDocumentPart;
+
+ // Delete the existing header part.
+ mainPart.DeleteParts(mainPart.HeaderParts);
+
+ // Create a new header part.
+ DocumentFormat.OpenXml.Packaging.HeaderPart headerPart =
+ mainPart.AddNewPart();
+
+ // Get Id of the headerPart.
+ string rId = mainPart.GetIdOfPart(headerPart);
+
+ // Feed target headerPart with source headerPart.
+ using (WordprocessingDocument wdDocSource =
+ WordprocessingDocument.Open(filepathFrom, true))
+ {
+ DocumentFormat.OpenXml.Packaging.HeaderPart firstHeader =
+ wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault();
+
+ wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault();
+
+ if (firstHeader != null)
+ {
+ headerPart.FeedData(firstHeader.GetStream());
+ }
+ }
+
+ // Get SectionProperties and Replace HeaderReference with new Id.
+ IEnumerable sectPrs =
+ mainPart.Document.Body.Elements();
+ foreach (var sectPr in sectPrs)
+ {
+ // Delete existing references to headers.
+ sectPr.RemoveAllChildren();
+
+ // Create the new header reference node.
+ sectPr.PrependChild(new HeaderReference() { Id = rId });
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/replace_the_header/cs/replace_the_header_cs.csproj b/samples/word/replace_the_header/cs/replace_the_header_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/replace_the_header/cs/replace_the_header_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/replace_the_header/vb/Program.vb b/samples/word/replace_the_header/vb/Program.vb
new file mode 100644
index 00000000..09cec0ca
--- /dev/null
+++ b/samples/word/replace_the_header/vb/Program.vb
@@ -0,0 +1,46 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub AddHeaderFromTo(ByVal filepathFrom As String, ByVal filepathTo As String)
+ ' Replace header in target document with header of source document.
+ Using wdDoc As WordprocessingDocument = _
+ WordprocessingDocument.Open(filepathTo, True)
+ Dim mainPart As MainDocumentPart = wdDoc.MainDocumentPart
+
+ ' Delete the existing header part.
+ mainPart.DeleteParts(mainPart.HeaderParts)
+
+ ' Create a new header part.
+ Dim headerPart = mainPart.AddNewPart(Of HeaderPart)()
+
+ ' Get Id of the headerPart.
+ Dim rId As String = mainPart.GetIdOfPart(headerPart)
+
+ ' Feed target headerPart with source headerPart.
+ Using wdDocSource As WordprocessingDocument = _
+ WordprocessingDocument.Open(filepathFrom, True)
+ Dim firstHeader = wdDocSource.MainDocumentPart.HeaderParts.FirstOrDefault()
+
+ If firstHeader IsNot Nothing Then
+ headerPart.FeedData(firstHeader.GetStream())
+ End If
+ End Using
+
+ ' Get SectionProperties and Replace HeaderReference with new Id.
+ Dim sectPrs = mainPart.Document.Body.Elements(Of SectionProperties)()
+ For Each sectPr In sectPrs
+ ' Delete existing references to headers.
+ sectPr.RemoveAllChildren(Of HeaderReference)()
+
+ ' Create the new header reference node.
+ sectPr.PrependChild(Of HeaderReference)(New HeaderReference() With {.Id = rId})
+ Next
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/replace_the_header/vb/replace_the_header_vb.vbproj b/samples/word/replace_the_header/vb/replace_the_header_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/replace_the_header/vb/replace_the_header_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/replace_the_styles_parts/cs/Program.cs b/samples/word/replace_the_styles_parts/cs/Program.cs
new file mode 100644
index 00000000..2d8bd2c5
--- /dev/null
+++ b/samples/word/replace_the_styles_parts/cs/Program.cs
@@ -0,0 +1,88 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+
+// Replace the styles in the "to" document with the styles in
+// the "from" document.
+static void ReplaceStyles(string fromDoc, string toDoc)
+{
+ // Extract and replace the styles part.
+ var node = ExtractStylesPart(fromDoc, false);
+ if (node is not null)
+ ReplaceStylesPart(toDoc, node, false);
+
+ // Extract and replace the stylesWithEffects part. To fully support
+ // round-tripping from Word 2010 to Word 2007, you should
+ // replace this part, as well.
+ node = ExtractStylesPart(fromDoc);
+ if (node is not null)
+ ReplaceStylesPart(toDoc, node);
+ return;
+}
+
+// Given a file and an XDocument instance that contains the content of
+// a styles or stylesWithEffects part, replace the styles in the file
+// with the styles in the XDocument.
+static void ReplaceStylesPart(string fileName, XDocument newStyles, bool setStylesWithEffectsPart = true)
+{
+ // Open the document for write access and get a reference.
+ using (var document = WordprocessingDocument.Open(fileName, true))
+ {
+ // Get a reference to the main document part.
+ var docPart = document.MainDocumentPart;
+
+ // Assign a reference to the appropriate part to the
+ // stylesPart variable.
+ StylesPart stylesPart = null;
+ if (setStylesWithEffectsPart)
+ stylesPart = docPart.StylesWithEffectsPart;
+ else
+ stylesPart = docPart.StyleDefinitionsPart;
+
+ // If the part exists, populate it with the new styles.
+ if (stylesPart is not null)
+ {
+ newStyles.Save(new StreamWriter(stylesPart.GetStream(
+ FileMode.Create, FileAccess.Write)));
+ }
+ }
+}
+
+// Extract the styles or stylesWithEffects part from a
+// word processing document as an XDocument instance.
+static XDocument ExtractStylesPart(string fileName, bool getStylesWithEffectsPart = true)
+{
+ // Declare a variable to hold the XDocument.
+ XDocument styles = null;
+
+ // Open the document for read access and get a reference.
+ using (var document = WordprocessingDocument.Open(fileName, false))
+ {
+ // Get a reference to the main document part.
+ var docPart = document.MainDocumentPart;
+
+ // Assign a reference to the appropriate part to the
+ // stylesPart variable.
+ StylesPart stylesPart = null;
+ if (getStylesWithEffectsPart)
+ stylesPart = docPart.StylesWithEffectsPart;
+ else
+ stylesPart = docPart.StyleDefinitionsPart;
+
+ // If the part exists, read it into the XDocument.
+ if (stylesPart is not null)
+ {
+ using (var reader = XmlNodeReader.Create(
+ stylesPart.GetStream(FileMode.Open, FileAccess.Read)))
+ {
+ // Create the XDocument.
+ styles = XDocument.Load(reader);
+ }
+ }
+ }
+ // Return the XDocument instance.
+ return styles;
+}
\ No newline at end of file
diff --git a/samples/word/replace_the_styles_parts/cs/replace_the_styles_parts_cs.csproj b/samples/word/replace_the_styles_parts/cs/replace_the_styles_parts_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/replace_the_styles_parts/cs/replace_the_styles_parts_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/replace_the_styles_parts/vb/Program.vb b/samples/word/replace_the_styles_parts/vb/Program.vb
new file mode 100644
index 00000000..586a8df3
--- /dev/null
+++ b/samples/word/replace_the_styles_parts/vb/Program.vb
@@ -0,0 +1,95 @@
+Imports System.IO
+Imports System.Xml
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Replace the styles in the "to" document with the styles
+ ' in the "from" document.
+ Public Sub ReplaceStyles(fromDoc As String, toDoc As String)
+ ' Extract and copy the styles part.
+ Dim node = ExtractStylesPart(fromDoc, False)
+ If node IsNot Nothing Then
+ ReplaceStylesPart(toDoc, node, False)
+ End If
+
+ ' Extract and copy the stylesWithEffects part. To fully support
+ ' round-tripping from Word 2013 to Word 2010, you should
+ ' replace this part, as well.
+ node = ExtractStylesPart(fromDoc, True)
+ If node IsNot Nothing Then
+ ReplaceStylesPart(toDoc, node, True)
+ End If
+ End Sub
+
+ ' Given a file and an XDocument instance that contains the content of
+ ' a styles or stylesWithEffects part, replace the styles in the file
+ ' with the styles in the XDocument.
+ Public Sub ReplaceStylesPart(
+ ByVal fileName As String, ByVal newStyles As XDocument,
+ Optional ByVal setStylesWithEffectsPart As Boolean = True)
+
+ ' Open the document for write access and get a reference.
+ Using document = WordprocessingDocument.Open(fileName, True)
+
+ ' Get a reference to the main document part.
+ Dim docPart = document.MainDocumentPart
+
+ ' Assign a reference to the appropriate part to the
+ ' stylesPart variable.
+ Dim stylesPart As StylesPart = Nothing
+ If setStylesWithEffectsPart Then
+ stylesPart = docPart.StylesWithEffectsPart
+ Else
+ stylesPart = docPart.StyleDefinitionsPart
+ End If
+
+ ' If the part exists, populate it with the new styles.
+ If stylesPart IsNot Nothing Then
+ newStyles.Save(New StreamWriter(
+ stylesPart.GetStream(FileMode.Create, FileAccess.Write)))
+ End If
+ End Using
+ End Sub
+
+ ' Extract the styles or stylesWithEffects part from a
+ ' word processing document as an XDocument instance.
+ Public Function ExtractStylesPart(
+ ByVal fileName As String,
+ Optional ByVal getStylesWithEffectsPart As Boolean = True) As XDocument
+
+ ' Declare a variable to hold the XDocument.
+ Dim styles As XDocument = Nothing
+
+ ' Open the document for read access and get a reference.
+ Using document = WordprocessingDocument.Open(fileName, False)
+
+ ' Get a reference to the main document part.
+ Dim docPart = document.MainDocumentPart
+
+ ' Assign a reference to the appropriate part to the
+ ' stylesPart variable.
+ Dim stylesPart As StylesPart = Nothing
+ If getStylesWithEffectsPart Then
+ stylesPart = docPart.StylesWithEffectsPart
+ Else
+ stylesPart = docPart.StyleDefinitionsPart
+ End If
+
+ ' If the part exists, read it into the XDocument.
+ If stylesPart IsNot Nothing Then
+ Using reader = XmlNodeReader.Create(
+ stylesPart.GetStream(FileMode.Open, FileAccess.Read))
+ ' Create the XDocument:
+ styles = XDocument.Load(reader)
+ End Using
+ End If
+ End Using
+ ' Return the XDocument instance.
+ Return styles
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/word/replace_the_styles_parts/vb/replace_the_styles_parts_vb.vbproj b/samples/word/replace_the_styles_parts/vb/replace_the_styles_parts_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/replace_the_styles_parts/vb/replace_the_styles_parts_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/replace_the_theme_part/cs/Program.cs b/samples/word/replace_the_theme_part/cs/Program.cs
new file mode 100644
index 00000000..5e7bd178
--- /dev/null
+++ b/samples/word/replace_the_theme_part/cs/Program.cs
@@ -0,0 +1,27 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using System.IO;
+
+// This method can be used to replace the theme part in a package.
+static void ReplaceTheme(string document, string themeFile)
+{
+ using (WordprocessingDocument wordDoc =
+ WordprocessingDocument.Open(document, true))
+ {
+ MainDocumentPart mainPart = wordDoc.MainDocumentPart;
+
+ // Delete the old document part.
+ mainPart.DeletePart(mainPart.ThemePart);
+
+ // Add a new document part and then add content.
+ ThemePart themePart = mainPart.AddNewPart();
+
+ using (StreamReader streamReader = new StreamReader(themeFile))
+ using (StreamWriter streamWriter =
+ new StreamWriter(themePart.GetStream(FileMode.Create)))
+ {
+ streamWriter.Write(streamReader.ReadToEnd());
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/replace_the_theme_part/cs/replace_the_theme_part_cs.csproj b/samples/word/replace_the_theme_part/cs/replace_the_theme_part_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/replace_the_theme_part/cs/replace_the_theme_part_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/replace_the_theme_part/vb/Program.vb b/samples/word/replace_the_theme_part/vb/Program.vb
new file mode 100644
index 00000000..6f7c5c01
--- /dev/null
+++ b/samples/word/replace_the_theme_part/vb/Program.vb
@@ -0,0 +1,31 @@
+Imports System.IO
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' This method can be used to replace a document part in a package.
+ Public Sub ReplaceTheme(ByVal document As String, ByVal themeFile As String)
+ Using wordDoc As WordprocessingDocument = _
+ WordprocessingDocument.Open(document, True)
+ Dim mainPart As MainDocumentPart = wordDoc.MainDocumentPart
+
+ ' Delete the old document part.
+ mainPart.DeletePart(mainPart.ThemePart)
+
+ ' Add a new document part and then add content.
+ Dim themePart As ThemePart = mainPart.AddNewPart(Of ThemePart)()
+
+ Using streamReader As New StreamReader(themeFile)
+ Using streamWriter As _
+ New StreamWriter(themePart.GetStream(FileMode.Create))
+
+ streamWriter.Write(streamReader.ReadToEnd())
+ End Using
+ End Using
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/replace_the_theme_part/vb/replace_the_theme_part_vb.vbproj b/samples/word/replace_the_theme_part/vb/replace_the_theme_part_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/replace_the_theme_part/vb/replace_the_theme_part_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/retrieve_application_property_values/cs/Program.cs b/samples/word/retrieve_application_property_values/cs/Program.cs
new file mode 100644
index 00000000..0497b46b
--- /dev/null
+++ b/samples/word/retrieve_application_property_values/cs/Program.cs
@@ -0,0 +1,31 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using System;
+
+namespace GetApplicationProperty
+{
+ class Program
+ {
+ private const string FILENAME =
+ @"C:\Users\Public\Documents\DocumentProperties.docx";
+
+ static void Main(string[] args)
+ {
+ using (WordprocessingDocument document =
+ WordprocessingDocument.Open(FILENAME, false))
+ {
+ var props = document.ExtendedFilePropertiesPart.Properties;
+
+ if (props.Company != null)
+ Console.WriteLine("Company = " + props.Company.Text);
+
+ if (props.Lines != null)
+ Console.WriteLine("Lines = " + props.Lines.Text);
+
+ if (props.Manager != null)
+ Console.WriteLine("Manager = " + props.Manager.Text);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/retrieve_application_property_values/cs/retrieve_application_property_values_cs.csproj b/samples/word/retrieve_application_property_values/cs/retrieve_application_property_values_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/retrieve_application_property_values/cs/retrieve_application_property_values_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/retrieve_application_property_values/vb/Program.vb b/samples/word/retrieve_application_property_values/vb/Program.vb
new file mode 100644
index 00000000..5b240015
--- /dev/null
+++ b/samples/word/retrieve_application_property_values/vb/Program.vb
@@ -0,0 +1,26 @@
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Module1
+
+ Private Const FILENAME As String =
+ "C:\Users\Public\Documents\DocumentProperties.docx"
+
+ Sub Main()
+ Using document As WordprocessingDocument =
+ WordprocessingDocument.Open(FILENAME, False)
+
+ Dim props = document.ExtendedFilePropertiesPart.Properties
+ If props.Company IsNot Nothing Then
+ Console.WriteLine("Company = " & props.Company.Text)
+ End If
+
+ If props.Lines IsNot Nothing Then
+ Console.WriteLine("Lines = " & props.Lines.Text)
+ End If
+
+ If props.Manager IsNot Nothing Then
+ Console.WriteLine("Manager = " & props.Manager.Text)
+ End If
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/retrieve_application_property_values/vb/retrieve_application_property_values_vb.vbproj b/samples/word/retrieve_application_property_values/vb/retrieve_application_property_values_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/retrieve_application_property_values/vb/retrieve_application_property_values_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/retrieve_comments/cs/Program.cs b/samples/word/retrieve_comments/cs/Program.cs
new file mode 100644
index 00000000..8b753514
--- /dev/null
+++ b/samples/word/retrieve_comments/cs/Program.cs
@@ -0,0 +1,23 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System;
+
+static void GetCommentsFromDocument(string fileName)
+{
+ using (WordprocessingDocument wordDoc =
+ WordprocessingDocument.Open(fileName, false))
+ {
+ WordprocessingCommentsPart commentsPart =
+ wordDoc.MainDocumentPart.WordprocessingCommentsPart;
+
+ if (commentsPart != null && commentsPart.Comments != null)
+ {
+ foreach (Comment comment in commentsPart.Comments.Elements())
+ {
+ Console.WriteLine(comment.InnerText);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/retrieve_comments/cs/retrieve_comments_cs.csproj b/samples/word/retrieve_comments/cs/retrieve_comments_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/retrieve_comments/cs/retrieve_comments_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/retrieve_comments/vb/Program.vb b/samples/word/retrieve_comments/vb/Program.vb
new file mode 100644
index 00000000..7e0b31c3
--- /dev/null
+++ b/samples/word/retrieve_comments/vb/Program.vb
@@ -0,0 +1,26 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub GetCommentsFromDocument(ByVal fileName As String)
+ Using wordDoc As WordprocessingDocument = _
+ WordprocessingDocument.Open(fileName, False)
+
+ Dim commentsPart As WordprocessingCommentsPart = _
+ wordDoc.MainDocumentPart.WordprocessingCommentsPart
+
+ If commentsPart IsNot Nothing AndAlso _
+ commentsPart.Comments IsNot Nothing Then
+ For Each comment As Comment In _
+ commentsPart.Comments.Elements(Of Comment)()
+ Console.WriteLine(comment.InnerText)
+ Next
+ End If
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/retrieve_comments/vb/retrieve_comments_vb.vbproj b/samples/word/retrieve_comments/vb/retrieve_comments_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/retrieve_comments/vb/retrieve_comments_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/search_and_replace_text_a_part/cs/Program.cs b/samples/word/search_and_replace_text_a_part/cs/Program.cs
new file mode 100644
index 00000000..1e9e730e
--- /dev/null
+++ b/samples/word/search_and_replace_text_a_part/cs/Program.cs
@@ -0,0 +1,26 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using System.IO;
+using System.Text.RegularExpressions;
+
+// To search and replace content in a document part.
+static void SearchAndReplace(string document)
+{
+ using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
+ {
+ string docText = null;
+ using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
+ {
+ docText = sr.ReadToEnd();
+ }
+
+ Regex regexText = new Regex("Hello world!");
+ docText = regexText.Replace(docText, "Hi Everyone!");
+
+ using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
+ {
+ sw.Write(docText);
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/search_and_replace_text_a_part/cs/search_and_replace_text_a_part_cs.csproj b/samples/word/search_and_replace_text_a_part/cs/search_and_replace_text_a_part_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/search_and_replace_text_a_part/cs/search_and_replace_text_a_part_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/search_and_replace_text_a_part/vb/Program.vb b/samples/word/search_and_replace_text_a_part/vb/Program.vb
new file mode 100644
index 00000000..e5f3d1a7
--- /dev/null
+++ b/samples/word/search_and_replace_text_a_part/vb/Program.vb
@@ -0,0 +1,31 @@
+Imports System.IO
+Imports System.Text.RegularExpressions
+Imports DocumentFormat.OpenXml.Packaging
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' To search and replace content in a document part.
+ Public Sub SearchAndReplace(ByVal document As String)
+ Dim wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, True)
+ using (wordDoc)
+ Dim docText As String = Nothing
+ Dim sr As StreamReader = New StreamReader(wordDoc.MainDocumentPart.GetStream)
+
+ using (sr)
+ docText = sr.ReadToEnd
+ End using
+
+ Dim regexText As Regex = New Regex("Hello world!")
+ docText = regexText.Replace(docText, "Hi Everyone!")
+ Dim sw As StreamWriter = New StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create))
+
+ using (sw)
+ sw.Write(docText)
+ End using
+ End using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/search_and_replace_text_a_part/vb/search_and_replace_text_a_part_vb.vbproj b/samples/word/search_and_replace_text_a_part/vb/search_and_replace_text_a_part_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/search_and_replace_text_a_part/vb/search_and_replace_text_a_part_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/set_a_custom_property/cs/Program.cs b/samples/word/set_a_custom_property/cs/Program.cs
new file mode 100644
index 00000000..c5e5d610
--- /dev/null
+++ b/samples/word/set_a_custom_property/cs/Program.cs
@@ -0,0 +1,144 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.CustomProperties;
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.VariantTypes;
+using System;
+using System.IO;
+using System.Linq;
+
+static string SetCustomProperty(
+ string fileName,
+ string propertyName,
+ object propertyValue,
+ PropertyTypes propertyType)
+{
+ // Given a document name, a property name/value, and the property type,
+ // add a custom property to a document. The method returns the original
+ // value, if it existed.
+
+ string returnValue = null;
+
+ var newProp = new CustomDocumentProperty();
+ bool propSet = false;
+
+ // Calculate the correct type.
+ switch (propertyType)
+ {
+ case PropertyTypes.DateTime:
+
+ // Be sure you were passed a real date,
+ // and if so, format in the correct way.
+ // The date/time value passed in should
+ // represent a UTC date/time.
+ if ((propertyValue) is DateTime)
+ {
+ newProp.VTFileTime =
+ new VTFileTime(string.Format("{0:s}Z",
+ Convert.ToDateTime(propertyValue)));
+ propSet = true;
+ }
+
+ break;
+
+ case PropertyTypes.NumberInteger:
+ if ((propertyValue) is int)
+ {
+ newProp.VTInt32 = new VTInt32(propertyValue.ToString());
+ propSet = true;
+ }
+
+ break;
+
+ case PropertyTypes.NumberDouble:
+ if (propertyValue is double)
+ {
+ newProp.VTFloat = new VTFloat(propertyValue.ToString());
+ propSet = true;
+ }
+
+ break;
+
+ case PropertyTypes.Text:
+ newProp.VTLPWSTR = new VTLPWSTR(propertyValue.ToString());
+ propSet = true;
+
+ break;
+
+ case PropertyTypes.YesNo:
+ if (propertyValue is bool)
+ {
+ // Must be lowercase.
+ newProp.VTBool = new VTBool(
+ Convert.ToBoolean(propertyValue).ToString().ToLower());
+ propSet = true;
+ }
+ break;
+ }
+
+ if (!propSet)
+ {
+ // If the code was not able to convert the
+ // property to a valid value, throw an exception.
+ throw new InvalidDataException("propertyValue");
+ }
+
+ // Now that you have handled the parameters, start
+ // working on the document.
+ newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
+ newProp.Name = propertyName;
+
+ using (var document = WordprocessingDocument.Open(fileName, true))
+ {
+ var customProps = document.CustomFilePropertiesPart;
+ if (customProps == null)
+ {
+ // No custom properties? Add the part, and the
+ // collection of properties now.
+ customProps = document.AddCustomFilePropertiesPart();
+ customProps.Properties =
+ new DocumentFormat.OpenXml.CustomProperties.Properties();
+ }
+
+ var props = customProps.Properties;
+ if (props != null)
+ {
+ // This will trigger an exception if the property's Name
+ // property is null, but if that happens, the property is damaged,
+ // and probably should raise an exception.
+ var prop =
+ props.Where(
+ p => ((CustomDocumentProperty)p).Name.Value
+ == propertyName).FirstOrDefault();
+
+ // Does the property exist? If so, get the return value,
+ // and then delete the property.
+ if (prop != null)
+ {
+ returnValue = prop.InnerText;
+ prop.Remove();
+ }
+
+ // Append the new property, and
+ // fix up all the property ID values.
+ // The PropertyId value must start at 2.
+ props.AppendChild(newProp);
+ int pid = 2;
+ foreach (CustomDocumentProperty item in props)
+ {
+ item.PropertyId = pid++;
+ }
+ props.Save();
+ }
+ }
+ return returnValue;
+}
+
+public enum PropertyTypes : int
+{
+ YesNo,
+ Text,
+ DateTime,
+ NumberInteger,
+ NumberDouble
+}
\ No newline at end of file
diff --git a/samples/word/set_a_custom_property/cs/set_a_custom_property_cs.csproj b/samples/word/set_a_custom_property/cs/set_a_custom_property_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/set_a_custom_property/cs/set_a_custom_property_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/set_a_custom_property/vb/Program.vb b/samples/word/set_a_custom_property/vb/Program.vb
new file mode 100644
index 00000000..e9bcb7f1
--- /dev/null
+++ b/samples/word/set_a_custom_property/vb/Program.vb
@@ -0,0 +1,126 @@
+Imports System.IO
+Imports DocumentFormat.OpenXml.CustomProperties
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.VariantTypes
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Enum PropertyTypes
+ YesNo
+ Text
+ DateTime
+ NumberInteger
+ NumberDouble
+ End Enum
+
+ Public Function SetCustomProperty( _
+ ByVal fileName As String,
+ ByVal propertyName As String, _
+ ByVal propertyValue As Object,
+ ByVal propertyType As PropertyTypes) As String
+
+ ' Given a document name, a property name/value, and the property type,
+ ' add a custom property to a document. The method returns the original
+ ' value, if it existed.
+
+ Dim returnValue As String = Nothing
+
+ Dim newProp As New CustomDocumentProperty
+ Dim propSet As Boolean = False
+
+ ' Calculate the correct type:
+ Select Case propertyType
+
+ Case PropertyTypes.DateTime
+ ' Make sure you were passed a real date,
+ ' and if so, format in the correct way.
+ ' The date/time value passed in should
+ ' represent a UTC date/time.
+ If TypeOf (propertyValue) Is DateTime Then
+ newProp.VTFileTime = _
+ New VTFileTime(String.Format("{0:s}Z",
+ Convert.ToDateTime(propertyValue)))
+ propSet = True
+ End If
+
+ Case PropertyTypes.NumberInteger
+ If TypeOf (propertyValue) Is Integer Then
+ newProp.VTInt32 = New VTInt32(propertyValue.ToString())
+ propSet = True
+ End If
+
+ Case PropertyTypes.NumberDouble
+ If TypeOf propertyValue Is Double Then
+ newProp.VTFloat = New VTFloat(propertyValue.ToString())
+ propSet = True
+ End If
+
+ Case PropertyTypes.Text
+ newProp.VTLPWSTR = New VTLPWSTR(propertyValue.ToString())
+ propSet = True
+
+ Case PropertyTypes.YesNo
+ If TypeOf propertyValue Is Boolean Then
+ ' Must be lowercase.
+ newProp.VTBool = _
+ New VTBool(Convert.ToBoolean(propertyValue).ToString().ToLower())
+ propSet = True
+ End If
+ End Select
+
+ If Not propSet Then
+ ' If the code was not able to convert the
+ ' property to a valid value, throw an exception.
+ Throw New InvalidDataException("propertyValue")
+ End If
+
+ ' Now that you have handled the parameters, start
+ ' working on the document.
+ newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
+ newProp.Name = propertyName
+
+ Using document = WordprocessingDocument.Open(fileName, True)
+ Dim customProps = document.CustomFilePropertiesPart
+ If customProps Is Nothing Then
+ ' No custom properties? Add the part, and the
+ ' collection of properties now.
+ customProps = document.AddCustomFilePropertiesPart
+ customProps.Properties = New Properties
+ End If
+
+ Dim props = customProps.Properties
+ If props IsNot Nothing Then
+ ' This will trigger an exception is the property's Name property
+ ' is null, but if that happens, the property is damaged, and
+ ' probably should raise an exception.
+ Dim prop = props.
+ Where(Function(p) CType(p, CustomDocumentProperty).
+ Name.Value = propertyName).FirstOrDefault()
+ ' Does the property exist? If so, get the return value,
+ ' and then delete the property.
+ If prop IsNot Nothing Then
+ returnValue = prop.InnerText
+ prop.Remove()
+ End If
+
+ ' Append the new property, and
+ ' fix up all the property ID values.
+ ' The PropertyId value must start at 2.
+ props.AppendChild(newProp)
+ Dim pid As Integer = 2
+ For Each item As CustomDocumentProperty In props
+ item.PropertyId = pid
+ pid += 1
+ Next
+ props.Save()
+ End If
+ End Using
+
+ Return returnValue
+
+ End Function
+End Module
\ No newline at end of file
diff --git a/samples/word/set_a_custom_property/vb/set_a_custom_property_vb.vbproj b/samples/word/set_a_custom_property/vb/set_a_custom_property_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/set_a_custom_property/vb/set_a_custom_property_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/set_the_font_for_a_text_run/cs/Program.cs b/samples/word/set_the_font_for_a_text_run/cs/Program.cs
new file mode 100644
index 00000000..78b7407d
--- /dev/null
+++ b/samples/word/set_the_font_for_a_text_run/cs/Program.cs
@@ -0,0 +1,27 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.Linq;
+
+// Set the font for a text run.
+static void SetRunFont(string fileName)
+{
+ // Open a Wordprocessing document for editing.
+ using (WordprocessingDocument package = WordprocessingDocument.Open(fileName, true))
+ {
+ // Set the font to Arial to the first Run.
+ // Use an object initializer for RunProperties and rPr.
+ RunProperties rPr = new RunProperties(
+ new RunFonts()
+ {
+ Ascii = "Arial"
+ });
+
+ Run r = package.MainDocumentPart.Document.Descendants().First();
+ r.PrependChild(rPr);
+
+ // Save changes to the MainDocumentPart part.
+ package.MainDocumentPart.Document.Save();
+ }
+}
\ No newline at end of file
diff --git a/samples/word/set_the_font_for_a_text_run/cs/set_the_font_for_a_text_run_cs.csproj b/samples/word/set_the_font_for_a_text_run/cs/set_the_font_for_a_text_run_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/set_the_font_for_a_text_run/cs/set_the_font_for_a_text_run_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/set_the_font_for_a_text_run/vb/Program.vb b/samples/word/set_the_font_for_a_text_run/vb/Program.vb
new file mode 100644
index 00000000..cfcdf4e5
--- /dev/null
+++ b/samples/word/set_the_font_for_a_text_run/vb/Program.vb
@@ -0,0 +1,25 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ ' Set the font for a text run.
+ Public Sub SetRunFont(ByVal fileName As String)
+ ' Open a Wordprocessing document for editing.
+ Dim package As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
+ Using (package)
+ ' Set the font to Arial to the first Run.
+ Dim rPr As RunProperties = New RunProperties(New RunFonts With {.Ascii = "Arial"})
+ Dim r As Run = package.MainDocumentPart.Document.Descendants(Of Run).First
+
+ r.PrependChild(Of RunProperties)(rPr)
+
+ ' Save changes to the main document part.
+ package.MainDocumentPart.Document.Save()
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/set_the_font_for_a_text_run/vb/set_the_font_for_a_text_run_vb.vbproj b/samples/word/set_the_font_for_a_text_run/vb/set_the_font_for_a_text_run_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/set_the_font_for_a_text_run/vb/set_the_font_for_a_text_run_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/validate/cs/Program.cs b/samples/word/validate/cs/Program.cs
new file mode 100644
index 00000000..a2359471
--- /dev/null
+++ b/samples/word/validate/cs/Program.cs
@@ -0,0 +1,77 @@
+#nullable disable
+
+using DocumentFormat.OpenXml.Packaging;
+using DocumentFormat.OpenXml.Validation;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System;
+
+static void ValidateWordDocument(string filepath)
+{
+ using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
+ {
+ try
+ {
+ OpenXmlValidator validator = new OpenXmlValidator();
+ int count = 0;
+ foreach (ValidationErrorInfo error in
+ validator.Validate(wordprocessingDocument))
+ {
+ count++;
+ Console.WriteLine("Error " + count);
+ Console.WriteLine("Description: " + error.Description);
+ Console.WriteLine("ErrorType: " + error.ErrorType);
+ Console.WriteLine("Node: " + error.Node);
+ Console.WriteLine("Path: " + error.Path.XPath);
+ Console.WriteLine("Part: " + error.Part.Uri);
+ Console.WriteLine("-------------------------------------------");
+ }
+
+ Console.WriteLine("count={0}", count);
+ }
+
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+
+ wordprocessingDocument.Dispose();
+ }
+}
+
+static void ValidateCorruptedWordDocument(string filepath)
+{
+ // Insert some text into the body, this would cause Schema Error
+ using (WordprocessingDocument wordprocessingDocument =
+ WordprocessingDocument.Open(filepath, true))
+ {
+ // Insert some text into the body, this would cause Schema Error
+ Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
+ Run run = new Run(new Text("some text"));
+ body.Append(run);
+
+ try
+ {
+ OpenXmlValidator validator = new OpenXmlValidator();
+ int count = 0;
+ foreach (ValidationErrorInfo error in
+ validator.Validate(wordprocessingDocument))
+ {
+ count++;
+ Console.WriteLine("Error " + count);
+ Console.WriteLine("Description: " + error.Description);
+ Console.WriteLine("ErrorType: " + error.ErrorType);
+ Console.WriteLine("Node: " + error.Node);
+ Console.WriteLine("Path: " + error.Path.XPath);
+ Console.WriteLine("Part: " + error.Part.Uri);
+ Console.WriteLine("-------------------------------------------");
+ }
+
+ Console.WriteLine("count={0}", count);
+ }
+
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/word/validate/cs/validate_cs.csproj b/samples/word/validate/cs/validate_cs.csproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/validate/cs/validate_cs.csproj
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/samples/word/validate/vb/Program.vb b/samples/word/validate/vb/Program.vb
new file mode 100644
index 00000000..2147514f
--- /dev/null
+++ b/samples/word/validate/vb/Program.vb
@@ -0,0 +1,66 @@
+Imports DocumentFormat.OpenXml.Packaging
+Imports DocumentFormat.OpenXml.Validation
+Imports DocumentFormat.OpenXml.Wordprocessing
+
+Module Program
+ Sub Main(args As String())
+ End Sub
+
+
+
+ Public Sub ValidateWordDocument(ByVal filepath As String)
+ Using wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
+ Try
+ Dim validator As New OpenXmlValidator()
+ Dim count As Integer = 0
+ For Each [error] As ValidationErrorInfo In validator.Validate(wordprocessingDocument__1)
+ count += 1
+ Console.WriteLine("Error " & count)
+ Console.WriteLine("Description: " & [error].Description)
+ Console.WriteLine("ErrorType: " & [error].ErrorType)
+ Console.WriteLine("Node: " & [error].Node.ToString())
+ Console.WriteLine("Path: " & [error].Path.XPath)
+ Console.WriteLine("Part: " & [error].Part.Uri.ToString())
+ Console.WriteLine("-------------------------------------------")
+ Next
+
+ Console.WriteLine("count={0}", count)
+
+ Catch ex As Exception
+ Console.WriteLine(ex.Message)
+ End Try
+
+ wordprocessingDocument__1.Dispose()
+ End Using
+ End Sub
+
+ Public Sub ValidateCorruptedWordDocument(ByVal filepath As String)
+ ' Insert some text into the body, this would cause Schema Error
+ Using wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(filepath, True)
+ ' Insert some text into the body, this would cause Schema Error
+ Dim body As Body = wordprocessingDocument__1.MainDocumentPart.Document.Body
+ Dim run As New Run(New Text("some text"))
+ body.Append(run)
+
+ Try
+ Dim validator As New OpenXmlValidator()
+ Dim count As Integer = 0
+ For Each [error] As ValidationErrorInfo In validator.Validate(wordprocessingDocument__1)
+ count += 1
+ Console.WriteLine("Error " & count)
+ Console.WriteLine("Description: " & [error].Description)
+ Console.WriteLine("ErrorType: " & [error].ErrorType)
+ Console.WriteLine("Node: " & [error].Node.ToString())
+ Console.WriteLine("Path: " & [error].Path.XPath)
+ Console.WriteLine("Part: " & [error].Part.Uri.ToString())
+ Console.WriteLine("-------------------------------------------")
+ Next
+
+ Console.WriteLine("count={0}", count)
+
+ Catch ex As Exception
+ Console.WriteLine(ex.Message)
+ End Try
+ End Using
+ End Sub
+End Module
\ No newline at end of file
diff --git a/samples/word/validate/vb/validate_vb.vbproj b/samples/word/validate/vb/validate_vb.vbproj
new file mode 100644
index 00000000..b4b1d3ea
--- /dev/null
+++ b/samples/word/validate/vb/validate_vb.vbproj
@@ -0,0 +1 @@
+
\ No newline at end of file