Skip to content

Commit ba31743

Browse files
authored
Extract snippets from remaining SpreadsheetML tutorials, extract "Packages and Document Parts" section, and fix multiple xmlns errors (#298)
1 parent 04deec7 commit ba31743

26 files changed

+310
-1160
lines changed

docs/includes/spreadsheet/structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ code example.
2222

2323
```xml
2424
<?xml version="1.0" encoding="UTF-8" ?>
25-
<worksheet xmlns="https://schemas.openxmlformats.org/spreadsheetml/2006/main">
25+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
2626
<sheetData>
2727
<row r="1">
2828
<c r="A1">

docs/presentation/structure-of-a-presentationml-document.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ The following XML code is the PresentationML that represents the relationship pa
650650

651651
```xml
652652
<?xml version="1.0" encoding="utf-8"?>
653-
<Relationships xmlns="https://schemas.openxmlformats.org/package/2006/relationships">
653+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
654654
<Relationship Type="https://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"
655655
Target="/ppt/slides/slide.xml"
656656
Id="rId2" />

docs/spreadsheet/how-to-add-custom-ui-to-a-spreadsheet-document.md

Lines changed: 21 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.suite: office
1111
ms.author: o365devx
1212
author: o365devx
1313
ms.topic: conceptual
14-
ms.date: 11/01/2017
14+
ms.date: 01/10/2024
1515
ms.localizationpriority: high
1616
---
1717

@@ -24,22 +24,15 @@ this task.
2424

2525
## Creating Custom UI
2626

27-
Before using the Open XML SDK to create a ribbon customization in an Excel workbook, you must first create the customization content. Describing the XML required to create a ribbon customization is beyond the scope of this topic. In addition, you will find it far easier to use the Ribbon Designer in Visual Studio 2010 to create the customization for you. For more information about customizing the ribbon by using the Visual Studio Ribbon Designer, see [Ribbon Designer](https://msdn.microsoft.com/library/26617206-f4da-416f-a18a-d817b2d4872d(Office.15).aspx) and [Walkthrough: Creating a Custom Tab by Using the Ribbon Designer](https://msdn.microsoft.com/library/312865e6-950f-46ab-88de-fe7eb8036bfe(Office.15).aspx).
28-
For the purposes of this demonstration, you will need an XML file that contains a customization, and the following code provides a simple customization (or you can create your own by using the Visual Studio Ribbon Designer, and then right-click to export the customization to an XML file). Copy the following content into a text file that is named AddCustomUI.xml for use as part of this example. This XML content describes a ribbon customization that includes a button labeled "Click Me!" in a group named Group1 on the **Add-Ins** tab in Excel. When you click the button, it attempts to run a macro named **SampleMacro** in the host workbook.
29-
30-
```xml
31-
<customUI xmlns="https://schemas.microsoft.com/office/2006/01/customui">
32-
<ribbon>
33-
<tabs>
34-
<tab idMso="TabAddIns">
35-
<group id="Group1" label="Group1">
36-
<button id="Button1" label="Click Me!" showImage="false" onAction="SampleMacro"/>
37-
</group>
38-
</tab>
39-
</tabs>
40-
</ribbon>
41-
</customUI>
42-
```
27+
Before using the Open XML SDK to create a ribbon customization in an Excel workbook, you must first create the customization content. Describing the XML required to create a ribbon customization is beyond the scope of this topic. In addition, you will find it far easier to use the Ribbon Designer in Visual Studio to create the customization for you. For more information about customizing the ribbon by using the Visual Studio Ribbon Designer, see [Ribbon Designer](https://msdn.microsoft.com/library/26617206-f4da-416f-a18a-d817b2d4872d(Office.15).aspx) and [Walkthrough: Creating a Custom Tab by Using the Ribbon Designer](https://msdn.microsoft.com/library/312865e6-950f-46ab-88de-fe7eb8036bfe(Office.15).aspx).
28+
For the purposes of this demonstration, you will need an XML file that contains a customization, and the following code provides a simple customization (or you can create your own by using the Visual Studio Ribbon Designer, and then right-click to export the customization to an XML file). The samples below are the xml strings used in this example. This XML content describes a ribbon customization that includes a button labeled "Click Me!" in a group named Group1 on the **Add-Ins** tab in Excel. When you click the button, it attempts to run a macro named **SampleMacro** in the host workbook.
29+
30+
### [C#](#tab/cs-xml)
31+
[!code-csharp[](../../samples/spreadsheet/add_custom_ui/cs/Program.cs#snippet4)]
32+
### [Visual Basic](#tab/vb-xml)
33+
[!code-vb[](../../samples/spreadsheet/add_custom_ui/vb/Program.vb#snippet4)]
34+
***
35+
4336

4437
## Create the Macro
4538

@@ -69,60 +62,14 @@ The **AddCustomUI** method accepts two parameters:
6962

7063
- customUIContent*A string that contains the custom content (that is, the XML markup that describes the customization).
7164

72-
The following code shows the two parameters.
73-
74-
### [C#](#tab/cs-0)
75-
```csharp
76-
static public void AddCustomUI(string fileName, string customUIContent)
77-
```
78-
79-
### [Visual Basic](#tab/vb-0)
80-
```vb
81-
Public Sub XLAddCustomUI(ByVal fileName As String,
82-
ByVal customUIContent As String)
83-
```
84-
***
85-
86-
87-
## Call the AddCustomUI Method
88-
89-
The method modifies the ribbon in an Excel workbook. To call the method, pass the file name of the workbook to modify, and a string that contains the customization XML, as shown in the following example code.
90-
91-
### [C#](#tab/cs-1)
92-
```csharp
93-
const string SAMPLEXML = "AddCustomUI.xml";
94-
const string DEMOFILE = "AddCustomUI.xlsm";
95-
96-
string content = System.IO.File.OpenText(SAMPLEXML).ReadToEnd();
97-
AddCustomUI(DEMOFILE, content);
98-
```
99-
100-
### [Visual Basic](#tab/vb-1)
101-
```vb
102-
Const SAMPLEXML As String = "AddCustomUI.xml"
103-
Const DEMOFILE As String = "AddCustomUI.xlsm"
104-
105-
Dim content As String = System.IO.File.OpenText(SAMPLEXML).ReadToEnd()
106-
AddCustomUI(DEMOFILE, content)
107-
```
108-
***
109-
110-
11165
## Interact with the Workbook
11266

11367
The sample method, **AddCustomUI**, starts by opening the requested workbook in read/write mode, as shown in the following code.
11468

11569
### [C#](#tab/cs-2)
116-
```csharp
117-
using (SpreadsheetDocument document =
118-
SpreadsheetDocument.Open(fileName, true))
119-
```
120-
70+
[!code-csharp[](../../samples/spreadsheet/add_custom_ui/cs/Program.cs#snippet1)]
12171
### [Visual Basic](#tab/vb-2)
122-
```vb
123-
Using document As SpreadsheetDocument =
124-
SpreadsheetDocument.Open(fileName, True)
125-
```
72+
[!code-vb[](../../samples/spreadsheet/add_custom_ui/vb/Program.vb#snippet1)]
12673
***
12774

12875

@@ -131,25 +78,9 @@ The sample method, **AddCustomUI**, starts by opening the requested workbook in
13178
Next, as shown in the following code, the sample method attempts to retrieve a reference to the single ribbon extensibility part. If the part does not yet exist, the code creates it and stores a reference to the new part.
13279

13380
### [C#](#tab/cs-3)
134-
```csharp
135-
// You can have only a single ribbon extensibility part.
136-
// If the part doesn't exist, create it.
137-
var part = document.RibbonExtensibilityPart;
138-
if (part == null)
139-
{
140-
part = document.AddRibbonExtensibilityPart();
141-
}
142-
```
143-
81+
[!code-csharp[](../../samples/spreadsheet/add_custom_ui/cs/Program.cs#snippet2)]
14482
### [Visual Basic](#tab/vb-3)
145-
```vb
146-
' You can have only a single ribbon extensibility part.
147-
' If the part doesn't exist, add it.
148-
Dim part = document.RibbonExtensibilityPart
149-
If part Is Nothing Then
150-
part = document.AddRibbonExtensibilityPart
151-
End If
152-
```
83+
[!code-vb[](../../samples/spreadsheet/add_custom_ui/vb/Program.vb#snippet2)]
15384
***
15485

15586

@@ -158,31 +89,24 @@ Next, as shown in the following code, the sample method attempts to retrieve a r
15889
Given a reference to the ribbon extensibility part, the following code finishes by setting the part's **CustomUI** property to a new [CustomUI](https://msdn.microsoft.com/library/office/documentformat.openxml.office.customui.customui.aspx) object that contains the supplied customization. Once the customization is in place, the code saves the custom UI.
15990

16091
### [C#](#tab/cs-4)
161-
```csharp
162-
part.CustomUI = new CustomUI(customUIContent);
163-
part.CustomUI.Save();
164-
```
165-
92+
[!code-csharp[](../../samples/spreadsheet/add_custom_ui/cs/Program.cs#snippet3)]
16693
### [Visual Basic](#tab/vb-4)
167-
```vb
168-
part.CustomUI = New CustomUI(customUIContent)
169-
part.CustomUI.Save()
170-
```
94+
[!code-vb[](../../samples/spreadsheet/add_custom_ui/vb/Program.vb#snippet3)]
17195
***
17296

17397

17498
## Sample Code
17599

176-
The following is the complete **AddCustomUI** code sample in C\# and Visual Basic.
100+
The following is the complete **AddCustomUI** code sample in C\# and Visual Basic. The first argument passed to the **AddCustomUI** should be the absolute
101+
path to the AddCustomUI.xlsm file created from the instructions above.
177102

178103
### [C#](#tab/cs)
179-
[!code-csharp[](../../samples/spreadsheet/add_custom_ui/cs/Program.cs)]
104+
[!code-csharp[](../../samples/spreadsheet/add_custom_ui/cs/Program.cs#snippet0)]
180105

181106
### [Visual Basic](#tab/vb)
182-
[!code-vb[](../../samples/spreadsheet/add_custom_ui/vb/Program.vb)]
107+
[!code-vb[](../../samples/spreadsheet/add_custom_ui/vb/Program.vb#snippet0)]
183108

184109
## See also
185110

186111
- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
187-
- [Ribbon Designer](https://msdn.microsoft.com/library/26617206-f4da-416f-a18a-d817b2d4872d(Office.15).aspx)
188-
- [Walkthrough: Creating a Custom Tab by Using the Ribbon Designer](https://msdn.microsoft.com/library/312865e6-950f-46ab-88de-fe7eb8036bfe(Office.15).aspx)
112+

0 commit comments

Comments
 (0)